Rename AsyncSshHandler.handleSshSetupFailure()
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / AsyncSshHandler.java
index 36cc81d6cf170a8cfe0f706f2de98184f7b99877..c8312e9419af95fe90a91c8130f35c74319a0ff1 100644 (file)
@@ -103,29 +103,6 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
                 negotiationFuture);
     }
 
-    private synchronized void handleSshChanelOpened(final ChannelHandlerContext ctx) {
-        LOG.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel());
-
-        if (negotiationFuture == null) {
-            connectPromise.setSuccess();
-        }
-
-        sshWriteAsyncHandler = new AsyncSshHandlerWriter(channel.getAsyncIn());
-        ctx.fireChannelActive();
-        channel.onClose(() -> disconnect(ctx, ctx.newPromise()));
-    }
-
-    private synchronized void handleSshSetupFailure(final ChannelHandlerContext ctx, final Throwable error) {
-        LOG.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), error);
-
-        // If the promise is not yet done, we have failed with initial connect and set connectPromise to failure
-        if (!connectPromise.isDone()) {
-            connectPromise.setFailure(error);
-        }
-
-        disconnect(ctx, ctx.newPromise());
-    }
-
     @Override
     public synchronized void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
         sshWriteAsyncHandler.write(ctx, msg, promise);
@@ -158,7 +135,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
     private void onConnectComplete(final ConnectFuture future, final ChannelHandlerContext ctx) {
         final var cause = future.getException();
         if (cause != null) {
-            handleSshSetupFailure(ctx, cause);
+            onOpenFailure(ctx, cause);
             return;
         }
 
@@ -176,7 +153,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
         try {
             authFuture = authenticationHandler.authenticate(clientSession);
         } catch (final IOException e) {
-            handleSshSetupFailure(ctx, e);
+            onOpenFailure(ctx, e);
             return;
         }
 
@@ -187,7 +164,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
             final ChannelHandlerContext ctx) {
         final var cause = future.getException();
         if (cause != null) {
-            handleSshSetupFailure(ctx, new AuthenticationFailedException("Authentication failed", cause));
+            onOpenFailure(ctx, new AuthenticationFailedException("Authentication failed", cause));
             return;
         }
 
@@ -205,7 +182,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
             channel.setStreaming(ClientChannel.Streaming.Async);
             openFuture = channel.open();
         } catch (final IOException e) {
-            handleSshSetupFailure(ctx, e);
+            onOpenFailure(ctx, e);
             return;
         }
 
@@ -215,11 +192,34 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
     private void onOpenComplete(final OpenFuture future, final ChannelHandlerContext ctx) {
         final var cause = future.getException();
         if (cause != null) {
-            handleSshSetupFailure(ctx, cause);
+            onOpenFailure(ctx, cause);
             return;
         }
 
-        handleSshChanelOpened(ctx);
+        onOpenComplete(ctx);
+    }
+
+    private synchronized void onOpenComplete(final ChannelHandlerContext ctx) {
+        LOG.trace("SSH subsystem channel opened successfully on channel: {}", ctx.channel());
+
+        if (negotiationFuture == null) {
+            connectPromise.setSuccess();
+        }
+
+        sshWriteAsyncHandler = new AsyncSshHandlerWriter(channel.getAsyncIn());
+        ctx.fireChannelActive();
+        channel.onClose(() -> disconnect(ctx, ctx.newPromise()));
+    }
+
+    private synchronized void onOpenFailure(final ChannelHandlerContext ctx, final Throwable cause) {
+        LOG.warn("Unable to setup SSH connection on channel: {}", ctx.channel(), cause);
+
+        // If the promise is not yet done, we have failed with initial connect and set connectPromise to failure
+        if (!connectPromise.isDone()) {
+            connectPromise.setFailure(cause);
+        }
+
+        disconnect(ctx, ctx.newPromise());
     }
 
     @Override