Bug 3148 - Fixed binding.api.NotificationListener support
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / NotificationBrokerImplModule.java
index b6c27a6332c4fdc7ddc6c08e25970f51431c8260..ec4bc76f554f3a8fb7bcff890fc1c047743b7057 100644 (file)
@@ -7,10 +7,16 @@
  */
 package org.opendaylight.controller.config.yang.md.sal.binding.impl;
 
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
+import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceWithInterestListeners;
+import org.opendaylight.controller.md.sal.binding.compat.HydrogenNotificationBrokerImpl;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService;
+import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
 import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
-import org.opendaylight.controller.sal.binding.impl.NotificationBrokerImpl;
-
-import com.google.common.util.concurrent.ListeningExecutorService;
 
 /**
 *
@@ -18,14 +24,14 @@ import com.google.common.util.concurrent.ListeningExecutorService;
 public final class NotificationBrokerImplModule extends
         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractNotificationBrokerImplModule {
 
-    public NotificationBrokerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+    public NotificationBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+            final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public NotificationBrokerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
-            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-            NotificationBrokerImplModule oldModule, java.lang.AutoCloseable oldInstance) {
+    public NotificationBrokerImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+            final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+            final NotificationBrokerImplModule oldModule, final java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
@@ -37,8 +43,39 @@ public final class NotificationBrokerImplModule extends
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        ListeningExecutorService listeningExecutor = SingletonHolder.getDefaultNotificationExecutor();
-        NotificationBrokerImpl broker = new NotificationBrokerImpl(listeningExecutor);
-        return broker;
+
+        final NotificationPublishService notificationPublishService = getNotificationPublishAdapterDependency();
+        final NotificationService notificationService = getNotificationAdapterDependency();
+
+        if(notificationPublishService != null & notificationService != null) {
+            return createHeliumAdapter(notificationPublishService,notificationService);
+        }
+
+        /*
+         *  FIXME: Switch to new broker (which has different threading model)
+         *  once this change is communicated with downstream users or
+         *  we will have adapter implementation which will honor Helium
+         *  threading model for notifications.
+         */
+        return new HydrogenNotificationBrokerImpl(SingletonHolder.getDefaultNotificationExecutor());
+    }
+
+    private static AutoCloseable createHeliumAdapter(final NotificationPublishService publishService,
+            final NotificationService listenService) {
+        if (listenService instanceof BindingDOMNotificationServiceAdapter
+                && publishService instanceof BindingDOMNotificationPublishServiceAdapter) {
+            final BindingDOMNotificationPublishServiceAdapter castedPublish =
+                    (BindingDOMNotificationPublishServiceAdapter) publishService;
+            final BindingDOMNotificationServiceAdapter castedListen =
+                    (BindingDOMNotificationServiceAdapter) listenService;
+            final DOMNotificationPublishService domPublishService = castedPublish.getDomPublishService();
+            if (domPublishService instanceof DOMNotificationSubscriptionListenerRegistry) {
+                final DOMNotificationSubscriptionListenerRegistry subsRegistry =
+                        (DOMNotificationSubscriptionListenerRegistry) domPublishService;
+                return new HeliumNotificationProviderServiceWithInterestListeners(castedPublish, castedListen,
+                        subsRegistry);
+            }
+        }
+        return new HeliumNotificationProviderServiceAdapter(publishService, listenService);
     }
 }