*/
package org.opendaylight.protocol.bgp.rib.impl;
+import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
-import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
import org.opendaylight.protocol.framework.SessionListenerFactory;
/**
* Implementation of BGPDispatcher.
*/
-public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher {
+public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher, AutoCloseable {
private final Timer timer = new HashedWheelTimer();
- private BGPSessionNegotiatorFactory snf;
-
private final BGPHandlerFactory hf;
- public BGPDispatcherImpl(final BGPMessageFactory parser) {
- super();
+ public BGPDispatcherImpl(final BGPMessageFactory parser, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
+ super(bossGroup, workerGroup);
this.hf = new BGPHandlerFactory(parser);
}
@Override
- public Future<? extends BGPSession> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
+ public Future<BGPSessionImpl> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
final BGPSessionListener listener, final ReconnectStrategy strategy) {
- this.snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
+ final BGPSessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
+ @Override
+ public BGPSessionListener getSessionListener() {
+ return listener;
+ }
+ };
+ return super.createClient(address, strategy, new PipelineInitializer<BGPSessionImpl>() {
+ @Override
+ public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
+ ch.pipeline().addLast(hf.getDecoders());
+ ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
+ ch.pipeline().addLast(hf.getEncoders());
+ }
+ });
+ }
+ @Override
+ public Future<Void> createReconnectingClient(final InetSocketAddress address,
+ final BGPSessionPreferences preferences, final BGPSessionListener listener,
+ final ReconnectStrategyFactory connectStrategyFactory,
+ final ReconnectStrategy reestablishStrategy) {
+ final BGPSessionNegotiatorFactory snf = new BGPSessionNegotiatorFactory(this.timer, preferences);
+ final SessionListenerFactory<BGPSessionListener> slf = new SessionListenerFactory<BGPSessionListener>() {
@Override
public BGPSessionListener getSessionListener() {
return listener;
}
};
- return super.createClient(address, strategy, slf);
+
+ return super.createReconnectingClient(address, connectStrategyFactory, reestablishStrategy, new PipelineInitializer<BGPSessionImpl>() {
+ @Override
+ public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
+ ch.pipeline().addLast(hf.getDecoders());
+ ch.pipeline().addLast("negotiator", snf.getSessionNegotiator(slf, ch, promise));
+ ch.pipeline().addLast(hf.getEncoders());
+ }
+ });
}
@Override
- public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise,
- final SessionListenerFactory<BGPSessionListener> slf) {
- ch.pipeline().addLast(this.hf.getDecoders());
- ch.pipeline().addLast("negotiator", this.snf.getSessionNegotiator(slf, ch, promise));
- ch.pipeline().addLast(this.hf.getEncoders());
+ public void close() {
}
}