Reduce number of parameters for RIBImpl 85/68785/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 17 Jan 2018 08:05:51 +0000 (09:05 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Tue, 27 Feb 2018 09:24:45 +0000 (10:24 +0100)
Change-Id: Ib9a9fff4e1d21673fec9251b32663106614fb8c1
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/CodecsRegistryImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/config/RibImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java

index 57ed866ec7887cf295fb43f69c19791e4a3ad533..e2a3b91767e8ea33c04c0874728f9e18ab977064 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class CodecsRegistryImpl implements CodecsRegistry {
+public final class CodecsRegistryImpl implements CodecsRegistry {
 
     private static final Logger LOG = LoggerFactory.getLogger(CodecsRegistryImpl.class);
 
@@ -44,7 +44,7 @@ final class CodecsRegistryImpl implements CodecsRegistry {
         this.classContext = requireNonNull(strategy);
     }
 
-    static CodecsRegistryImpl create(final BindingCodecTreeFactory codecFactory, final GeneratedClassLoadingStrategy classStrategy) {
+    public static CodecsRegistryImpl create(final BindingCodecTreeFactory codecFactory, final GeneratedClassLoadingStrategy classStrategy) {
         return new CodecsRegistryImpl(codecFactory, classStrategy);
     }
 
index bd3ca3b2d53f667bee6d4e6b63f291b2f587f32a..cd12e279f1ed2f9b6ee5bf636643726c193225c0 100755 (executable)
@@ -13,7 +13,6 @@ import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.HashMap;
@@ -22,7 +21,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.concurrent.Future;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
 import javax.annotation.concurrent.ThreadSafe;
@@ -36,10 +34,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
-import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
@@ -53,7 +47,6 @@ import org.opendaylight.protocol.bgp.rib.impl.state.BGPRIBStateImpl;
 import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
 import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
-import org.opendaylight.protocol.bgp.rib.spi.util.ClusterSingletonServiceRegistrationHelper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRib;
@@ -115,8 +108,8 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
 
     public RIBImpl(final RibId ribId, final AsNumber localAs, final BgpId localBgpId,
             final ClusterIdentifier clusterId, final RIBExtensionConsumerContext extensions, final BGPDispatcher dispatcher,
-            final BindingCodecTreeFactory codecFactory, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables,
-            @Nonnull final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies, final GeneratedClassLoadingStrategy classStrategy) {
+            final CodecsRegistryImpl codecsRegistry, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables,
+            @Nonnull final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies) {
         super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(requireNonNull(ribId))),
                 localBgpId, localAs);
         this.localAs = requireNonNull(localAs);
@@ -127,7 +120,7 @@ public final class RIBImpl extends BGPRIBStateImpl implements RIB, TransactionCh
         this.domDataBroker = requireNonNull(domDataBroker);
         this.service = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
         this.extensions = requireNonNull(extensions);
-        this.codecsRegistry = CodecsRegistryImpl.create(codecFactory, classStrategy);
+        this.codecsRegistry = codecsRegistry;
         this.ribContextRegistry = RIBSupportContextRegistryImpl.create(extensions, this.codecsRegistry);
         final InstanceIdentifierBuilder yangRibIdBuilder = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Rib.QNAME);
         this.yangRibId = yangRibIdBuilder.nodeWithKey(Rib.QNAME, RIB_ID_QNAME, ribId.getValue()).build();
index c9c18398112a3b0ed2d2a6a6c96fa69a92428569..633251926ee8a0d36972340237045512c2c41da9 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
+import org.opendaylight.protocol.bgp.rib.impl.CodecsRegistryImpl;
 import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
@@ -228,6 +229,10 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
                 .stream()
                 .collect(Collectors.toMap(entry ->
                         new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
+
+        final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(codecTreeFactory,
+                this.extensions.getClassLoadingStrategy());
+
         return new RIBImpl(
                 new RibId(bgpInstanceName),
                 this.asNumber,
@@ -235,11 +240,10 @@ public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
                 this.clusterId,
                 this.extensions,
                 this.dispatcher,
-                this.codecTreeFactory,
+                codecsRegistry,
                 this.domBroker,
                 toTableTypes(this.afiSafi, tableTypeRegistry),
-                pathSelectionModes,
-                this.extensions.getClassLoadingStrategy());
+                pathSelectionModes);
     }
 
     @Override
index 1eda3a5f84cc77a327704c2d92a1b17b3090fa91..402c04ee5c8e5fb2521b8c42f520ce5dbcb7daed 100644 (file)
@@ -152,6 +152,7 @@ public abstract class AbstractAddPathTest extends AbstractConcurrentDataBrokerTe
     private NioEventLoopGroup boss;
     private org.opendaylight.protocol.bgp.inet.BGPActivator inetActivator;
     protected StrictBGPPeerRegistry serverRegistry;
+    protected CodecsRegistryImpl codecsRegistry;
 
     @Before
     public void setUp() throws Exception {
@@ -190,6 +191,9 @@ public abstract class AbstractAddPathTest extends AbstractConcurrentDataBrokerTe
             this.serverRegistry);
         doReturn(Mockito.mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
             .registerClusterSingletonService(any(ClusterSingletonService.class));
+
+        this.codecsRegistry = CodecsRegistryImpl.create(this.mappingService.getCodecFactory(),
+                this.ribExtension.getClassLoadingStrategy());
     }
 
     @After
index d063372dc2dd8fdc6c27d249e934101e06a16104..c13e77eed4456ee0bbfc98e8fc8e71972f505ef9 100644 (file)
@@ -173,14 +173,18 @@ public class AbstractRIBTestSetup {
 
         this.a1 = new RIBActivator();
         this.a1.startRIBExtensionProvider(context);
+
+        final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(this.codecFactory,
+                GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
+
         mockedMethods();
         doReturn(mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider)
                 .registerClusterSingletonService(any(ClusterSingletonService.class));
         this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), RIB_ID, CLUSTER_ID, context,
-                this.dispatcher, this.codecFactory, this.dom, localTables,
+                this.dispatcher, codecsRegistry, this.dom, localTables,
                 Collections.singletonMap(new TablesKey(AFI, SAFI),
-                        BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
-                GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
+                        BasePathSelectionModeFactory.createBestPathSelectionStrategy())
+        );
         this.rib.onGlobalContextUpdated(schemaContext);
         this.ribSupport = getRib().getRibSupportContext().getRIBSupportContext(KEY).getRibSupport();
     }
index 7ab75c5d9311ac047774ef99b231e3cff7c0e094..906fdad4ff2d6da5f4d14bf61e1e01dba1a7fb42 100644 (file)
@@ -55,8 +55,8 @@ public class AddPathAllPathsTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"), AS_NUMBER, BGP_ID, null,
-                this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
-            getDomBroker(), TABLES_TYPE, pathTables, this.ribExtension.getClassLoadingStrategy());
+                this.ribExtension, this.serverDispatcher, this.codecsRegistry,
+            getDomBroker(), TABLES_TYPE, pathTables);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
index 85d7a753812baac3e73cdab77e63138671d81294..92636e4436f4d3a5ef28c8b12ef813f16bf20ec2 100644 (file)
@@ -44,8 +44,8 @@ public class AddPathBasePathsTest extends AbstractAddPathTest {
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"),
             AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
-            this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
-            this.ribExtension.getClassLoadingStrategy());
+            this.codecsRegistry, getDomBroker(), TABLES_TYPE, pathTables
+        );
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
         final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT));
