BUG-54 : switched channel pipeline to be protocol specific.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPDispatcherImpl.java
index 2feaed9b83085335f5c2d34f126de180eeef9365..52cc2df3c642eb88725037036d4bc23ee14d988b 100644 (file)
@@ -8,51 +8,50 @@
 package org.opendaylight.protocol.pcep.impl;
 
 import io.netty.channel.ChannelFuture;
-import io.netty.util.concurrent.Future;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.util.concurrent.Promise;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.protocol.framework.AbstractDispatcher;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
 import org.opendaylight.protocol.pcep.PCEPDispatcher;
 import org.opendaylight.protocol.pcep.PCEPMessage;
-import org.opendaylight.protocol.pcep.PCEPSession;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Implementation of PCEPDispatcher.
  */
-public class PCEPDispatcherImpl extends AbstractDispatcher implements PCEPDispatcher {
-       private static final PCEPMessageFactory msgFactory = new PCEPMessageFactory();
+public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
+
        private final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf;
 
+       private final PCEPHandlerFactory hf = new PCEPHandlerFactory();
+
        /**
         * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
         * 
         * @throws IOException if some error occurred during opening the selector
         */
-       public PCEPDispatcherImpl(final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf) {
+       public PCEPDispatcherImpl(final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
                super();
-               this.snf = snf;
+               this.snf = Preconditions.checkNotNull(negotiatorFactory);
        }
 
        @Override
        public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
-               return this.createServer(address, listenerFactory, snf, msgFactory);
+               return super.createServer(address, listenerFactory);
        }
 
-       /**
-        * Create client is used for mock purposes only.
-        * 
-        * @throws ExecutionException
-        * @throws InterruptedException
-        */
        @Override
-       public Future<? extends PCEPSession> createClient(final InetSocketAddress address, final PCEPSessionListener listener, final ReconnectStrategy strategy) {
-               return this.createClient(address, listener, snf, msgFactory, strategy);
+       public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise,
+                       final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
+               ch.pipeline().addLast(this.hf.getDecoders());
+               ch.pipeline().addLast("negotiator", this.snf.getSessionNegotiator(listenerFactory, ch, promise));
+               ch.pipeline().addLast(this.hf.getEncoders());
        }
 }