Refactor SwitchConnectionProvider a bit 52/111852/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 23 May 2024 16:02:32 +0000 (18:02 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 26 May 2024 20:51:47 +0000 (22:51 +0200)
This interface specifies AutoCloseable, which is an implementation leak
from the days of Config Subsystem. Eliminate this specification and make
sure the close() method performs deactivation.

This is the step in the direction of having well-defined lifecycle,
where the users cannot interfere with what the provider is doing.

Change-Id: I1ccbb6987f21b3871d80a9da694211e3c3d19204
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit b753a6614a2036e78f76d7c17fde521a58f887da)

openflowjava/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/SwitchConnectionProviderImpl.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java
openflowjava/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/it/integration/IntegrationTest.java
openflowjava/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java

index 6c12edf9922aa48b4316550a3abc51f097d92431..a55a638a45354de3b9fb9fde6183e20448aec150 100755 (executable)
@@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory;
  * @author michal.polkorab
  */
 @Component(service = SwitchConnectionProvider.class, factory = SwitchConnectionProviderImpl.FACTORY_NAME)
-public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, ConnectionInitializer {
+public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, ConnectionInitializer, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(SwitchConnectionProviderImpl.class);
 
     private static final String THREAD_NAME_PREFIX = "OFP-SwitchConnectionProvider-Udp/TcpHandler";
@@ -82,8 +82,6 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
         "org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl";
     public static final String PROP_CONFIG = ".config";
 
-    private SwitchConnectionHandler switchConnectionHandler;
-    private ServerFacade serverFacade;
     private final ConnectionConfiguration connConfig;
     private final SerializationFactory serializationFactory;
     private final SerializerRegistry serializerRegistry;
@@ -94,6 +92,7 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
     private final String threadName;
 
     private TcpConnectionInitializer connectionInitializer;
+    private ServerFacade serverFacade;
     // FIXME: clean this up when no longer needed
     private final ServiceRegistration diagReg;
 
@@ -123,8 +122,10 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
         this(diagStatus, new ConnectionConfigurationImpl((SwitchConnectionConfig) props.get(PROP_CONFIG)));
     }
 
+    @Override
     @Deactivate
-    void deactivate() {
+    public void close() {
+        shutdown();
         diagReg.close();
     }
 
@@ -133,12 +134,6 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
         return config == null ? "-null-config" : "_" + config.getPort();
     }
 
