Improve notification delivery defensiveness 88/89488/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 27 Apr 2020 11:45:28 +0000 (13:45 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Apr 2020 10:16:31 +0000 (12:16 +0200)
If a listener throws an exception, make sure to log it and proceed
as if nothing happened.

JIRA: MDSAL-544
Change-Id: I0ca54bb5c517115b840ad03ea24d442c7762ff05
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit bc58fd6b46acb6f94d6b9395a67f7112d134f0c1)

dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterEvent.java

index 8743fc90d72f038853794a20eb414b7c1a370f81..9dd4f6a3ec999aab0a58261c6e3ae21a31a31a8b 100644 (file)
@@ -16,12 +16,15 @@ import java.util.Collection;
 import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * A single notification event in the disruptor ringbuffer. These objects are reused,
- * so they do have mutable state.
+ * A single notification event in the disruptor ringbuffer. These objects are reused, so they do have mutable state.
  */
 final class DOMNotificationRouterEvent {
+    private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
+
     static final EventFactory<DOMNotificationRouterEvent> FACTORY = DOMNotificationRouterEvent::new;
 
     private Collection<AbstractListenerRegistration<? extends DOMNotificationListener>> subscribers;
@@ -41,10 +44,16 @@ final class DOMNotificationRouterEvent {
         return this.future;
     }
 
+    @SuppressWarnings("checkstyle:illegalCatch")
     void deliverNotification() {
-        for (AbstractListenerRegistration<? extends DOMNotificationListener> r : subscribers) {
-            if (r.notClosed()) {
-                r.getInstance().onNotification(notification);
+        for (AbstractListenerRegistration<? extends DOMNotificationListener> reg : subscribers) {
+            if (reg.notClosed()) {
+                final DOMNotificationListener listener = reg.getInstance();
+                try {
+                    listener.onNotification(notification);
+                } catch (Exception e) {
+                    LOG.warn("Listener {} failed during notification delivery", listener, e);
+                }
             }
         }
     }
@@ -52,5 +61,4 @@ final class DOMNotificationRouterEvent {
     void setFuture() {
         future.set(null);
     }
-
-}
\ No newline at end of file
+}