com.liferay.batch.engine.internal.BatchEngineTaskMethodRegistryImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.batch.engine.service
Show all versions of com.liferay.batch.engine.service
Liferay Batch Engine Service
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.batch.engine.internal;
import com.liferay.batch.engine.BatchEngineTaskItemDelegate;
import com.liferay.batch.engine.ItemClassRegistry;
import com.liferay.batch.engine.internal.item.BatchEngineTaskItemDelegateExecutor;
import com.liferay.batch.engine.internal.item.BatchEngineTaskItemDelegateExecutorCreator;
import com.liferay.petra.string.StringBundler;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.Validator;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceObjects;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
/**
* @author Ivica Cardic
*/
@Component(
service = {BatchEngineTaskMethodRegistry.class, ItemClassRegistry.class}
)
public class BatchEngineTaskMethodRegistryImpl
implements BatchEngineTaskMethodRegistry {
@Override
public BatchEngineTaskItemDelegateExecutorCreator
getBatchEngineTaskItemDelegateExecutorCreator(
String itemClassName, String taskItemDelegateName) {
if (Validator.isNull(taskItemDelegateName)) {
taskItemDelegateName = "DEFAULT";
}
Map
batchEngineTaskItemDelegateExecutorCreatorMap =
_batchEngineTaskItemDelegateExecutorCreators.get(
_itemClasses.get(itemClassName));
return batchEngineTaskItemDelegateExecutorCreatorMap.get(
taskItemDelegateName);
}
@Override
public Class> getItemClass(String itemClassName) {
Class> itemClass = _itemClasses.get(itemClassName);
if (itemClass == null) {
throw new IllegalStateException("Unknown class: " + itemClassName);
}
return itemClass;
}
@Activate
protected void activate(BundleContext bundleContext) {
_serviceTracker = new ServiceTracker<>(
bundleContext, BatchEngineTaskItemDelegate.class.getName(),
new BatchEngineTaskMethodServiceTrackerCustomizer(bundleContext));
_serviceTracker.open();
}
@Deactivate
protected void deactivate() {
_serviceTracker.close();
}
private static final Log _log = LogFactoryUtil.getLog(
BatchEngineTaskMethodRegistryImpl.class);
private final Map
, Map>
_batchEngineTaskItemDelegateExecutorCreators =
new ConcurrentHashMap<>();
private final Map> _itemClasses =
new ConcurrentHashMap<>();
private ServiceTracker, Class>>
_serviceTracker;
private class BatchEngineTaskMethodServiceTrackerCustomizer
implements ServiceTrackerCustomizer
, Class>> {
@Override
public Class> addingService(
ServiceReference>
serviceReference) {
BatchEngineTaskItemDelegate
© 2015 - 2025 Weber Informatics LLC | Privacy Policy