Add AbstractClientChannelInitializer
[netconf.git] / netconf / netconf-client / src / main / java / org / opendaylight / netconf / client / TlsClientChannelInitializer.java
index 64d567f5aaac8893edee78673a98f5cfa7335180..dc6598dd2a3deb159f963e51b1f26eeaad1bb984 100644 (file)
@@ -11,25 +11,21 @@ import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 import io.netty.util.concurrent.Promise;
-import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
 
-public final class TlsClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
+public final class TlsClientChannelInitializer extends AbstractClientChannelInitializer {
     public static final String CHANNEL_ACTIVE_SENTRY = "channelActiveSentry";
 
     private final SslHandlerFactory sslHandlerFactory;
-    private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
-    private final NetconfClientSessionListener sessionListener;
 
     public TlsClientChannelInitializer(final SslHandlerFactory sslHandlerFactory,
                                        final NetconfClientSessionNegotiatorFactory negotiatorFactory,
                                        final NetconfClientSessionListener sessionListener) {
+        super(negotiatorFactory, sessionListener);
         this.sslHandlerFactory = sslHandlerFactory;
-        this.negotiatorFactory = negotiatorFactory;
-        this.sessionListener = sessionListener;
     }
 
     @Override
-    public void initialize(Channel ch, Promise<NetconfClientSession> promise) {
+    public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
         // When ssl handshake fails due to the certificate mismatch, the connection will try again,
         // then we have a chance to create a new SslHandler using the latest certificates with the
         // help of the sentry. We will replace the sentry with the new SslHandler once the channel
@@ -38,12 +34,6 @@ public final class TlsClientChannelInitializer extends AbstractChannelInitialize
         super.initialize(ch, promise);
     }
 
-    @Override
-    protected void initializeSessionNegotiator(Channel ch, Promise<NetconfClientSession> promise) {
-        ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
-                negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
-    }
-
     private static final class ChannelActiveSentry extends ChannelInboundHandlerAdapter {
         private final SslHandlerFactory sslHandlerFactory;
 
@@ -52,9 +42,9 @@ public final class TlsClientChannelInitializer extends AbstractChannelInitialize
         }
 
         @Override
-        public void channelActive(ChannelHandlerContext ctx) {
-            ctx.pipeline().replace(this, "sslHandler", sslHandlerFactory.createSslHandler())
-                          .fireChannelActive();
+        public void channelActive(final ChannelHandlerContext ctx) {
+            final var sslHandler = sslHandlerFactory.createSslHandler();
+            ctx.pipeline().replace(this, "sslHandler", sslHandler).fireChannelActive();
         }
     }
 }