Merge "Resolve Bug:593. Persister should communicate via OSGi SR instead of TCP."
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / impl / NotificationRouterImpl.java
index 6242dee038661da6d4d79685bc6e0a35b7c720da..7fba31114f6d53a2c491f91511109a32b6c8efec 100644 (file)
@@ -8,23 +8,10 @@
 package org.opendaylight.controller.sal.dom.broker.impl;
 
 import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
 
-import org.opendaylight.controller.sal.core.api.BrokerService;
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
-import org.opendaylight.controller.sal.core.api.Consumer.ConsumerFunctionality;
-import org.opendaylight.controller.sal.core.api.Provider.ProviderFunctionality;
 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
-import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
-import org.opendaylight.controller.sal.core.api.notify.NotificationService;
-import org.opendaylight.controller.sal.core.spi.BrokerModule;
 import org.opendaylight.controller.sal.dom.broker.spi.NotificationRouter;
-import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
@@ -32,25 +19,26 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
 
 public class NotificationRouterImpl implements NotificationRouter {
     private static Logger log = LoggerFactory.getLogger(NotificationRouterImpl.class);
 
-    private Multimap<QName, Registration<NotificationListener>> listeners = HashMultimap.create();
+    private final Multimap<QName, ListenerRegistration> listeners = Multimaps.synchronizedSetMultimap(HashMultimap.<QName, ListenerRegistration>create());
+//    private Registration<NotificationListener> defaultListener;
 
     private void sendNotification(CompositeNode notification) {
-        QName type = notification.getNodeType();
-        Collection<Registration<NotificationListener>> toNotify = listeners.get(type);
+        final QName type = notification.getNodeType();
+        final Collection<ListenerRegistration> toNotify = listeners.get(type);
         log.trace("Publishing notification " + type);
 
-        if (toNotify == null) {
-            // No listeners were registered - returns.
+        if ((toNotify == null) || toNotify.isEmpty()) {
+            log.debug("No listener registered for handling of notification {}", type);
             return;
         }
 
-        for (Registration<NotificationListener> listener : toNotify) {
+        for (ListenerRegistration listener : toNotify) {
             try {
                 // FIXME: ensure that notification is immutable
                 listener.getInstance().onNotification(notification);
@@ -58,7 +46,6 @@ public class NotificationRouterImpl implements NotificationRouter {
                 log.error("Uncaught exception in NotificationListener", e);
             }
         }
-
     }
 
     @Override
@@ -69,10 +56,11 @@ public class NotificationRouterImpl implements NotificationRouter {
     @Override
     public Registration<NotificationListener> addNotificationListener(QName notification, NotificationListener listener) {
         ListenerRegistration ret = new ListenerRegistration(notification, listener);
+        listeners.put(notification, ret);
         return ret;
     }
 
-    private class ListenerRegistration extends AbstractObjectRegistration<NotificationListener> {
+    private class ListenerRegistration extends AbstractListenerRegistration<NotificationListener> {
 
         final QName type;