Added constructor which allows for custom NetconfClientSessionListener 36/4036/1
authorTony Tkacik <ttkacik@cisco.com>
Mon, 6 Jan 2014 19:53:59 +0000 (20:53 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 6 Jan 2014 19:56:50 +0000 (20:56 +0100)
Change-Id: I95c1f59a704c91cb1c06c1765935612fc13bc890
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java

index 2ce779a1f54e9ce4f68b9c7f1db478d9de4e0201..8b8c886a1c0328b558a4992c7d67b6b99b71800c 100644 (file)
@@ -71,6 +71,10 @@ public class NetconfClient implements Closeable {
         return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher);
     }
 
+    public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher,NetconfClientSessionListener listener) throws InterruptedException {
+        return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher,listener);
+    }
+
     public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs,
             NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
         this(clientLabelForLogging, address,
@@ -83,6 +87,17 @@ public class NetconfClient implements Closeable {
                 DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher);
     }
 
+    public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat,
+            NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException{
+        this.label = clientLabelForLogging;
+        dispatch = netconfClientDispatcher;
+        sessionListener = listener;
+        Future<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strat);
+        this.address = address;
+        clientSession = get(clientFuture);
+        this.sessionId = clientSession.getSessionId();
+    }
+
     public NetconfMessage sendMessage(NetconfMessage message) {
         return sendMessage(message, 5, 1000);
     }
@@ -90,6 +105,7 @@ public class NetconfClient implements Closeable {
     public NetconfMessage sendMessage(NetconfMessage message, int attempts, int attemptMsDelay) {
         long startTime = System.currentTimeMillis();
         Preconditions.checkState(clientSession.isUp(), "Session was not up yet");
+        //logger.debug("Sending message: {}",XmlUtil.toString(message.getDocument()));
         clientSession.sendMessage(message);
         try {
             return sessionListener.getLastMessage(attempts, attemptMsDelay);