index f31379178ad8f52794b64b3ddb7b630f18698b22..33cd17c01633bc47821c8e6ca20009d35b462784 100644 (file)
@@ -44,8 +44,7 @@ public class AddPathNPathsTest extends AbstractAddPathTest {
 
         this.ribImpl = new RIBImpl(new RibId("test-rib"),
             AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher,
-            this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
-            this.ribExtension.getClassLoadingStrategy());
+            this.codecsRegistry, getDomBroker(), TABLES_TYPE, pathTables);
 
         this.ribImpl.instantiateServiceInstance();
         this.ribImpl.onGlobalContextUpdated(this.schemaContext);
index 42da7a773042f10aa40b870406e26e265f67e591..180173004a3cd6cac8eb6eae464bd6fe29b5659b 100755 (executable)
@@ -82,6 +82,7 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
     private BindingCodecTreeFactory codecFactory;
 
     private DOMSchemaService schemaService;
+    private CodecsRegistryImpl codecsRegistry;
 
     @Before
     public void setUp() throws Exception {
@@ -103,6 +104,8 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
 
         this.baseact.startRIBExtensionProvider(this.ext1);
         this.lsact.startRIBExtensionProvider(this.ext2);
+        this.codecsRegistry = CodecsRegistryImpl.create(this.codecFactory,
+                GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
     }
 
     @Override
@@ -133,9 +136,9 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
                 LinkstateSubsequentAddressFamily.class));
         final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID),
                 AS_NUMBER, new BgpId("127.0.0.1"), null, this.ext2, this.dispatcher,
-                this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
-                BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
-                GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
+                this.codecsRegistry, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
+                BasePathSelectionModeFactory.createBestPathSelectionStrategy())
+        );
         rib.instantiateServiceInstance();
         assertTablesExists(tables);
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
@@ -151,9 +154,9 @@ public class ParserToSalTest extends AbstractConcurrentDataBrokerTest {
         final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class,
                 UnicastSubsequentAddressFamily.class));
         final RIBImpl rib = new RIBImpl(new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID,
-                null, this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables,
-                Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
-                GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
+                null, this.ext1, this.dispatcher, this.codecsRegistry, getDomBroker(), tables,
+                Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy())
+        );
         rib.instantiateServiceInstance();
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
         assertTablesExists(tables);
index c8be49fe8bac4357e7555f021e9a7c901712f9a5..42aa27966cf6b27082a5726ca82ceaabdee99e6f 100644 (file)
@@ -208,8 +208,8 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy());
         final RIBImpl ribImpl = new RIBImpl( new RibId(RIB_ID), AS_NUMBER,
-            new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
-            this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy());
+            new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.codecsRegistry,
+            this.domBroker, ImmutableList.of(this.ipv4tt), pathTables);
         ribImpl.instantiateServiceInstance();
         ribImpl.onGlobalContextUpdated(this.schemaContext);
 
@@ -256,8 +256,8 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest {
         final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
             BasePathSelectionModeFactory.createBestPathSelectionStrategy());
         final RIBImpl ribImpl = new RIBImpl( new RibId(RIB_ID), AS_NUMBER,
-            new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.mappingService.getCodecFactory(),
-            this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy());
+            new BgpId(RIB_ID), null, this.ribExtension, this.serverDispatcher, this.codecsRegistry,
+            this.domBroker, ImmutableList.of(this.ipv4tt), pathTables);
         ribImpl.instantiateServiceInstance();
         ribImpl.onGlobalContextUpdated(this.schemaContext);