Added config SI for io.netty.util.Timer and config module wrapper for HashedWheelTime...
[controller.git] / opendaylight / netconf / config-persister-impl / src / main / java / org / opendaylight / controller / netconf / persist / impl / ConfigPersisterNotificationHandler.java
index 47d5ff6f136ca84b10757c5599ac39da25cff06a..a20e00bcffcc114ab9849b821898280bc743b4b2 100644 (file)
@@ -11,12 +11,15 @@ package org.opendaylight.controller.netconf.persist.impl;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
 import org.opendaylight.controller.config.persist.api.Persister;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 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.opendaylight.controller.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
@@ -32,6 +35,7 @@ import javax.management.MBeanServerConnection;
 import javax.management.Notification;
 import javax.management.NotificationListener;
 import javax.management.ObjectName;
+import javax.net.ssl.SSLContext;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -50,6 +54,8 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
     private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterNotificationHandler.class);
 
     private final InetSocketAddress address;
+    private final NetconfClientDispatcher dispatcher;
+    private final EventLoopGroup nettyThreadgroup;
 
     private NetconfClient netconfClient;
 
@@ -73,6 +79,9 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         this.address = address;
         this.mbeanServer = mbeanServer;
         this.timeout = timeout;
+
+        this.nettyThreadgroup = new NioEventLoopGroup();
+        this.dispatcher = new NetconfClientDispatcher(Optional.<SSLContext>absent(), nettyThreadgroup, nettyThreadgroup);
     }
 
     public void init() throws InterruptedException {
@@ -117,7 +126,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
             attempt++;
 
             try {
-                netconfClient = new NetconfClient(this.toString(), address, delay);
+                netconfClient = new NetconfClient(this.toString(), address, delay, dispatcher);
                 // TODO is this correct ex to catch ?
             } catch (IllegalStateException e) {
                 logger.debug("Netconf {} was not initialized or is not stable, attempt {}", address, attempt, e);
@@ -309,6 +318,12 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
             }
         }
 
+        try {
+            nettyThreadgroup.shutdownGracefully();
+        } catch (Exception e) {
+            logger.warn("Unable to close netconf client thread group {}", dispatcher, e);
+        }
+
         // unregister from JMX
         try {
             if (mbeanServer.isRegistered(on)) {