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=e319d2cb679260718c9eade75234b9996170007c;hp=1c3ac7a455c4f80eb8a1607f1e942bb2c91f3977;hb=c5b0b028392646507133df0af5efcee547763b6d;hpb=eff404d4edd10fcde6d85c5821c80263339d9a4a 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 1c3ac7a455..e319d2cb67 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 @@ -8,10 +8,10 @@ package org.opendaylight.controller.netconf.persist.impl; +import org.opendaylight.controller.config.persist.api.Persister; import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification; import org.opendaylight.controller.netconf.api.jmx.DefaultCommitOperationMXBean; import org.opendaylight.controller.netconf.api.jmx.NetconfJMXNotification; -import org.opendaylight.controller.netconf.client.NetconfClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,40 +26,60 @@ import java.io.IOException; import java.util.regex.Pattern; /** - * Responsible for listening for notifications from netconf containing latest + * Responsible for listening for notifications from netconf (via JMX) containing latest * committed configuration that should be persisted, and also for loading last * configuration. */ @ThreadSafe -public class ConfigPersisterNotificationHandler implements NotificationListener, Closeable { +public class ConfigPersisterNotificationHandler implements Closeable { private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterNotificationHandler.class); private final MBeanServerConnection mBeanServerConnection; - private final NetconfClient netconfClient; - private final PersisterAggregator persisterAggregator; - private final Pattern ignoredMissingCapabilityRegex; + private final ConfigPersisterNotificationListener listener; + - public ConfigPersisterNotificationHandler(MBeanServerConnection mBeanServerConnection, NetconfClient netconfClient, - PersisterAggregator persisterAggregator, Pattern ignoredMissingCapabilityRegex) { + public ConfigPersisterNotificationHandler(MBeanServerConnection mBeanServerConnection, + Persister persisterAggregator, Pattern ignoredMissingCapabilityRegex) { this.mBeanServerConnection = mBeanServerConnection; - this.netconfClient = netconfClient; - this.persisterAggregator = persisterAggregator; - this.ignoredMissingCapabilityRegex = ignoredMissingCapabilityRegex; - } + listener = new ConfigPersisterNotificationListener(persisterAggregator, ignoredMissingCapabilityRegex); + registerAsJMXListener(mBeanServerConnection, listener); - public void init() { - registerAsJMXListener(); } - private void registerAsJMXListener() { + private static void registerAsJMXListener(MBeanServerConnection mBeanServerConnection, ConfigPersisterNotificationListener listener) { logger.trace("Called registerAsJMXListener"); try { - mBeanServerConnection.addNotificationListener(DefaultCommitOperationMXBean.objectName, this, null, null); + mBeanServerConnection.addNotificationListener(DefaultCommitOperationMXBean.objectName, listener, null, null); } catch (InstanceNotFoundException | IOException e) { throw new RuntimeException("Cannot register as JMX listener to netconf", e); } } + @Override + public synchronized void close() { + // unregister from JMX + ObjectName on = DefaultCommitOperationMXBean.objectName; + try { + if (mBeanServerConnection.isRegistered(on)) { + mBeanServerConnection.removeNotificationListener(on, listener); + } + } catch (Exception e) { + logger.warn("Unable to unregister {} as listener for {}", listener, on, e); + } + } +} + +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) { + this.persisterAggregator = persisterAggregator; + this.ignoredMissingCapabilityRegex = ignoredMissingCapabilityRegex; + } + @Override public void handleNotification(Notification notification, Object handback) { if (notification instanceof NetconfJMXNotification == false) @@ -68,12 +88,13 @@ public class ConfigPersisterNotificationHandler implements NotificationListener, // Socket should not be closed at this point // Activator unregisters this as JMX listener before close is called - logger.info("Received notification {}", notification); + logger.trace("Received notification {}", notification); if (notification instanceof CommitJMXNotification) { try { handleAfterCommitNotification((CommitJMXNotification) notification); - } catch (Exception e) { - // TODO: notificationBroadcast support logs only DEBUG + } catch (Throwable e) { + // log exceptions from notification Handler here since + // notificationBroadcastSupport logs only DEBUG level logger.warn("Exception occured during notification handling: ", e); throw e; } @@ -85,27 +106,9 @@ public class ConfigPersisterNotificationHandler implements NotificationListener, try { persisterAggregator.persistConfig(new CapabilityStrippingConfigSnapshotHolder(notification.getConfigSnapshot(), notification.getCapabilities(), ignoredMissingCapabilityRegex)); - logger.info("Configuration persisted successfully"); + logger.trace("Configuration persisted successfully"); } catch (IOException e) { throw new RuntimeException("Unable to persist configuration snapshot", e); } } - - @Override - public synchronized void close() { - // unregister from JMX - ObjectName on = DefaultCommitOperationMXBean.objectName; - try { - if (mBeanServerConnection.isRegistered(on)) { - mBeanServerConnection.removeNotificationListener(on, this); - } - } catch (Exception e) { - logger.warn("Unable to unregister {} as listener for {}", this, on, e); - } - } - - public NetconfClient getNetconfClient() { - return netconfClient; - } - -} +} \ No newline at end of file