Remove DOMDataTreeShard and all related interfaces
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / osgi / DynamicBindingAdapter.java
index aaaa6b7bf00a0f5e002a08e9d9a4e3d1ccee2b69..cfa9904218cc6ce25836417076bc7779fb4cb5fc 100644 (file)
@@ -9,25 +9,19 @@ package org.opendaylight.mdsal.binding.dom.adapter.osgi;
 
 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.binding.api.RpcConsumerRegistry;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMDataBrokerAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMDataTreeServiceAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMMountPointServiceAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMNotificationPublishServiceAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMNotificationServiceAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMRpcProviderServiceAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMRpcServiceAdapter;
-import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
+import org.opendaylight.mdsal.binding.dom.adapter.spi.AdapterFactory;
+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;
@@ -35,6 +29,11 @@ import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 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;
@@ -45,46 +44,63 @@ 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 BindingToNormalizedNodeCodec codec, 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, codec,
-                    BindingDOMDataBrokerAdapter::new),
-            new AdaptingTracker<>(ctx, DOMDataTreeService.class, DataTreeService.class, codec,
-                    BindingDOMDataTreeServiceAdapter::create),
-            new AdaptingTracker<>(ctx, DOMMountPointService.class, MountPointService.class, codec,
-                    BindingDOMMountPointServiceAdapter::new),
-            new AdaptingTracker<>(ctx, DOMNotificationService.class, NotificationService.class, codec,
-                    BindingDOMNotificationServiceAdapter::new),
-            new AdaptingTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class, codec,
-                    BindingDOMNotificationPublishServiceAdapter::new),
-            new AdaptingTracker<>(ctx, DOMRpcService.class, RpcConsumerRegistry.class, codec,
-                    BindingDOMRpcServiceAdapter::new),
-            new AdaptingTracker<>(ctx, DOMRpcProviderService.class, RpcProviderService.class, codec,
-                    BindingDOMRpcProviderServiceAdapter::new));
+            new AdaptingTracker<>(ctx, DOMDataBroker.class, DataBroker.class, factory::createDataBroker,
+                    dataBrokerFactory),
+            new AdaptingTracker<>(ctx, DOMMountPointService.class, MountPointService.class,
+                    factory::createMountPointService, mountPointServiceFactory),
+            new AdaptingTracker<>(ctx, DOMNotificationService.class, NotificationService.class,
+                    factory::createNotificationService, notificationServiceFactory),
+            new AdaptingTracker<>(ctx, DOMNotificationPublishService.class, NotificationPublishService.class,
+                    factory::createNotificationPublishService, notificationPublishServiceFactory),
+            new AdaptingTracker<>(ctx, DOMRpcService.class, RpcConsumerRegistry.class,
+                    factory::createRpcConsumerRegistry, rpcConsumerRegistryFactory),
+            new AdaptingTracker<>(ctx, DOMRpcProviderService.class, RpcProviderService.class,
+                    factory::createRpcProviderService, rpcProviderServiceFactory),
+            new AdaptingTracker<>(ctx, DOMActionService.class, ActionService.class, factory::createActionService,
+                    actionServiceFactory),
+            new AdaptingTracker<>(ctx, DOMActionProviderService.class, ActionProviderService.class,
+                    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();
     }
 }