X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClient.java;h=d95977492a9206fb0ff05d4e6229810b08dcda9a;hb=25ba6b145406b98f8521bcf510bb85bf0167ef72;hp=b5a06ca0ab47f5ff13b0f016152ac081d26f0e6f;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java index b5a06ca0ab..d95977492a 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java @@ -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,16 +42,14 @@ public class NetconfClient implements Closeable { // TODO test reconnecting constructor public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectionAttempts, - int attemptMsTimeout) { - this(clientLabelForLogging, address, getReconnectStrategy(connectionAttempts, attemptMsTimeout), Optional - . absent()); + int attemptMsTimeout, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this(clientLabelForLogging, address, getReconnectStrategy(connectionAttempts, attemptMsTimeout), + netconfClientDispatcher); } - private NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, - Optional maybeSSLContext) { + 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 clientFuture = dispatch.createClient(address, sessionListener, strat); this.address = address; @@ -59,10 +57,10 @@ public class NetconfClient implements Closeable { this.sessionId = clientSession.getSessionId(); } - private NetconfClientSession get(Future clientFuture) { + private NetconfClientSession get(Future clientFuture) throws InterruptedException { try { return clientFuture.get(); - } catch (InterruptedException | CancellationException e) { + } catch (CancellationException e) { throw new RuntimeException("Netconf client interrupted", e); } catch (ExecutionException e) { throw new IllegalStateException("Unable to create netconf client", e); @@ -70,25 +68,15 @@ public class NetconfClient implements Closeable { } public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs, - Optional maybeSSLContext) { + 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) { - this(clientLabelForLogging, address, - new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), Optional - . absent()); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address) { - this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, - DEFAULT_CONNECT_TIMEOUT), Optional. absent()); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, Optional maybeSSLContext) { + 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) { @@ -110,7 +98,6 @@ public class NetconfClient implements Closeable { @Override public void close() throws IOException { clientSession.close(); - dispatch.close(); } private static ReconnectStrategy getReconnectStrategy(int connectionAttempts, int attemptMsTimeout) { @@ -135,4 +122,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; + } }