Merge "Resolve Bug:445 Remove freemarker from config code generator."
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / NetconfServerDispatcher.java
index 7c5bd0cb21dcc25988c3e66c17f7821b3a780d11..130818b12a7d6e040ff863b1026e9e9101d81385 100644 (file)
@@ -12,14 +12,13 @@ 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.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 
 import java.net.InetSocketAddress;
 
-public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession, NetconfServerSessionListener> {
+public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSession, NetconfServerSessionListener> {
 
     private final ServerChannelInitializer initializer;
 
@@ -31,31 +30,37 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfSession,
 
     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 ServerChannelInitializer extends AbstractChannelInitializer {
+    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 ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
-                                            NetconfServerSessionListenerFactory listenerFactory) {
+
+        public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
             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 initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
+            ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
+                    negotiatorFactory.getSessionNegotiator(null, ch, promise));
+        }
     }
 
 }