Bug 3234: Do not notify empty Rpc implementation change.
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / broker / impl / DOMRpcRouter.java
index d72f714a5f83d8b061697ce599c5c0d9748db7ad..14e75e22c6c6572f62f802901bd0e9e356d93097 100644 (file)
@@ -67,22 +67,23 @@ public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcP
         final DOMRpcRoutingTable newTable = oldTable.remove(implementation, rpcs);
 
         final Collection<DOMRpcIdentifier> removedRpcs = notPresentRpcs(newTable, rpcs);
-        final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
         routingTable = newTable;
-
-        listenerNotifier.execute(new Runnable() {
-            @Override
-            public void run() {
-                for (ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
-                    // Need to ensure removed listeners do not get notified
-                    synchronized (DOMRpcRouter.this) {
-                        if (listeners.contains(l)) {
-                            l.getInstance().onRpcUnavailable(removedRpcs);
+        if(!removedRpcs.isEmpty()) {
+            final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
+            listenerNotifier.execute(new Runnable() {
+                @Override
+                public void run() {
+                    for (final ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
+                        // Need to ensure removed listeners do not get notified
+                        synchronized (DOMRpcRouter.this) {
+                            if (listeners.contains(l)) {
+                                l.getInstance().onRpcUnavailable(removedRpcs);
+                            }
                         }
                     }
                 }
-            }
-        });
+            });
+        }
     }
 
     @Override
@@ -91,22 +92,24 @@ public final class DOMRpcRouter implements AutoCloseable, DOMRpcService, DOMRpcP
         final DOMRpcRoutingTable newTable = oldTable.add(implementation, rpcs);
 
         final Collection<DOMRpcIdentifier> addedRpcs = notPresentRpcs(oldTable, rpcs);
-        final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
         routingTable = newTable;
 
-        listenerNotifier.execute(new Runnable() {
-            @Override
-            public void run() {
-                for (ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
-                    // Need to ensure removed listeners do not get notified
-                    synchronized (DOMRpcRouter.this) {
-                        if (listeners.contains(l)) {
-                            l.getInstance().onRpcAvailable(addedRpcs);
+        if(!addedRpcs.isEmpty()) {
+            final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
+            listenerNotifier.execute(new Runnable() {
+                @Override
+                public void run() {
+                    for (final ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
+                        // Need to ensure removed listeners do not get notified
+                        synchronized (DOMRpcRouter.this) {
+                            if (listeners.contains(l)) {
+                                l.getInstance().onRpcAvailable(addedRpcs);
+                            }
                         }
                     }
                 }
-            }
-        });
+            });
+        }
 
         return new AbstractDOMRpcImplementationRegistration<T>(implementation) {
             @Override