Bump upstreams
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / SshClientChannelInitializer.java
index 9adf79cef1d404860ce8bc5cbfd2f5c00b67f3aa..81f2d00b9724222973af2bea2ce6f39f788cdcc5 100644 (file)
@@ -9,40 +9,33 @@ package org.opendaylight.netconf.client;
 
 import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
-import java.io.IOException;
-import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler;
+import org.opendaylight.netconf.nettyutil.handler.ssh.client.NetconfSshClient;
 
-final class SshClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
-
+final class SshClientChannelInitializer extends AbstractClientChannelInitializer {
     private final AuthenticationHandler authenticationHandler;
-    private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
-    private final NetconfClientSessionListener sessionListener;
+    private final NetconfSshClient sshClient;
 
     SshClientChannelInitializer(final AuthenticationHandler authHandler,
-                                final NetconfClientSessionNegotiatorFactory negotiatorFactory,
-                                final NetconfClientSessionListener sessionListener) {
-        this.authenticationHandler = authHandler;
-        this.negotiatorFactory = negotiatorFactory;
-        this.sessionListener = sessionListener;
+            final NetconfClientSessionNegotiatorFactory negotiatorFactory,
+            final NetconfClientSessionListener sessionListener, @Nullable final NetconfSshClient sshClient) {
+        super(negotiatorFactory, sessionListener);
+        authenticationHandler = authHandler;
+        this.sshClient = sshClient;
     }
 
-    @Override
-    public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
-        try {
-            // ssh handler has to be the first handler in pipeline
-            ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise));
-            super.initialize(ch, promise);
-        } catch (final IOException e) {
-            throw new RuntimeException(e);
-        }
+    SshClientChannelInitializer(final AuthenticationHandler authHandler,
+            final NetconfClientSessionNegotiatorFactory negotiatorFactory,
+            final NetconfClientSessionListener sessionListener) {
+        this(authHandler, negotiatorFactory, sessionListener, null);
     }
 
     @Override
-    protected void initializeSessionNegotiator(final Channel ch,
-                                               final Promise<NetconfClientSession> promise) {
-        ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
-                negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
+    public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
+        // ssh handler has to be the first handler in pipeline
+        ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(authenticationHandler, promise, sshClient));
+        super.initialize(ch, promise);
     }
 }