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());
}
}