Modernize RPC registration 19/110819/8
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 17 Mar 2024 20:14:39 +0000 (21:14 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 18 Mar 2024 09:32:32 +0000 (09:32 +0000)
Do not use ClassToInstanceMap to register RPCs.

Change-Id: I205bc4b51459b771d61580dde8aac7d5da74c451
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/benchmark-app/src/main/java/org/opendaylight/protocol/bgp/benchmark/app/AppPeerBenchmark.java
bgp/benchmark-app/src/test/java/org/opendaylight/protocol/bgp/benchmark/app/AppPeerBenchmarkTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyProgramming.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/TopologyRPCs.java
pcep/tunnel/tunnel-provider/src/main/java/org/opendaylight/bgpcep/pcep/tunnel/provider/TunnelProgramming.java
programming/impl/src/main/java/org/opendaylight/bgpcep/programming/impl/DefaultInstructionScheduler.java
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/AbstractProgrammingTest.java

index 04cb1bcc94c6ff09b5ce1f61a95ab4267be83899..e4538ed59c728fbce9421b7766cd404181c8b31e 100644 (file)
@@ -12,7 +12,6 @@ import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Stopwatch;
-import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -70,7 +69,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -113,10 +111,8 @@ public final class AppPeerBenchmark implements FutureCallback<Empty>, AutoClosea
             .child(Tables.class, new TablesKey(Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE))
             .child(Ipv4RoutesCase.class, Ipv4Routes.class);
         rpcRegistration = rpcProviderRegistry.registerRpcImplementations(
-            ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-                .put(AddPrefix.class, this::addPrefix)
-                .put(DeletePrefix.class, this::deletePrefix)
-                .build());
+            (AddPrefix) this::addPrefix,
+            (DeletePrefix) this::deletePrefix);
         LOG.info("BGP Application Peer Benchmark Application started.");
     }
 
index 6afb55ff339b311d13e29808d3e44cbc8ee918fb..840eea08b70e8a65515ba8dbac9beaa5a65ffc76 100644 (file)
@@ -16,7 +16,6 @@ import static org.opendaylight.protocol.util.CheckTestUtil.checkEquals;
 import static org.opendaylight.protocol.util.CheckTestUtil.checkNotPresentConfiguration;
 import static org.opendaylight.protocol.util.CheckTestUtil.readDataConfiguration;
 
-import com.google.common.collect.ClassToInstanceMap;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev200120.output.Result;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.Uint32;
 
