import com.google.common.collect.ImmutableList;
import java.util.List;
-import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.mdsal.binding.api.ActionProviderService;
import org.opendaylight.mdsal.binding.api.ActionService;
import org.opendaylight.mdsal.binding.api.BindingService;
import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.DataTreeService;
import org.opendaylight.mdsal.binding.api.MountPointService;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.mdsal.binding.api.NotificationService;
import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
import org.opendaylight.mdsal.dom.api.DOMActionService;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
import org.opendaylight.mdsal.dom.api.DOMNotificationService;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.api.DOMService;
import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentFactory;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*
* @author Robert Varga
*/
-public final class DynamicBindingAdapter implements AutoCloseable {
+@Component(immediate = true)
+public final class DynamicBindingAdapter {
private static final Logger LOG = LoggerFactory.getLogger(DynamicBindingAdapter.class);
- @GuardedBy("this")
- private List<AdaptingTracker<?, ?>> trackers;
+ private List<AdaptingTracker<?, ?>> trackers = ImmutableList.of();
- public DynamicBindingAdapter(final AdapterFactory factory, final BundleContext ctx) {
+ @Reference
+ AdapterFactory factory = null;
+ @Reference(target = "(component.factory=" + OSGiActionService.FACTORY_NAME + ")")
+ ComponentFactory actionServiceFactory = null;
+ @Reference(target = "(component.factory=" + OSGiActionProviderService.FACTORY_NAME + ")")
+ ComponentFactory actionProviderServiceFactory = null;
+ @Reference(target = "(component.factory=" + OSGiDataBroker.FACTORY_NAME + ")")
+ ComponentFactory dataBrokerFactory = null;
+ @Reference(target = "(component.factory=" + OSGiMountPointService.FACTORY_NAME + ")")
+ ComponentFactory mountPointServiceFactory = null;
+ @Reference(target = "(component.factory=" + OSGiNotificationService.FACTORY_NAME + ")")
+ ComponentFactory notificationServiceFactory = null;
+ @Reference(target = "(component.factory=" + OSGiNotificationPublishService.FACTORY_NAME + ")")
+ ComponentFactory notificationPublishServiceFactory = null;
+ @Reference(target = "(component.factory=" + OSGiRpcConsumerRegistry.FACTORY_NAME + ")")
+ ComponentFactory rpcConsumerRegistryFactory = null;
+ @Reference(target = "(component.factory=" + OSGiRpcProviderService.FACTORY_NAME + ")")
+ ComponentFactory rpcProviderServiceFactory = null;
+
+ @Activate
+ void activate(final BundleContext ctx) {
trackers = ImmutableList.of(
- new AdaptingTracker<>(ctx, DOMDataBroker.class, DataBroker.class, factory::createDataBroker),
- new AdaptingTracker<>(ctx, DOMDataTreeService.class, DataTreeService.class, factory::createDataTreeService),
+ new AdaptingTracker<>(ctx, DOMDataBroker.class, DataBroker.class, factory::createDataBroker,
+ dataBrokerFactory),
new AdaptingTracker<>(ctx, DOMMountPointService.class, MountPointService.class,
- factory::createMountPointService),
+ factory::createMountPointService, mountPointServiceFactory),
new AdaptingTracker<>(ctx, DOMNotificationService.class, NotificationService.class,
- factory::createNotificationService),
+ factory::createNotificationService, notificationServiceFactory),
new AdaptingTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class,
- factory::createNotificationPublishService),
+ factory::createNotificationPublishService, notificationPublishServiceFactory),
new AdaptingTracker<>(ctx, DOMRpcService.class, RpcConsumerRegistry.class,
- factory::createRpcConsumerRegistry),
+ factory::createRpcConsumerRegistry, rpcConsumerRegistryFactory),
new AdaptingTracker<>(ctx, DOMRpcProviderService.class, RpcProviderService.class,
- factory::createRpcProviderService),
- new AdaptingTracker<>(ctx, DOMActionService.class, ActionService.class, factory::createActionService),
+ factory::createRpcProviderService, rpcProviderServiceFactory),
+ new AdaptingTracker<>(ctx, DOMActionService.class, ActionService.class, factory::createActionService,
+ actionServiceFactory),
new AdaptingTracker<>(ctx, DOMActionProviderService.class, ActionProviderService.class,
- factory::createActionProviderService));
+ factory::createActionProviderService, actionProviderServiceFactory));
LOG.debug("Starting {} DOMService trackers", trackers.size());
trackers.forEach(ServiceTracker::open);
LOG.info("{} DOMService trackers started", trackers.size());
}
- @Override
- public void close() {
- final List<AdaptingTracker<?, ?>> toClose;
- synchronized (this) {
- toClose = trackers;
- trackers = ImmutableList.of();
- }
-
- LOG.debug("Stopping {} DOMService trackers", toClose.size());
- if (!toClose.isEmpty()) {
- toClose.forEach(AdaptingTracker::close);
- LOG.info("{} DOMService trackers stopped", toClose.size());
+ @Deactivate
+ void deactivate() {
+ LOG.debug("Stopping {} DOMService trackers", trackers.size());
+ if (!trackers.isEmpty()) {
+ trackers.forEach(AdaptingTracker::close);
+ LOG.info("{} DOMService trackers stopped", trackers.size());
}
+ trackers = ImmutableList.of();
}
}