From: Robert Varga Date: Mon, 27 Apr 2020 11:45:28 +0000 (+0200) Subject: Improve notification delivery defensiveness X-Git-Tag: v4.0.14~3 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=5fd148eb5a94099b7261b5fc905ad6462ea8d95e Improve notification delivery defensiveness 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 (cherry picked from commit bc58fd6b46acb6f94d6b9395a67f7112d134f0c1) --- diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterEvent.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterEvent.java index 8743fc90d7..9dd4f6a3ec 100644 --- a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterEvent.java +++ b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterEvent.java @@ -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 FACTORY = DOMNotificationRouterEvent::new; private Collection> subscribers; @@ -41,10 +44,16 @@ final class DOMNotificationRouterEvent { return this.future; } + @SuppressWarnings("checkstyle:illegalCatch") void deliverNotification() { - for (AbstractListenerRegistration r : subscribers) { - if (r.notClosed()) { - r.getInstance().onNotification(notification); + for (AbstractListenerRegistration 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 +}