Merge "Resolve Bug:707 - ConfigPusher should wait for netconf-impl to register JMX...
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerDispatcher.java
index 882d368a1af3648b06579903769d48026ecdf38c..ee9009762e8cda9d3f2ac8896f2df8bced568f83 100644 (file)
@@ -8,63 +8,59 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import com.google.common.base.Optional;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
-import org.opendaylight.controller.netconf.api.NetconfSession;
-import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
-import org.opendaylight.controller.netconf.util.AbstractSslChannelInitializer;
-import org.opendaylight.protocol.framework.AbstractDispatcher;
 
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
 import java.net.InetSocketAddress;
 
-public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
+import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
+import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
+import org.opendaylight.protocol.framework.AbstractDispatcher;
+
+public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSession, NetconfServerSessionListener> {
 
-    private final ServerSslChannelInitializer initializer;
+    private final ServerChannelInitializer initializer;
 
-    public NetconfServerDispatcher(ServerSslChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
+    public NetconfServerDispatcher(ServerChannelInitializer serverChannelInitializer, EventLoopGroup bossGroup,
             EventLoopGroup workerGroup) {
         super(bossGroup, workerGroup);
         this.initializer = serverChannelInitializer;
     }
 
-    // TODO test create server with same address twice
     public ChannelFuture createServer(InetSocketAddress address) {
 
-        return super.createServer(address, new PipelineInitializer<NetconfSession>() {
+        return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
             @Override
-            public void initializeChannel(final SocketChannel ch, final Promise<NetconfSession> promise) {
+            public void initializeChannel(final SocketChannel ch, final Promise<NetconfServerSession> promise) {
                 initializer.initialize(ch, promise);
             }
         });
     }
 
-    public static class ServerSslChannelInitializer extends AbstractSslChannelInitializer {
+    public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
+
+        public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
 
         private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
         private final NetconfServerSessionListenerFactory listenerFactory;
 
-        public ServerSslChannelInitializer(Optional<SSLContext> maybeContext,
-                                            NetconfServerSessionNegotiatorFactory negotiatorFactory,
+        public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
                                             NetconfServerSessionListenerFactory listenerFactory) {
-            super(maybeContext);
             this.negotiatorFactory = negotiatorFactory;
             this.listenerFactory = listenerFactory;
         }
 
         @Override
-        protected void initializeAfterDecoder(SocketChannel ch, Promise<? extends NetconfSession> promise) {
-            ch.pipeline().addLast("deserializerExHandler", new DeserializerExceptionHandler());
-            ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
+        protected void initializeMessageDecoder(SocketChannel ch) {
+            super.initializeMessageDecoder(ch);
+            ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
         }
 
         @Override
-        protected void initSslEngine(SSLEngine sslEngine) {
-            sslEngine.setUseClientMode(false);
+        protected void initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
+            ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
         }
     }