Fix persister bug introduced in last commit. 68/3268/1
authorTomas Olvecky <tolvecky@cisco.com>
Sat, 30 Nov 2013 15:54:15 +0000 (16:54 +0100)
committerTomas Olvecky <tolvecky@cisco.com>
Sat, 30 Nov 2013 15:54:15 +0000 (16:54 +0100)
Registering to JMX failed due to previous bugfix.

Change-Id: I8be8751e299d7f10c7ed691b9bcefbd62308fcae
Signed-off-by: Tomas Olvecky <tolvecky@cisco.com>
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPersisterNotificationHandler.java

index ac6b5b28fd697fdf1290f3e5d8df2a6717834429..d83b1eaaf341931571ce723378f41145a3342154 100644 (file)
@@ -101,25 +101,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         if (maybeConfig.isPresent()) {
             logger.debug("Last config found {}", persister);
             ConflictingVersionException lastException = null;
-            int maxAttempts = 30;
-            for(int i = 0 ; i < maxAttempts; i++) {
-                registerToNetconf(maybeConfig.get().getCapabilities());
-
-                final String configSnapshot = maybeConfig.get().getConfigSnapshot();
-                logger.trace("Pushing following xml to netconf {}", configSnapshot);
-                try {
-                    pushLastConfig(XmlUtil.readXmlToElement(configSnapshot));
-                    return;
-                } catch(ConflictingVersionException e) {
-                    closeClientAndDispatcher(netconfClient, netconfClientDispatcher);
-                    lastException = e;
-                    Thread.sleep(1000);
-                } catch (SAXException | IOException e) {
-                    throw new IllegalStateException("Unable to load last config", e);
-                }
-            }
-            throw new IllegalStateException("Failed to push configuration, maximum attempt count has been reached: "
-                    + maxAttempts, lastException);
+            pushLastConfigWithRetries(maybeConfig, lastException);
 
         } else {
             // this ensures that netconf is initialized, this is first
@@ -132,6 +114,28 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         registerAsJMXListener();
     }
 
+    private void pushLastConfigWithRetries(Optional<ConfigSnapshotHolder> maybeConfig, ConflictingVersionException lastException) throws InterruptedException {
+        int maxAttempts = 30;
+        for(int i = 0 ; i < maxAttempts; i++) {
+            registerToNetconf(maybeConfig.get().getCapabilities());
+
+            final String configSnapshot = maybeConfig.get().getConfigSnapshot();
+            logger.trace("Pushing following xml to netconf {}", configSnapshot);
+            try {
+                pushLastConfig(XmlUtil.readXmlToElement(configSnapshot));
+                return;
+            } catch(ConflictingVersionException e) {
+                closeClientAndDispatcher(netconfClient, netconfClientDispatcher);
+                lastException = e;
+                Thread.sleep(1000);
+            } catch (SAXException | IOException e) {
+                throw new IllegalStateException("Unable to load last config", e);
+            }
+        }
+        throw new IllegalStateException("Failed to push configuration, maximum attempt count has been reached: "
+                + maxAttempts, lastException);
+    }
+
     private synchronized long registerToNetconf(Set<String> expectedCaps) throws InterruptedException {
 
         Set<String> currentCapabilities = Sets.newHashSet();
@@ -209,6 +213,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
     }
 
     private void registerAsJMXListener() {
+        logger.trace("Called registerAsJMXListener");
         try {
             mbeanServer.addNotificationListener(on, this, null, null);
         } catch (InstanceNotFoundException | IOException e) {