BUG-3888 : refactoring, removed unused session validators
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / TestClientDispatcher.java
index 72b50d30431de7944b503772489977aef17cd218..135bf8a4a00475c4b1d2d3607ca20077eca783d2 100644 (file)
@@ -11,70 +11,45 @@ package org.opendaylight.protocol.bgp.rib.impl;
 import com.google.common.base.Optional;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.EventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.Promise;
 import java.net.InetSocketAddress;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
-import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
-import org.opendaylight.protocol.framework.AbstractDispatcher;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 
-public class TestClientDispatcher extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> {
-
-    private static final String NEGOTIATOR = "negotiator";
+public class TestClientDispatcher {
 
     private final BGPHandlerFactory hf;
-    private InetSocketAddress localAddress;
     private final InetSocketAddress defaulAddress;
+    private InetSocketAddress localAddress;
+    private final BGPDispatcherImpl disp;
 
     protected TestClientDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MessageRegistry messageRegistry,
-            final InetSocketAddress locaAddress) {
-        super(bossGroup, workerGroup);
+                                   final InetSocketAddress locaAddress) {
+        disp = new BGPDispatcherImpl(messageRegistry, bossGroup, workerGroup) {
+            @Override
+            protected void customizeBootstrap(final Bootstrap b) {
+                b.localAddress(locaAddress);
+            }
+        };
         this.hf = new BGPHandlerFactory(messageRegistry);
         this.localAddress = locaAddress;
         this.defaulAddress = locaAddress;
     }
 
     public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress,
-            final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategy strategy, final Optional<InetSocketAddress> localAddress) {
+                                                            final AsNumber remoteAs, final BGPPeerRegistry listener, final ReconnectStrategy strategy, final Optional<InetSocketAddress> localAddress) {
         setLocalAddress(localAddress);
-        final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(remoteAs, listener);
-        return super.createClient(remoteAddress, strategy, new PipelineInitializer<BGPSessionImpl>() {
-
-            @Override
-            public void initializeChannel(SocketChannel ch, Promise<BGPSessionImpl> promise) {
-                ch.pipeline().addLast(TestClientDispatcher.this.hf.getDecoders());
-                ch.pipeline().addLast(NEGOTIATOR, snf.getSessionNegotiator(null, ch, promise));
-                ch.pipeline().addLast(TestClientDispatcher.this.hf.getEncoders());
-            }
-        });
+        return disp.createClient(remoteAddress, remoteAs, listener, strategy);
     }
 
     public synchronized Future<Void> createReconnectingClient(final InetSocketAddress address,
-        final AsNumber remoteAs, final BGPPeerRegistry peerRegistry, final ReconnectStrategyFactory reconnectStrategyFactory,
-        final Optional<InetSocketAddress> localAddress) {
+                                                              final AsNumber remoteAs, final BGPPeerRegistry peerRegistry, final ReconnectStrategyFactory reconnectStrategyFactory,
+                                                              final Optional<InetSocketAddress> localAddress) {
         setLocalAddress(localAddress);
-        final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(remoteAs, peerRegistry);
-        final Future<Void> ret = super.createReconnectingClient(address, reconnectStrategyFactory, new PipelineInitializer<BGPSessionImpl>() {
-            @Override
-            public void initializeChannel(final SocketChannel ch, final Promise<BGPSessionImpl> promise) {
-                ch.pipeline().addLast(TestClientDispatcher.this.hf.getDecoders());
-                ch.pipeline().addLast(NEGOTIATOR, snf.getSessionNegotiator(null, ch, promise));
-                ch.pipeline().addLast(TestClientDispatcher.this.hf.getEncoders());
-            }
-        });
-
-        return ret;
-    }
-
-    @Override
-    protected void customizeBootstrap(Bootstrap b) {
-        b.localAddress(this.localAddress);
-        super.customizeBootstrap(b);
+        return disp.createReconnectingClient(address, remoteAs, peerRegistry, reconnectStrategyFactory, null);
     }
 
     private synchronized void setLocalAddress(final Optional<InetSocketAddress> localAddress) {