Fix of issue 377 for Notifications resolving.
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / NotificationBrokerImpl.xtend
index 52aa8d029066b3093a90300f6bb078886b2b3d7b..d997af59126833190b26696e752dfcc7061fe352 100644 (file)
@@ -21,14 +21,20 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration
 import org.opendaylight.yangtools.concepts.Registration\r
 import org.opendaylight.yangtools.yang.binding.Notification\r
 import org.slf4j.LoggerFactory\r
-import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder\rimport com.google.common.collect.Multimaps
-
-class NotificationBrokerImpl implements NotificationProviderService, AutoCloseable {\r
+import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder\rimport com.google.common.collect.Multimaps\r
+import org.opendaylight.yangtools.concepts.util.ListenerRegistry\r
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService.NotificationInterestListener\r
 \r
+class NotificationBrokerImpl implements NotificationProviderService, AutoCloseable {\r
+    \r
+    val ListenerRegistry<NotificationInterestListener> interestListeners = ListenerRegistry.create;\r
+    \r
     val Multimap<Class<? extends Notification>, NotificationListener<?>> listeners;\r
 \r
     @Property\r
     var ExecutorService executor;\r
+    \r
+    val logger = LoggerFactory.getLogger(NotificationBrokerImpl)\r
 \r
     new() {\r
         listeners = Multimaps.synchronizedSetMultimap(HashMultimap.create())\r
@@ -101,14 +107,26 @@ class NotificationBrokerImpl implements NotificationProviderService, AutoCloseab
         NotificationListener<T> listener) {\r
         val reg = new GenericNotificationRegistration<T>(notificationType, listener, this);\r
         listeners.put(notificationType, listener);\r
+        announceNotificationSubscription(notificationType);\r
         return reg;\r
     }\r
+    \r
+    def announceNotificationSubscription(Class<? extends Notification> notification) {\r
+        for (listener : interestListeners) {\r
+            try {\r
+                listener.instance.onNotificationSubscribtion(notification);\r
+            } catch (Exception e) {\r
+                logger.error("", e.message)\r
+            }\r
+        }\r
+    }\r
 \r
     override registerNotificationListener(\r
         org.opendaylight.yangtools.yang.binding.NotificationListener listener) {\r
         val invoker = SingletonHolder.INVOKER_FACTORY.invokerFor(listener);\r
         for (notifyType : invoker.supportedNotifications) {\r
             listeners.put(notifyType, invoker.invocationProxy)\r
+            announceNotificationSubscription(notifyType)\r
         }\r
         val registration = new GeneratedListenerRegistration(listener, invoker,this);\r
         return registration as Registration<org.opendaylight.yangtools.yang.binding.NotificationListener>;\r
@@ -128,6 +146,14 @@ class NotificationBrokerImpl implements NotificationProviderService, AutoCloseab
         //FIXME: implement properly.\r
     }\r
     \r
+    override registerInterestListener(NotificationInterestListener interestListener) {\r
+        val registration = interestListeners.register(interestListener);\r
+        \r
+        for(notification : listeners.keySet) {\r
+            interestListener.onNotificationSubscribtion(notification);\r
+        }\r
+        return registration\r
+    }\r
 }\r
 \r
 class GenericNotificationRegistration<T extends Notification> extends AbstractObjectRegistration<NotificationListener<T>> implements ListenerRegistration<NotificationListener<T>> {\r