X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2FConfigPersisterNotificationHandler.java;h=40a15be70616217d81529b003f899236865d8ac8;hp=e319d2cb679260718c9eade75234b9996170007c;hb=386d8f0ac5fa09ee5514d48284f1a4012f408b52;hpb=c61d22e4dc73fdaba09aa8c0b189ea7459679e03 diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java index e319d2cb67..40a15be706 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java @@ -23,7 +23,6 @@ import javax.management.NotificationListener; import javax.management.ObjectName; import java.io.Closeable; import java.io.IOException; -import java.util.regex.Pattern; /** * Responsible for listening for notifications from netconf (via JMX) containing latest @@ -39,9 +38,9 @@ public class ConfigPersisterNotificationHandler implements Closeable { public ConfigPersisterNotificationHandler(MBeanServerConnection mBeanServerConnection, - Persister persisterAggregator, Pattern ignoredMissingCapabilityRegex) { + Persister persisterAggregator) { this.mBeanServerConnection = mBeanServerConnection; - listener = new ConfigPersisterNotificationListener(persisterAggregator, ignoredMissingCapabilityRegex); + listener = new ConfigPersisterNotificationListener(persisterAggregator); registerAsJMXListener(mBeanServerConnection, listener); } @@ -49,16 +48,16 @@ public class ConfigPersisterNotificationHandler implements Closeable { private static void registerAsJMXListener(MBeanServerConnection mBeanServerConnection, ConfigPersisterNotificationListener listener) { logger.trace("Called registerAsJMXListener"); try { - mBeanServerConnection.addNotificationListener(DefaultCommitOperationMXBean.objectName, listener, null, null); + mBeanServerConnection.addNotificationListener(DefaultCommitOperationMXBean.OBJECT_NAME, listener, null, null); } catch (InstanceNotFoundException | IOException e) { - throw new RuntimeException("Cannot register as JMX listener to netconf", e); + throw new IllegalStateException("Cannot register as JMX listener to netconf", e); } } @Override public synchronized void close() { // unregister from JMX - ObjectName on = DefaultCommitOperationMXBean.objectName; + ObjectName on = DefaultCommitOperationMXBean.OBJECT_NAME; try { if (mBeanServerConnection.isRegistered(on)) { mBeanServerConnection.removeNotificationListener(on, listener); @@ -73,16 +72,14 @@ class ConfigPersisterNotificationListener implements NotificationListener { private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterNotificationListener.class); private final Persister persisterAggregator; - private final Pattern ignoredMissingCapabilityRegex; - ConfigPersisterNotificationListener(Persister persisterAggregator, Pattern ignoredMissingCapabilityRegex) { + ConfigPersisterNotificationListener(Persister persisterAggregator) { this.persisterAggregator = persisterAggregator; - this.ignoredMissingCapabilityRegex = ignoredMissingCapabilityRegex; } @Override public void handleNotification(Notification notification, Object handback) { - if (notification instanceof NetconfJMXNotification == false) + if (!(notification instanceof NetconfJMXNotification)) return; // Socket should not be closed at this point @@ -92,23 +89,24 @@ class ConfigPersisterNotificationListener implements NotificationListener { if (notification instanceof CommitJMXNotification) { try { handleAfterCommitNotification((CommitJMXNotification) notification); - } catch (Throwable e) { + } catch (Exception e) { // log exceptions from notification Handler here since // notificationBroadcastSupport logs only DEBUG level - logger.warn("Exception occured during notification handling: ", e); + logger.warn("Failed to handle notification {}", notification, e); throw e; } - } else + } else { throw new IllegalStateException("Unknown config registry notification type " + notification); + } } private void handleAfterCommitNotification(final CommitJMXNotification notification) { try { persisterAggregator.persistConfig(new CapabilityStrippingConfigSnapshotHolder(notification.getConfigSnapshot(), - notification.getCapabilities(), ignoredMissingCapabilityRegex)); + notification.getCapabilities())); logger.trace("Configuration persisted successfully"); } catch (IOException e) { throw new RuntimeException("Unable to persist configuration snapshot", e); } } -} \ No newline at end of file +}