Do not fail if invoking of listener fails 13/81413/5
authorJakub Morvay <jakub.morvay@gmail.com>
Sat, 6 Apr 2019 09:19:13 +0000 (11:19 +0200)
committerJakub Morvay <jakub.morvay@gmail.com>
Sun, 7 Apr 2019 11:01:52 +0000 (13:01 +0200)
DOMMountPointServiceImpl should not fail and propagate uncaught
exceptions from mount point listeners. When invocation of a registered
listener onMounPpointCreated or onMounPointRemoved callback fails, just
log the error and continue execution.

Change-Id: I5d182b610c0b5749cfe01efc13bc1dddfffa5283
Signed-off-by: Jakub Morvay <jakub.morvay@gmail.com>
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMMountPointServiceImpl.java

index 1e34e21e38b4cf3f139b2e64d0d233145ce2dfac..5579ade7c0fb8114a5e44cc202215e2b98c00885 100644 (file)
@@ -53,13 +53,20 @@ public class DOMMountPointServiceImpl implements DOMMountPointService {
         return listeners.register(listener);
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private ObjectRegistration<DOMMountPoint> registerMountPoint(final SimpleDOMMountPoint mountPoint) {
         final YangInstanceIdentifier mountPointId = mountPoint.getIdentifier();
         synchronized (mountPoints) {
             final DOMMountPoint prev = mountPoints.putIfAbsent(mountPointId, mountPoint);
             checkState(prev == null, "Mount point %s already exists as %s", mountPointId, prev);
         }
-        listeners.forEach(listener -> listener.getInstance().onMountPointCreated(mountPointId));
+        listeners.forEach(listener -> {
+            try {
+                listener.getInstance().onMountPointCreated(mountPointId);
+            } catch (final Exception ex) {
+                LOG.error("Listener {} failed on mount point {} created event", listener, mountPoint, ex);
+            }
+        });
 
         return new AbstractObjectRegistration<DOMMountPoint>(mountPoint) {
             @Override
@@ -69,6 +76,7 @@ public class DOMMountPointServiceImpl implements DOMMountPointService {
         };
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private void unregisterMountPoint(final YangInstanceIdentifier mountPointId) {
         synchronized (mountPoints) {
             if (mountPoints.remove(mountPointId) == null) {
@@ -77,7 +85,13 @@ public class DOMMountPointServiceImpl implements DOMMountPointService {
             }
         }
 
-        listeners.forEach(listener -> listener.getInstance().onMountPointRemoved(mountPointId));
+        listeners.forEach(listener -> {
+            try {
+                listener.getInstance().onMountPointRemoved(mountPointId);
+            } catch (final Exception ex) {
+                LOG.error("Listener {} failed on mount point {} removed event", listener, mountPointId, ex);
+            }
+        });
     }
 
     final class DOMMountPointBuilderImpl implements DOMMountPointBuilder {