MD-SAL StatisticsManager- Stopping statistics thread until i fix all the relevant
[controller.git] / opendaylight / netconf / netconf-client / src / main / java / org / opendaylight / controller / netconf / client / NetconfClient.java
index b8372b618c2d2b20bfaf1e1e8117b9d065b7cb4f..61a9a9b9548bc6eeb771dcf952c61e08e4a669f3 100644 (file)
@@ -8,19 +8,9 @@
 
 package org.opendaylight.controller.netconf.client;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.protocol.framework.NeverReconnectStrategy;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.TimedReconnectStrategy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.SSLContext;
 import java.io.Closeable;
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -28,6 +18,16 @@ import java.util.Set;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 
+import org.opendaylight.controller.netconf.api.NetconfMessage;
+import org.opendaylight.protocol.framework.NeverReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.TimedReconnectStrategy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+
 public class NetconfClient implements Closeable {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class);
@@ -42,15 +42,14 @@ public class NetconfClient implements Closeable {
 
     // TODO test reconnecting constructor
     public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectionAttempts,
-            int attemptMsTimeout) throws InterruptedException {
-        this(clientLabelForLogging, address, getReconnectStrategy(connectionAttempts, attemptMsTimeout), Optional
-                .<SSLContext> absent());
+            int attemptMsTimeout, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
+        this(clientLabelForLogging, address, getReconnectStrategy(connectionAttempts, attemptMsTimeout),
+                netconfClientDispatcher);
     }
 
-    private NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat,
-            Optional<SSLContext> maybeSSLContext) throws InterruptedException {
+    private NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
         this.label = clientLabelForLogging;
-        dispatch = new NetconfClientDispatcher(maybeSSLContext);
+        dispatch = netconfClientDispatcher;
 
         sessionListener = new NetconfClientSessionListener();
         Future<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strat);
@@ -70,27 +69,15 @@ public class NetconfClient implements Closeable {
     }
 
     public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs,
-            Optional<SSLContext> maybeSSLContext) throws InterruptedException {
+            NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
         this(clientLabelForLogging, address,
-                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), maybeSSLContext);
+                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), netconfClientDispatcher);
     }
 
-    public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs)
-            throws InterruptedException {
-        this(clientLabelForLogging, address,
-                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), Optional
-                        .<SSLContext> absent());
-    }
-
-    public NetconfClient(String clientLabelForLogging, InetSocketAddress address) throws InterruptedException {
-        this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE,
-                DEFAULT_CONNECT_TIMEOUT), Optional.<SSLContext> absent());
-    }
-
-    public NetconfClient(String clientLabelForLogging, InetSocketAddress address, Optional<SSLContext> maybeSSLContext)
-            throws InterruptedException {
+    public NetconfClient(String clientLabelForLogging, InetSocketAddress address,
+            NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
         this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE,
-                DEFAULT_CONNECT_TIMEOUT), maybeSSLContext);
+                DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher);
     }
 
     public NetconfMessage sendMessage(NetconfMessage message) {
@@ -112,7 +99,6 @@ public class NetconfClient implements Closeable {
     @Override
     public void close() throws IOException {
         clientSession.close();
-        dispatch.close();
     }
 
     private static ReconnectStrategy getReconnectStrategy(int connectionAttempts, int attemptMsTimeout) {
@@ -137,4 +123,8 @@ public class NetconfClient implements Closeable {
         Preconditions.checkState(clientSession != null, "Client was not initialized successfully");
         return Sets.newHashSet(clientSession.getServerCapabilities());
     }
+
+    public NetconfClientSession getClientSession() {
+        return clientSession;
+    }
 }