@@ -54,7 +54,7 @@ public class AppPeerBenchmarkTest extends AbstractConcurrentDataBrokerTest {
 
     @Before
     public void setUp() {
-        doReturn(registration).when(rpcRegistry).registerRpcImplementations(any(ClassToInstanceMap.class));
+        doReturn(registration).when(rpcRegistry).registerRpcImplementations(any(Rpc[].class));
         doNothing().when(registration).close();
     }
 
index cf98d83220be5d687f26249eefda50ac819feb29..0a8aeca1c7ac21914d33613e843aa199353bec67 100644 (file)
@@ -16,7 +16,6 @@ import com.google.common.base.Stopwatch;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
@@ -97,7 +96,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.Notification;
-import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@@ -420,15 +418,13 @@ public class BGPPeer extends AbstractPeer implements BGPSessionListener {
 
             if (rpcRegistry != null) {
                 final var bgpPeerHandler = new BgpPeerRpc(this, session, tables);
-                rpcRegistration = rpcRegistry.registerRpcImplementations(
-                    ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-                        .put(ResetSession.class, bgpPeerHandler::resetSession)
-                        .put(RestartGracefully.class, bgpPeerHandler::restartGracefully)
-                        .put(RouteRefreshRequest.class, bgpPeerHandler::routeRefreshRequest)
-                        .build(),
-                    ImmutableSet.of(rib.getInstanceIdentifier().child(
-                        org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib
-                        .Peer.class, new PeerKey(peerId))));
+                rpcRegistration = rpcRegistry.registerRpcImplementations(List.of(
+                    (ResetSession) bgpPeerHandler::resetSession,
+                    (RestartGracefully) bgpPeerHandler::restartGracefully,
+                    (RouteRefreshRequest) bgpPeerHandler::routeRefreshRequest), ImmutableSet.of(
+                        rib.getInstanceIdentifier().child(
+                            org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib
+                            .rib.Peer.class, new PeerKey(peerId))));
             }
         } else {
             final Set<TablesKey> forwardingTables;
index 24dc727664e891908403fe764f463e7aa78e3e95..f9efcc44eb932b8364e68e776a2f3f86231629b5 100644 (file)
@@ -11,9 +11,9 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
 import java.util.Set;
 import org.opendaylight.bgpcep.pcep.topology.spi.AbstractInstructionExecutor;
 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
@@ -45,7 +45,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 final class TopologyProgramming {
@@ -59,13 +58,12 @@ final class TopologyProgramming {
 
     Registration register(final RpcProviderService rpcProviderService,
             final KeyedInstanceIdentifier<Topology, TopologyKey> path) {
-        return rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-            .put(SubmitAddLsp.class, this::submitAddLsp)
-            .put(SubmitRemoveLsp.class, this::submitRemoveLsp)
-            .put(SubmitUpdateLsp.class, this::submitUpdateLsp)
-            .put(SubmitEnsureLspOperational.class, this::submitEnsureLspOperational)
-            .put(SubmitTriggerSync.class, this::submitTriggerSync)
-            .build(), Set.of(path));
+        return rpcProviderService.registerRpcImplementations(List.of(
+            (SubmitAddLsp) this::submitAddLsp,
+            (SubmitRemoveLsp) this::submitRemoveLsp,
+            (SubmitUpdateLsp) this::submitUpdateLsp,
+            (SubmitEnsureLspOperational) this::submitEnsureLspOperational,
+            (SubmitTriggerSync) this::submitTriggerSync), Set.of(path));
     }
 
     @VisibleForTesting
index 84f8024f25050570db6aa741e9e484b85a7ba6aa..8f872107070297866a51c93429259e659768bd22 100644 (file)
@@ -10,10 +10,10 @@ package org.opendaylight.bgpcep.pcep.topology.provider;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
+import java.util.List;
 import java.util.Set;
 import org.opendaylight.bgpcep.programming.spi.SuccessfulRpcResult;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
@@ -45,7 +45,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 final class TopologyRPCs {
@@ -57,14 +56,13 @@ final class TopologyRPCs {
 
     Registration register(final RpcProviderService rpcProviderService,
             final KeyedInstanceIdentifier<Topology, TopologyKey> path) {
-        return rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-            .put(AddLsp.class, this::addLsp)
-            .put(RemoveLsp.class, this::removeLsp)
-            .put(TriggerSync.class, this::triggerSync)
-            .put(UpdateLsp.class, this::updateLsp)
-            .put(EnsureLspOperational.class, this::ensureLspOperational)
-            .put(TearDownSession.class, this::tearDownSession)
-            .build(), Set.of(path));
+        return rpcProviderService.registerRpcImplementations(List.of(
+            (AddLsp) this::addLsp,
+            (RemoveLsp) this::removeLsp,
+            (TriggerSync) this::triggerSync,
+            (UpdateLsp) this::updateLsp,
+            (EnsureLspOperational) this::ensureLspOperational,
+            (TearDownSession) this::tearDownSession), Set.of(path));
     }
 
     @VisibleForTesting
index 7fa3e63c1060e10c9d4de096678126e07ea8cff1..60ec8f88c7426415641dfeacaba855a0d8eab700 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.bgpcep.pcep.tunnel.provider;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.List;
 import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.bgpcep.pcep.topology.spi.AbstractInstructionExecutor;
@@ -34,7 +34,6 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,12 +51,10 @@ public final class TunnelProgramming implements AutoCloseable {
     }
 
     Registration register(final KeyedInstanceIdentifier<Topology, TopologyKey> topologyPath) {
-        return dependencies.getRpcProviderRegistry().registerRpcImplementations(
-            ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-                .put(PcepCreateP2pTunnel.class, this::pcepCreateP2pTunnel)
-                .put(PcepDestroyTunnel.class, this::pcepDestroyTunnel)
-                .put(PcepUpdateTunnel.class, this::pcepUpdateTunnel)
-                .build(), Set.of(topologyPath));
+        return dependencies.getRpcProviderRegistry().registerRpcImplementations(List.of(
+            (PcepCreateP2pTunnel) this::pcepCreateP2pTunnel,
+            (PcepDestroyTunnel) this::pcepDestroyTunnel,
+            (PcepUpdateTunnel) this::pcepUpdateTunnel), Set.of(topologyPath));
     }
 
     @VisibleForTesting
index e328cc188a448e93c04764b040a47659aaf4edd8..064b32ff1ae8adb87801d2659792436718de7aba 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.bgpcep.programming.impl;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.FluentFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
@@ -72,7 +71,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programm
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Rpc;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -175,10 +173,9 @@ final class DefaultInstructionScheduler implements ClusterSingletonService, Inst
     @Override
     public synchronized void instantiateServiceInstance() {
         LOG.info("Instruction Queue service {} instantiated", sgi.value());
-        reg = rpcProviderRegistry.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-            .put(CancelInstruction.class, this::cancelInstruction)
-            .put(CleanInstructions.class, this::cleanInstructions)
-            .build());
+        reg = rpcProviderRegistry.registerRpcImplementations(
+            (CancelInstruction) this::cancelInstruction,
+            (CleanInstructions) this::cleanInstructions);
 
         final WriteTransaction wt = dataProvider.newWriteOnlyTransaction();
         wt.put(LogicalDatastoreType.OPERATIONAL, qid, new InstructionsQueueBuilder()
index d4f4a475877e54b3541f25b1adb4ade114a7c7bc..8d76a44dae5c606c5c8d14eb442944f5325faf9c 100644 (file)
@@ -12,7 +12,6 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 
-import com.google.common.collect.ClassToInstanceMap;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.opendaylight.mdsal.binding.api.RpcProviderService;
@@ -20,6 +19,7 @@ import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBro
 import org.opendaylight.mdsal.singleton.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.Rpc;
 
 abstract class AbstractProgrammingTest extends AbstractConcurrentDataBrokerTest {
     @Mock
@@ -47,7 +47,7 @@ abstract class AbstractProgrammingTest extends AbstractConcurrentDataBrokerTest
             return null;
         }).when(singletonServiceRegistration).close();
 
-        doReturn(registration).when(rpcRegistry).registerRpcImplementations(any(ClassToInstanceMap.class));
+        doReturn(registration).when(rpcRegistry).registerRpcImplementations(any(Rpc[].class));
 
         doNothing().when(registration).close();
     }