BUG-58: pass ReconnectStrategy to dispatcher 39/939/1
authorRobert Varga <rovarga@cisco.com>
Wed, 21 Aug 2013 10:18:48 +0000 (12:18 +0200)
committerRobert Varga <rovarga@cisco.com>
Wed, 21 Aug 2013 14:44:27 +0000 (16:44 +0200)
Change-Id: I3491a157c5a8d7754a15f40ef301d810a8eee435
Signed-off-by: Robert Varga <rovarga@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/spi/BGPDispatcher.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPImplTest.java
bgp/testtool/src/main/java/org/opendaylight/protocol/bgp/testtool/Main.java
framework/src/main/java/org/opendaylight/protocol/framework/Dispatcher.java
framework/src/main/java/org/opendaylight/protocol/framework/DispatcherImpl.java
framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java

index 709965bcc4c111f4e10055e1c2f21a2280580f0d..e368b28b9bcd5ef8edcf82fbcd3d891d07c0910d 100644 (file)
@@ -9,13 +9,12 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import io.netty.util.concurrent.Future;
 
-import java.io.IOException;
-
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPConnection;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.framework.Dispatcher;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
 
 /**
  * Implementation of BGPDispatcher.
@@ -24,13 +23,14 @@ public final class BGPDispatcherImpl implements BGPDispatcher {
 
        private final Dispatcher dispatcher;
 
-       public BGPDispatcherImpl(final Dispatcher dispatcher) throws IOException {
+       public BGPDispatcherImpl(final Dispatcher dispatcher) {
                this.dispatcher = dispatcher;
        }
 
        @Override
-       public Future<? extends BGPSession> createClient(final BGPConnection connection, final ProtocolMessageFactory parser) throws IOException {
-               return this.dispatcher.createClient(connection, new BGPSessionFactory(parser));
+       public Future<? extends BGPSession> createClient(final BGPConnection connection, final ProtocolMessageFactory parser,
+                       final ReconnectStrategy strategy) {
+               return this.dispatcher.createClient(connection, new BGPSessionFactory(parser), strategy);
        }
 
        public Dispatcher getDispatcher() {
index b95854bb85fbb80fa280ae7e987f690ab36622a5..c978df27dfae3e5f55c280c3295ee7920f190d20 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposalChecker;
 import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
 
 import com.google.common.base.Preconditions;
 
@@ -75,10 +76,13 @@ public class BGPImpl implements BGP, Closeable {
         */
        @Override
        public BGPListenerRegistration registerUpdateListener(final BGPSessionListener listener) throws IOException {
+               // FIXME: BUG-58: fix this
+               final ReconnectStrategy strategy = null;
+
                final BGPSession session;
                try {
                        session = this.dispatcher.createClient(
-                                       new BGPConnectionImpl(this.address, listener, this.proposal.getProposal(), this.checker), this.parser).get();
+                                       new BGPConnectionImpl(this.address, listener, this.proposal.getProposal(), this.checker), this.parser, strategy).get();
                } catch (InterruptedException | ExecutionException e) {
                        throw new IOException("Failed to connect to peer", e);
                }
index 6755f392db6fe32ede5df9d91ec9431d61c4fa62..e2df70da1b5351b451a6c287d571efed66cbb479 100644 (file)
@@ -13,6 +13,7 @@ import java.io.IOException;
 
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
 
 /**
  * Dispatcher class for creating BGP clients.
@@ -27,5 +28,5 @@ public interface BGPDispatcher {
         * @return client session
         * @throws IOException
         */
-       Future<? extends BGPSession> createClient(BGPConnection connection, ProtocolMessageFactory parser) throws IOException;
+       Future<? extends BGPSession> createClient(BGPConnection connection, ProtocolMessageFactory parser, final ReconnectStrategy strategy);
 }
