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=4cdca208bc5e472088b07741b958c2e716e3f2dd;hb=c16bb7d2401d0f013e6dae3d0d877e3b7a208e46;hp=b8951a4789e1f1b4bc305cf6ed0c824a8e960ccf;hpb=7755106575294f8b0c938127cd813fcc85a8f7f9;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 b8951a4789..4cdca208bc 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,17 +8,8 @@ package org.opendaylight.controller.netconf.client; -import com.google.common.base.Preconditions; -import com.google.common.base.Stopwatch; -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 java.io.Closeable; import java.io.IOException; @@ -27,7 +18,23 @@ import java.util.Set; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +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.base.Stopwatch; +import com.google.common.collect.Sets; +/** + * @deprecated Use {@link NetconfClientDispatcher.createClient()} or {@link NetconfClientDispatcher.createReconnectingClient()} instead. + */ +@Deprecated public class NetconfClient implements Closeable { private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class); @@ -50,7 +57,7 @@ public class NetconfClient implements Closeable { private NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { this.label = clientLabelForLogging; dispatch = netconfClientDispatcher; - sessionListener = new NetconfClientSessionListener(); + sessionListener = new SimpleNetconfClientSessionListener(); Future clientFuture = dispatch.createClient(address, sessionListener, strat); this.address = address; clientSession = get(clientFuture); @@ -71,7 +78,8 @@ public class NetconfClient implements Closeable { return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher); } - public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher,NetconfClientSessionListener listener) throws InterruptedException { + public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, + ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException { return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher,listener); } @@ -98,25 +106,31 @@ public class NetconfClient implements Closeable { this.sessionId = clientSession.getSessionId(); } - public NetconfMessage sendMessage(NetconfMessage message) { + public Future sendRequest(NetconfMessage message) { + return ((SimpleNetconfClientSessionListener)sessionListener).sendRequest(message); + } + + /** + * @deprecated Use {@link sendRequest} instead + */ + @Deprecated + public NetconfMessage sendMessage(NetconfMessage message) throws ExecutionException, InterruptedException, TimeoutException { return sendMessage(message, 5, 1000); } - public NetconfMessage sendMessage(NetconfMessage message, int attempts, int attemptMsDelay) { - Stopwatch stopwatch = new Stopwatch().start(); - Preconditions.checkState(clientSession.isUp(), "Session was not up yet"); + /** + * @deprecated Use {@link sendRequest} instead + */ + @Deprecated + public NetconfMessage sendMessage(NetconfMessage message, int attempts, int attemptMsDelay) throws ExecutionException, InterruptedException, TimeoutException { //logger.debug("Sending message: {}",XmlUtil.toString(message.getDocument())); - clientSession.sendMessage(message); + final Stopwatch stopwatch = new Stopwatch().start(); + try { - return sessionListener.getLastMessage(attempts, attemptMsDelay); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException(this + " Cannot read message from " + address, e); - } catch (IllegalStateException e) { - throw new IllegalStateException(this + " Cannot read message from " + address, e); + return sendRequest(message).get(attempts * attemptMsDelay, TimeUnit.MILLISECONDS); } finally { stopwatch.stop(); - logger.debug("Total time spent waiting for response {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS)); + logger.debug("Total time spent waiting for response from {}: {} ms", address, stopwatch.elapsed(TimeUnit.MILLISECONDS)); } }