-    @Override
-    public void setSwitchConnectionHandler(final SwitchConnectionHandler switchConnectionHandler) {
-        LOG.debug("setSwitchConnectionHandler");
-        this.switchConnectionHandler = switchConnectionHandler;
-    }
-
     @Override
     public ListenableFuture<Boolean> shutdown() {
         LOG.debug("Shutdown summoned");
@@ -153,13 +148,17 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
 
     @Override
     @SuppressWarnings("checkstyle:IllegalCatch")
-    public ListenableFuture<Void> startup() {
+    public ListenableFuture<Void> startup(final SwitchConnectionHandler connectionHandler) {
         LOG.debug("Startup summoned");
+        if (connConfig == null) {
+            return Futures.immediateFailedFuture(new IllegalStateException("Connection not configured"));
+        }
+        if (connectionHandler == null) {
+            return Futures.immediateFailedFuture(new IllegalStateException("SwitchConnectionHandler is not set"));
+        }
+
         try {
-            serverFacade = createAndConfigureServer();
-            if (switchConnectionHandler == null) {
-                throw new IllegalStateException("SwitchConnectionHandler is not set");
-            }
+            serverFacade = createAndConfigureServer(connectionHandler);
             Futures.addCallback(listeningExecutorService.submit(serverFacade), new FutureCallback<Object>() {
                 @Override
                 public void onFailure(final Throwable throwable) {
@@ -178,19 +177,16 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
         }
     }
 
-    private ServerFacade createAndConfigureServer() {
+    private ServerFacade createAndConfigureServer(final SwitchConnectionHandler connectionHandler) {
         LOG.debug("Configuring ..");
 
-        if (connConfig == null) {
-            throw new IllegalStateException("Connection not configured");
-        }
         final var transportProtocol = (TransportProtocol) connConfig.getTransferProtocol();
         if (transportProtocol == null) {
             throw new IllegalStateException("No transport protocol received in " + connConfig);
         }
 
         final var factory = new ChannelInitializerFactory();
-        factory.setSwitchConnectionHandler(switchConnectionHandler);
+        factory.setSwitchConnectionHandler(connectionHandler);
         factory.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
         factory.setTlsConfig(connConfig.getTlsConfiguration());
         factory.setSerializationFactory(serializationFactory);
@@ -227,11 +223,6 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider, C
         return serverFacade;
     }
 
-    @Override
-    public void close() {
-        shutdown();
-    }
-
     @Override
     public boolean unregisterSerializer(final ExperimenterSerializerKey key) {
         return serializerRegistry.unregisterSerializer((MessageTypeKey<?>) key);
index a2b0daa16620fb6f7ccf8aff4fc98e66d8628d93..7c5328812262e8327a1b791e65c6f7dd28532f07 100755 (executable)
@@ -9,11 +9,10 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.List;
-import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
@@ -86,7 +85,7 @@ public class SwitchConnectionProviderImpl02Test {
      *
      * @param protocol communication protocol
      */
-    public void startUp(final TransportProtocol protocol) throws UnknownHostException {
+    public void startUp(final TransportProtocol protocol) throws Exception {
         config = null;
         if (protocol != null) {
             createConfig(protocol);
@@ -94,7 +93,7 @@ public class SwitchConnectionProviderImpl02Test {
         provider = new SwitchConnectionProviderImpl(diagStatusService, config);
     }
 
-    private void createConfig(final TransportProtocol protocol) throws UnknownHostException {
+    private void createConfig(final TransportProtocol protocol) throws Exception {
         InetAddress startupAddress = InetAddress.getLocalHost();
 
         tlsConfiguration = null;
@@ -114,9 +113,9 @@ public class SwitchConnectionProviderImpl02Test {
      * Test getServerFacade.
      */
     @Test
-    public void testServerFacade() throws UnknownHostException {
+    public void testServerFacade() throws Exception {
         startUp(TransportProtocol.TCP);
-        final var future = provider.startup();
+        final var future = provider.startup(handler);
         final var serverFacade = provider.getServerFacade();
         assertNotNull("Wrong -- getServerFacade return null", serverFacade);
     }
@@ -125,7 +124,7 @@ public class SwitchConnectionProviderImpl02Test {
      * Test shutdown on unconfigured provider.
      */
     @Test(expected = IllegalStateException.class)
-    public void testShutdownUnconfigured() throws UnknownHostException {
+    public void testShutdownUnconfigured() throws Exception {
         startUp(TransportProtocol.TCP);
         provider.shutdown();
     }
@@ -134,7 +133,7 @@ public class SwitchConnectionProviderImpl02Test {
      * Test unregister by wrong key.
      */
     @Test
-    public void testUnregisterWrongKeys() throws UnknownHostException {
+    public void testUnregisterWrongKeys() throws Exception {
         startUp(TransportProtocol.TCP);
         final var testSerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
         assertFalse("Wrong -- unregisterSerializer",provider.unregisterSerializer(testSerKey));
@@ -146,124 +145,124 @@ public class SwitchConnectionProviderImpl02Test {
      * Test register and unregister method.
      */
     @Test
-    public void testUnregisterExistingKeys() throws UnknownHostException {
+    public void testUnregisterExistingKeys() throws Exception {
         startUp(TransportProtocol.TCP);
         // -- registerActionSerializer
         final ExperimenterActionSerializerKey key1 =
             new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42), TestSubType.VALUE);
         provider.registerActionSerializer(key1, serializer);
-        Assert.assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
-        Assert.assertFalse("Wrong -- unregister ActionSerializer by not existing key",
+        assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
+        assertFalse("Wrong -- unregister ActionSerializer by not existing key",
                 provider.unregisterSerializer(key1));
         // -- registerActionDeserializer
         final ExperimenterActionDeserializerKey key2
             = new ExperimenterActionDeserializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
         provider.registerActionDeserializer(key2, deserializer);
-        Assert.assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
-        Assert.assertFalse("Wrong -- unregister ActionDeserializer by not existing key",
+        assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
+        assertFalse("Wrong -- unregister ActionDeserializer by not existing key",
                 provider.unregisterDeserializer(key2));
         // -- registerInstructionSerializer
         final ExperimenterInstructionSerializerKey key3 =
             new ExperimenterInstructionSerializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
         provider.registerInstructionSerializer(key3, serializer);
-        Assert.assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
-        Assert.assertFalse("Wrong -- unregister InstructionSerializer by not existing key",
+        assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
+        assertFalse("Wrong -- unregister InstructionSerializer by not existing key",
                 provider.unregisterSerializer(key3));
         // -- registerInstructionDeserializer
         final ExperimenterInstructionDeserializerKey key4 =
             new ExperimenterInstructionDeserializerKey(EncodeConstants.OF_VERSION_1_0, 42L);
         provider.registerInstructionDeserializer(key4, deserializer);
-        Assert.assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
-        Assert.assertFalse("Wrong -- unregister InstructionDeserializer by not existing key",
+        assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
+        assertFalse("Wrong -- unregister InstructionDeserializer by not existing key",
                 provider.unregisterDeserializer(key4));
         // -- registerMatchEntryDeserializer
         final MatchEntryDeserializerKey key5 =
             new MatchEntryDeserializerKey(EncodeConstants.OF_VERSION_1_0, 0x8000, 42);
         provider.registerMatchEntryDeserializer(key5, deserializer);
-        Assert.assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
-        Assert.assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key",
+        assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
+        assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key",
                 provider.unregisterDeserializer(key5));
         // -- registerErrorDeserializer
         final ExperimenterIdDeserializerKey key6 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
                 Uint32.valueOf(42), ErrorMessage.class);
         provider.registerErrorDeserializer(key6, deserializerError);
-        Assert.assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
-        Assert.assertFalse("Wrong -- unregister ErrorDeserializer by not existing key",
+        assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
+        assertFalse("Wrong -- unregister ErrorDeserializer by not existing key",
                 provider.unregisterDeserializer(key6));
         // -- registerExperimenterMessageDeserializer
         final ExperimenterIdDeserializerKey key7 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
                 Uint32.valueOf(42), ExperimenterMessage.class);
         provider.registerExperimenterMessageDeserializer(key7, deserializerExpMsg);
-        Assert.assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
-        Assert.assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key",
+        assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
+        assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key",
                 provider.unregisterDeserializer(key7));
         // -- registerMultipartReplyMessageDeserializer
         final ExperimenterIdDeserializerKey key8 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
                 Uint32.valueOf(42), MultipartReplyMessage.class);
         provider.registerMultipartReplyMessageDeserializer(key8, deserializerMultipartRplMsg);
-        Assert.assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer",
+        assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer",
                 provider.unregisterDeserializer(key8));
-        Assert.assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key",
+        assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key",
                 provider.unregisterDeserializer(key8));
         // -- registerMultipartReplyTFDeserializer
         final ExperimenterIdDeserializerKey key9 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
                 Uint32.valueOf(42), MultipartReplyMessage.class);
         provider.registerMultipartReplyTFDeserializer(key9, deserializer);
-        Assert.assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
-        Assert.assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key",
+        assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
+        assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key",
                 provider.unregisterDeserializer(key9));
         // -- registerQueuePropertyDeserializer
         final ExperimenterIdDeserializerKey key10 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
                 Uint32.valueOf(42), QueueProperty.class);
         provider.registerQueuePropertyDeserializer(key10, deserializerQueueProperty);
-        Assert.assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
-        Assert.assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key",
+        assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
+        assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key",
                 provider.unregisterDeserializer(key10));
         // -- registerMeterBandDeserializer
         final ExperimenterIdDeserializerKey key11 = new ExperimenterIdDeserializerKey(EncodeConstants.OF_VERSION_1_0,
                 Uint32.valueOf(42), MeterBandExperimenterCase.class);
         provider.registerMeterBandDeserializer(key11, deserializerMeterBandExpCase);
-        Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
-        Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key",
+        assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
+        assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key",
                 provider.unregisterDeserializer(key11));
         // -- registerExperimenterMessageSerializer
         ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key12 =
             new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
                 ExperimenterDataOfChoice.class);
         provider.registerExperimenterMessageSerializer(key12, serializerExperimenterInput);
-        Assert.assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12));
-        Assert.assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key",
+        assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12));
+        assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key",
                 provider.unregisterSerializer(key12));
         //registerMultipartRequestSerializer
         ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key13 =
             new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
                 ExperimenterDataOfChoice.class);
         provider.registerMultipartRequestSerializer(key13, serializerMultipartRequestExpCase);
-        Assert.assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
-        Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key",
+        assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
+        assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key",
                 provider.unregisterSerializer(key13));
         // -- registerMultipartRequestTFSerializer
         final ExperimenterIdSerializerKey<TableFeatureProperties> key14 =
             new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
                 TableFeatureProperties.class);
         provider.registerMultipartRequestTFSerializer(key14, serializer);
-        Assert.assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
-        Assert.assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key",
+        assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
+        assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key",
                 provider.unregisterSerializer(key14));
         // -- registerMeterBandSerializer
         final ExperimenterIdMeterSubTypeSerializerKey<MeterBandExperimenterCase> key15 =
             new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42),
                 MeterBandExperimenterCase.class,null);
         provider.registerMeterBandSerializer(key15, serializerMeterBandExpCase);
-        Assert.assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
-        Assert.assertFalse("Wrong -- unregister MeterBandSerializer by not existing key",
+        assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
+        assertFalse("Wrong -- unregister MeterBandSerializer by not existing key",
                 provider.unregisterSerializer(key15));
         // -- registerMatchEntrySerializer
         final MatchEntrySerializerKey<OpenflowBasicClass, InPort> key16 =
             new MatchEntrySerializerKey<>(EncodeConstants.OF_VERSION_1_3, OpenflowBasicClass.VALUE, InPort.VALUE);
         provider.registerMatchEntrySerializer(key16, serializer);
-        Assert.assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
-        Assert.assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key",
+        assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
+        assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key",
                 provider.unregisterSerializer(key15));
         // -- registerSerializer
         final MessageTypeKey key17 = new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, TestSubType.class);
index f5fbe8bf36b15c1c2339a81e9cc3fe101ba3825e..5987de64d5f20ed09802d3807d77820aabbca7ca 100644 (file)
@@ -91,9 +91,9 @@ public class SwitchConnectionProviderImplTest {
      * Tests provider startup - without configuration and {@link SwitchConnectionHandler}.
      */
     @Test
-    public void testStartup1() throws UnknownHostException {
+    public void testStartup1() throws Exception {
         startUp(null);
-        final var future = provider.startup();
+        final var future = provider.startup(null);
 
         final var cause = assertThrows(ExecutionException.class, () -> future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS))
             .getCause();
@@ -105,10 +105,9 @@ public class SwitchConnectionProviderImplTest {
      * Tests provider startup - without configuration.
      */
     @Test
-    public void testStartup2() throws UnknownHostException {
+    public void testStartup2() throws Exception {
         startUp(null);
-        provider.setSwitchConnectionHandler(handler);
-        final var future = provider.startup();
+        final var future = provider.startup(handler);
 
         final var cause = assertThrows(ExecutionException.class, () -> future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS))
             .getCause();
@@ -120,9 +119,9 @@ public class SwitchConnectionProviderImplTest {
      * Tests provider startup - without {@link SwitchConnectionHandler}.
      */
     @Test
-    public void testStartup3() throws UnknownHostException {
+    public void testStartup3() throws Exception {
         startUp(TransportProtocol.TCP);
-        final var future = provider.startup();
+        final var future = provider.startup(null);
 
         final var cause = assertThrows(ExecutionException.class, () -> future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS))
             .getCause();
@@ -136,9 +135,7 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup4() throws Exception {
         startUp(TransportProtocol.TCP);
-        provider.setSwitchConnectionHandler(handler);
-
-        provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+        provider.startup(handler).get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
     }
 
     /**
@@ -147,9 +144,7 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup5() throws Exception {
         startUp(TransportProtocol.TLS);
-        provider.setSwitchConnectionHandler(handler);
-
-        provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+        provider.startup(handler).get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
     }
 
     /**
@@ -158,9 +153,7 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testStartup6() throws Exception {
         startUp(TransportProtocol.UDP);
-        provider.setSwitchConnectionHandler(handler);
-
-        provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+        provider.startup(handler).get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
     }
 
     /**
@@ -169,9 +162,7 @@ public class SwitchConnectionProviderImplTest {
     @Test
     public void testShutdown() throws Exception {
         startUp(TransportProtocol.TCP);
-        provider.setSwitchConnectionHandler(handler);
-
-        provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+        provider.startup(handler).get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
         assertTrue("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
     }
 }
index fc78e954dbdd38e9d97b7686a1955a9a14e6bb1d..a5dea958837059ff0e2987ff4f9ddf46424d0e93 100644 (file)
@@ -108,8 +108,7 @@ public class IntegrationTest {
         doReturn(mock(ServiceRegistration.class)).when(diagStatusService).register(any());
 
         switchConnectionProvider = new SwitchConnectionProviderImpl(diagStatusService, connConfig);
-        switchConnectionProvider.setSwitchConnectionHandler(mockPlugin);
-        switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+        switchConnectionProvider.startup(mockPlugin).get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
         if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) {
             final TcpHandler tcpHandler = (TcpHandler) switchConnectionProvider.getServerFacade();
             port = tcpHandler.getPort();
index cab8051c16d2994a73173be58bc830cee9b9e3d2..481fc56dd10128e2a248a6259e6af2973c0e9160 100644 (file)
@@ -19,9 +19,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtens
  * @author mirehak
  * @author michal.polkorab
  */
-public interface SwitchConnectionProvider extends AutoCloseable,
-        SerializerExtensionProvider, DeserializerExtensionProvider {
-
+public interface SwitchConnectionProvider extends SerializerExtensionProvider, DeserializerExtensionProvider {
     /**
      * Returns the connection configuration.
      *
@@ -30,12 +28,12 @@ public interface SwitchConnectionProvider extends AutoCloseable,
     ConnectionConfiguration getConfiguration();
 
     /**
-     * Start listening to switches, but please don't forget to do
-     * {@link #setSwitchConnectionHandler(SwitchConnectionHandler)} first.
+     * Start listening to switches using specified {@link SwitchConnectionHandler}.
      *
+     * @param connectionHandler instance being informed when new switch connects
      * @return future completing when the channel has been resolved
      */
-    ListenableFuture<Void> startup();
+    ListenableFuture<Void> startup(SwitchConnectionHandler connectionHandler);
 
     /**
      * Stop listening to switches.
@@ -43,11 +41,4 @@ public interface SwitchConnectionProvider extends AutoCloseable,
      * @return future, triggered to true, when all listening channels are down
      */
     ListenableFuture<Boolean> shutdown();
-
-    /**
-     * Sets the SwitchConnectionHandler.
-     *
-     * @param switchConHandler instance being informed when new switch connects
-     */
-    void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler);
 }
index b841e72c8229b7c34619cec8182bf0566f48622a..708a5bb203fd040c79605bb41497600fc52da636 100644 (file)
@@ -213,8 +213,7 @@ public final class OpenFlowPluginProviderImpl
             }
 
             // Set handler of incoming connections and start switch connection provider
-            switchConnectionProvider.setSwitchConnectionHandler(connectionManager);
-            return switchConnectionProvider.startup();
+            return switchConnectionProvider.startup(connectionManager);
         }).collect(Collectors.toSet())), new FutureCallback<List<Void>>() {
             @Override
             public void onSuccess(final List<Void> result) {
index 9480822833d06a9d39026b669edf9eab528a39db..6c7bae1855ab93f7765bf1d69ab549af60d0e2b7 100644 (file)
@@ -77,7 +77,7 @@ public class OpenFlowPluginProviderImplTest {
         when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
         doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
         when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
-        when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(null));
+        when(switchConnectionProvider.startup(any())).thenReturn(Futures.immediateFuture(null));
         when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
         when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
                 any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
@@ -102,7 +102,7 @@ public class OpenFlowPluginProviderImplTest {
                 ofPluginDiagstatusProvider, systemReadyMonitor)) {
             // Calling the onSystemBootReady() callback
             provider.onSystemBootReady();
-            verify(switchConnectionProvider).startup();
+            verify(switchConnectionProvider).startup(any());
         }
         verify(switchConnectionProvider).shutdown();
     }