index 648c7efc7fb17b8b32544028990194e053d55951..b42d2ecb32a5d29a84d056c7370ebce46f02cf2e 100644 (file)
@@ -29,6 +29,7 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
 
 public class BGPImplTest {
 
@@ -52,7 +53,7 @@ public class BGPImplTest {
                doReturn("").when(this.parser).toString();
 
                doReturn(null).when(this.future).get();
-               doReturn(future).when(this.disp).createClient(any(BGPConnection.class), any(ProtocolMessageFactory.class));
+               doReturn(future).when(this.disp).createClient(any(BGPConnection.class), any(ProtocolMessageFactory.class), any(ReconnectStrategy.class));
        }
 
        @Test
index 96135204f54a92a411f6f1b59ca825f56fd9d855..b7e2aa8ecf3276dc0bd8ac3b0feb39d1628ad12a 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.bgp.testtool;
 
+import io.netty.util.concurrent.GlobalEventExecutor;
+
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
@@ -22,6 +24,7 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposalChecker;
 import org.opendaylight.protocol.concepts.ASNumber;
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.framework.DispatcherImpl;
+import org.opendaylight.protocol.framework.NeverReconnectStrategy;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -99,6 +102,7 @@ public class Main {
                logger.debug(address + " " + sessionListener + " " + proposal + " " + checker);
 
                final InetSocketAddress addr = address;
-               m.dispatcher.createClient(new BGPConnectionImpl(addr, sessionListener, proposal, checker), parser);
+               m.dispatcher.createClient(new BGPConnectionImpl(addr, sessionListener, proposal, checker), parser,
+                               new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
        }
 }
index c17ab8854f3a42df5df632a4f7f5fe68b5ce9504..a534072e0ef1d31fa20b4cc263ead91cdb04db38 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.framework;
 
 import io.netty.util.concurrent.Future;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 
 /**
@@ -26,16 +25,17 @@ public interface Dispatcher {
         * @return instance of ProtocolServer
         */
        public Future<ProtocolServer> createServer(final InetSocketAddress address, final ProtocolConnectionFactory connectionFactory,
-                       final ProtocolSessionFactory<?> sfactory) throws IOException;
+                       final ProtocolSessionFactory<?> sfactory);
 
        /**
         * Creates a client.
         * 
         * @param connection connection specific attributes
         * @param sfactory protocol session factory to create a specific session
-        * @param handlerFactory protocol-specific channel handlers factory
+        * @param strategy Reconnection strategy to be used when initial connection fails
         * 
         * @return session associated with this client
         */
-       public <T extends ProtocolSession> Future<T> createClient(final ProtocolConnection connection, final ProtocolSessionFactory<T> sfactory) throws IOException;
+       public <T extends ProtocolSession> Future<T> createClient(final ProtocolConnection connection,
+                       final ProtocolSessionFactory<T> sfactory, final ReconnectStrategy strategy);
 }
index 84f773ef8ad1a2c29e2293092a5b8f3374009738..cd3a6cf8bbc29513321d7dbd945d7034a22fb1fa 100644 (file)
@@ -189,7 +189,7 @@ public final class DispatcherImpl implements Dispatcher, SessionParent {
        }
 
        @Override
-       public <T extends ProtocolSession> Future<T> createClient(final ProtocolConnection connection, final ProtocolSessionFactory<T> sfactory) {
+       public <T extends ProtocolSession> Future<T> createClient(final ProtocolConnection connection, final ProtocolSessionFactory<T> sfactory, final ReconnectStrategy strategy) {
                final Bootstrap b = new Bootstrap();
                b.group(this.workerGroup);
                b.channel(NioSocketChannel.class);
index db11695b6bd841cd3ee6b35a0a166c559812da6d..e8587cfd3d449fd542236b3a6d0270eddfa6ec96 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.protocol.framework;
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import io.netty.util.concurrent.GlobalEventExecutor;
 
 import java.io.IOException;
 import java.net.ConnectException;
@@ -86,7 +87,7 @@ public class ServerTest {
                        public SessionListener getListener() {
                                return ServerTest.this.pce;
                        }
-               }, new SimpleSessionFactory(MAX_MSGSIZE)).get();
+               }, new SimpleSessionFactory(MAX_MSGSIZE), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)).get();
 
                final int maxAttempts = 1000;
                int attempts = 0;
@@ -124,7 +125,7 @@ public class ServerTest {
                                public SessionListener getListener() {
                                        return listener;
                                }
-                       }, new SimpleSessionFactory(MAX_MSGSIZE)).get();
+                       }, new SimpleSessionFactory(MAX_MSGSIZE), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)).get();
 
                        fail("Connection succeeded unexpectedly");
                } catch (ExecutionException e) {
index dab566be4fab74a474c5a17404baedc3ba6258ba..86d0363d0fc04cfa6f16bad63a1b21745d103ae0 100644 (file)
@@ -15,6 +15,7 @@ import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.protocol.framework.Dispatcher;
 import org.opendaylight.protocol.framework.ProtocolServer;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.pcep.PCEPConnection;
 import org.opendaylight.protocol.pcep.PCEPConnectionFactory;
 import org.opendaylight.protocol.pcep.PCEPDispatcher;
@@ -62,7 +63,10 @@ public class PCEPDispatcherImpl implements PCEPDispatcher {
         */
        @Override
        public Future<? extends PCEPSession> createClient(final PCEPConnection connection) throws IOException {
-               return this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages));
+               // FIXME: BUG-58: fix this
+               final ReconnectStrategy strategy = null;
+
+               return this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages), strategy);
        }
 
        @Override