Inline AsyncSshHandler.startSsh() 11/102711/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Oct 2022 18:51:13 +0000 (20:51 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 08:07:03 +0000 (10:07 +0200)
There is just no reason to have this method split out, inline it to its
sole user -- which is making interactions a bit clearer. We also see
that there is a blocking call, holding up the caller until the
connection succeeds.

JIRA: NETCONF-905
Change-Id: Iae781a743e670498c9329162bb05a7475f32d370
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java

index 0d2f6e1aa5aa42868fb6bcec746a87ee168139a9..325c7062b65770f3ce0eddd7593f64cafe6b4d73 100644 (file)
@@ -102,20 +102,6 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
                 negotiationFuture);
     }
 
                 negotiationFuture);
     }
 
-    private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) throws IOException {
-        LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel());
-
-        final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address)
-               .verify(ctx.channel().config().getConnectTimeoutMillis(), TimeUnit.MILLISECONDS);
-        sshConnectionFuture.addListener(future -> {
-            if (future.isConnected()) {
-                handleSshSessionCreated(future, ctx);
-            } else {
-                handleSshSetupFailure(ctx, future.getException());
-            }
-        });
-    }
-
     private synchronized void handleSshSessionCreated(final ConnectFuture future, final ChannelHandlerContext ctx) {
         try {
             LOG.trace("SSH session created on channel: {}", ctx.channel());
     private synchronized void handleSshSessionCreated(final ConnectFuture future, final ChannelHandlerContext ctx) {
         try {
             LOG.trace("SSH session created on channel: {}", ctx.channel());
@@ -188,7 +174,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
 
     @Override
     public synchronized void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
 
     @Override
     public synchronized void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
-                                     final SocketAddress localAddress, final ChannelPromise promise) throws Exception {
+            final SocketAddress localAddress, final ChannelPromise promise) throws IOException {
         LOG.debug("SSH session connecting on channel {}. promise: {}", ctx.channel(), promise);
         connectPromise = requireNonNull(promise);
 
         LOG.debug("SSH session connecting on channel {}. promise: {}", ctx.channel(), promise);
         connectPromise = requireNonNull(promise);
 
@@ -201,7 +187,19 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
             //complete connection promise with netconf negotiation future
             negotiationFuture.addListener(negotiationFutureListener);
         }
             //complete connection promise with netconf negotiation future
             negotiationFuture.addListener(negotiationFutureListener);
         }
-        startSsh(ctx, remoteAddress);
+
+        LOG.debug("Starting SSH to {} on channel: {}", remoteAddress, ctx.channel());
+        final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), remoteAddress)
+            // FIXME: this is a blocking call, we should handle this with a concurrently-scheduled timeout. We do not
+            //        have a Timer ready, so perhaps we should be using the event loop?
+            .verify(ctx.channel().config().getConnectTimeoutMillis(), TimeUnit.MILLISECONDS);
+        sshConnectionFuture.addListener(future -> {
+            if (future.isConnected()) {
+                handleSshSessionCreated(future, ctx);
+            } else {
+                handleSshSetupFailure(ctx, future.getException());
+            }
+        });
     }
 
     @Override
     }
 
     @Override