*/
package org.opendaylight.protocol.pcep.impl;
+import com.google.common.base.Preconditions;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Promise;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.framework.AbstractDispatcher;
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.PCEPSessionListener;
+import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
-import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.net.InetSocketAddress;
/**
* Implementation of PCEPDispatcher.
*/
-public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
-
- private final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf;
+public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher, AutoCloseable {
- private final PCEPHandlerFactory hf = new PCEPHandlerFactory();
+ private final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf;
+ private final PCEPHandlerFactory hf;
/**
* 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> negotiatorFactory) {
- super();
+ public PCEPDispatcherImpl(final MessageHandlerRegistry registry,
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
+ EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
+ super(bossGroup, workerGroup);
this.snf = Preconditions.checkNotNull(negotiatorFactory);
+ this.hf = new PCEPHandlerFactory(registry);
}
@Override
public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
- return super.createServer(address, listenerFactory);
+ return super.createServer(address, new PipelineInitializer<PCEPSessionImpl>() {
+ @Override
+ public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise) {
+ ch.pipeline().addLast(PCEPDispatcherImpl.this.hf.getDecoders());
+ ch.pipeline().addLast("negotiator", PCEPDispatcherImpl.this.snf.getSessionNegotiator(listenerFactory, ch, promise));
+ ch.pipeline().addLast(PCEPDispatcherImpl.this.hf.getEncoders());
+ }
+ });
}
- @Override
- 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());
- }
+ @Override
+ public void close() {
+ }
}