Modernize sal-remoterpc-connector 81/103581/4
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 4 Dec 2022 20:55:04 +0000 (21:55 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 18 Dec 2022 11:07:55 +0000 (12:07 +0100)
Use instanceof patterns to reduce casts.

Change-Id: Iafcb05461e2c241310857ee2bf93591bed66a7d4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/OpsInvoker.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/OpsRegistrar.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteDOMActionFuture.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteDOMRpcFuture.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/TerminationMonitor.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/messages/ExecuteAction.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/ActionRegistry.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/ActionRoutingTable.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/RpcRegistry.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/BucketStoreActor.java
opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/gossip/Gossiper.java

index 9c47e68faa6a95bf5ba9a2861ad4295bedd219f8..dcb930e8ca3482c12d471625e7e62e4eb379591c 100644 (file)
@@ -68,11 +68,11 @@ final class OpsInvoker extends AbstractUntypedActor {
 
     @Override
     protected void handleReceive(final Object message) {
-        if (message instanceof ExecuteRpc) {
+        if (message instanceof ExecuteRpc executeRpc) {
             LOG.debug("Handling ExecuteOps Message");
-            execute((ExecuteRpc) message);
-        } else if (message instanceof ExecuteAction) {
-            execute((ExecuteAction) message);
+            execute(executeRpc);
+        } else if (message instanceof ExecuteAction executeAction) {
+            execute(executeAction);
         } else {
             unknownMessage(message);
         }
index a16bbd4eb5236413d036bccc3a6cbf6c922dfb34..cfd5b2dadc9c072222faca8d8933c73f834c3fa3 100644 (file)
@@ -65,12 +65,12 @@ final class OpsRegistrar extends AbstractUntypedActor {
 
     @Override
     protected void handleReceive(final Object message) {
-        if (message instanceof UpdateRemoteEndpoints) {
+        if (message instanceof UpdateRemoteEndpoints updateEndpoints) {
             LOG.debug("Handling updateRemoteEndpoints message");
-            updateRemoteRpcEndpoints(((UpdateRemoteEndpoints) message).getRpcEndpoints());
-        } else if (message instanceof UpdateRemoteActionEndpoints) {
+            updateRemoteRpcEndpoints(updateEndpoints.getRpcEndpoints());
+        } else if (message instanceof UpdateRemoteActionEndpoints updateEndpoints) {
             LOG.debug("Handling updateRemoteActionEndpoints message");
-            updateRemoteActionEndpoints(((UpdateRemoteActionEndpoints) message).getActionEndpoints());
+            updateRemoteActionEndpoints(updateEndpoints.getActionEndpoints());
         } else {
             unknownMessage(message);
         }
index 6b4ab55de4e52c91f3b252cabe7be20943bcb5c7..9d9e29ad36befc04617a39f804fdc003b27fa3eb 100644 (file)
@@ -23,8 +23,7 @@ final class RemoteDOMActionFuture extends AbstractRemoteFuture<Absolute, DOMActi
 
     @Override
     DOMActionResult processReply(final Object reply) {
-        if (reply instanceof ActionResponse) {
-            final ActionResponse actionReply = (ActionResponse) reply;
+        if (reply instanceof ActionResponse actionReply) {
             final ContainerNode output = actionReply.getOutput();
             return output == null ? new SimpleDOMActionResult(actionReply.getErrors())
                     : new SimpleDOMActionResult(output, actionReply.getErrors());
index ef1e635bcbb2ba05864ab4fa3a1b492dc97e9e30..e112d1f9818411067b072516a034b993f04bc237 100644 (file)
@@ -22,7 +22,7 @@ final class RemoteDOMRpcFuture extends AbstractRemoteFuture<QName, DOMRpcResult,
 
     @Override
     DOMRpcResult processReply(final Object reply) {
-        return reply instanceof RpcResponse ? new DefaultDOMRpcResult(((RpcResponse) reply).getOutput()) : null;
+        return reply instanceof RpcResponse response ? new DefaultDOMRpcResult(response.getOutput()) : null;
     }
 
     @Override
index fb034300f9964442e3481d727943430a8a3fbe80..a79a4e45d421f2aad2f008e6a41d92ff115c1592 100644 (file)
@@ -22,11 +22,9 @@ public class TerminationMonitor extends UntypedAbstractActor {
 
     @Override
     public void onReceive(final Object message) {
-        if (message instanceof Terminated) {
-            Terminated terminated = (Terminated) message;
+        if (message instanceof Terminated terminated) {
             LOG.debug("Actor terminated : {}", terminated.actor());
-        } else if (message instanceof Monitor) {
-            Monitor monitor = (Monitor) message;
+        } else if (message instanceof Monitor monitor) {
             getContext().watch(monitor.getActorRef());
         }
     }
index cb03c220beeb95410ec66817b922907679e47a64..a97613542b2bd32e9bd61b8612f8d81d3aa1d1fe 100644 (file)
@@ -87,7 +87,7 @@ public final class ExecuteAction extends AbstractExecute<Absolute, @NonNull Cont
         public void readExternal(final ObjectInput in) throws IOException {
             final NormalizedNodeDataInput stream = NormalizedNodeDataInput.newDataInput(in);
             final SchemaNodeIdentifier sni = stream.readSchemaNodeIdentifier();
-            if (!(sni instanceof Absolute)) {
+            if (!(sni instanceof Absolute absolute)) {
                 throw new InvalidObjectException("Non-absolute type " + sni);
             }
 
@@ -95,7 +95,7 @@ public final class ExecuteAction extends AbstractExecute<Absolute, @NonNull Cont
             final YangInstanceIdentifier path = stream.readYangInstanceIdentifier();
             final ContainerNode input = (ContainerNode) stream.readOptionalNormalizedNode().orElse(null);
 
-            executeAction = new ExecuteAction((Absolute) sni, new DOMDataTreeIdentifier(type, path), input);
+            executeAction = new ExecuteAction(absolute, new DOMDataTreeIdentifier(type, path), input);
         }
 
         private Object readResolve() {
index 96697391485b79f75ccadaa5e148e7d533c5552d..2a91b5ab614c84fb8c1c8c37771513fa82b8af51 100644 (file)
@@ -77,9 +77,9 @@ public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
 
     @Override
     protected void handleCommand(final Object message) throws Exception {
-        if (message instanceof ActionRegistry.Messages.UpdateActions) {
+        if (message instanceof ActionRegistry.Messages.UpdateActions updateActions) {
             LOG.debug("handling updatesActionRoutes message");
-            updatesActionRoutes((Messages.UpdateActions) message);
+            updatesActionRoutes(updateActions);
         } else {
             super.handleCommand(message);
         }
@@ -149,11 +149,11 @@ public class ActionRegistry extends BucketStoreActor<ActionRoutingTable> {
             }
 
             Collection<DOMActionInstance> getAddedActions() {
-                return this.addedActions;
+                return addedActions;
             }
 
             Collection<DOMActionInstance> getRemovedActions() {
-                return this.removedActions;
+                return removedActions;
             }
 
 
index dfb05c67f1d6e15a96e23a19375c62085cec3f8d..3cdfeaf889db725d155e1db4a8b185e4e847e228 100644 (file)
@@ -78,11 +78,11 @@ public final class ActionRoutingTable extends AbstractRoutingTable<ActionRouting
             actions = new ArrayList<>(size);
             for (int i = 0; i < size; ++i) {
                 final SchemaNodeIdentifier sni = nnin.readSchemaNodeIdentifier();
-                if (!(sni instanceof Absolute)) {
+                if (!(sni instanceof Absolute absolute)) {
                     throw new InvalidObjectException("Non-absolute type " + sni);
                 }
 
-                actions.add(DOMActionInstance.of((Absolute) sni, LogicalDatastoreType.OPERATIONAL,
+                actions.add(DOMActionInstance.of(absolute, LogicalDatastoreType.OPERATIONAL,
                         nnin.readYangInstanceIdentifier()));
             }
         }
index 2c89f1426072a6e945de5ed107fd3b07a53ef7df..8d66ed8ccb163abc56891009bfe09cfdae29add6 100644 (file)
@@ -81,10 +81,10 @@ public class RpcRegistry extends BucketStoreActor<RoutingTable> {
 
     @Override
     protected void handleCommand(final Object message) throws Exception {
-        if (message instanceof AddOrUpdateRoutes) {
-            receiveAddRoutes((AddOrUpdateRoutes) message);
-        } else if (message instanceof RemoveRoutes) {
-            receiveRemoveRoutes((RemoveRoutes) message);
+        if (message instanceof AddOrUpdateRoutes addRoutes) {
+            receiveAddRoutes(addRoutes);
+        } else if (message instanceof RemoveRoutes removeRoutes) {
+            receiveRemoveRoutes(removeRoutes);
         } else {
             super.handleCommand(message);
         }
@@ -161,7 +161,7 @@ public class RpcRegistry extends BucketStoreActor<RoutingTable> {
             }
 
             List<DOMRpcIdentifier> getRouteIdentifiers() {
-                return this.rpcRouteIdentifiers;
+                return rpcRouteIdentifiers;
             }
 
             @Override
index b494256d500f2fe53f2660c3216ce503a4b09d91..f155880c0185677e20e4187df79684858f8be934 100644 (file)
@@ -154,18 +154,17 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
             return;
         }
 
-        if (message instanceof ExecuteInActor) {
-            ((ExecuteInActor) message).accept(this);
+        if (message instanceof ExecuteInActor execute) {
+            execute.accept(this);
         } else if (GET_BUCKET_VERSIONS == message) {
             // FIXME: do we need to send ourselves?
             getSender().tell(ImmutableMap.copyOf(versions), getSelf());
-        } else if (message instanceof Terminated) {
-            actorTerminated((Terminated) message);
-        } else if (message instanceof DeleteSnapshotsSuccess) {
-            LOG.debug("{}: got command: {}", persistenceId(), message);
-        } else if (message instanceof DeleteSnapshotsFailure) {
-            LOG.warn("{}: failed to delete prior snapshots", persistenceId(),
-                ((DeleteSnapshotsFailure) message).cause());
+        } else if (message instanceof Terminated terminated) {
+            actorTerminated(terminated);
+        } else if (message instanceof DeleteSnapshotsSuccess deleteSuccess) {
+            LOG.debug("{}: got command: {}", persistenceId(), deleteSuccess);
+        } else if (message instanceof DeleteSnapshotsFailure deleteFailure) {
+            LOG.warn("{}: failed to delete prior snapshots", persistenceId(), deleteFailure.cause());
         } else {
             LOG.debug("Unhandled message [{}]", message);
             unhandled(message);
@@ -173,15 +172,14 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
     }
 
     private void handleSnapshotMessage(final Object message) {
-        if (message instanceof SaveSnapshotFailure) {
-            LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) message).cause());
+        if (message instanceof SaveSnapshotFailure saveFailure) {
+            LOG.error("{}: failed to persist state", persistenceId(), saveFailure.cause());
             persisting = false;
             self().tell(PoisonPill.getInstance(), ActorRef.noSender());
-        } else if (message instanceof SaveSnapshotSuccess) {
-            LOG.debug("{}: got command: {}", persistenceId(), message);
-            SaveSnapshotSuccess saved = (SaveSnapshotSuccess)message;
-            deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(),
-                    saved.metadata().timestamp() - 1, 0L, 0L));
+        } else if (message instanceof SaveSnapshotSuccess saveSuccess) {
+            LOG.debug("{}: got command: {}", persistenceId(), saveSuccess);
+            deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(), saveSuccess.metadata().timestamp() - 1,
+                0L, 0L));
             persisting = false;
             unstash();
         } else {
@@ -199,13 +197,13 @@ public abstract class BucketStoreActor<T extends BucketData<T>> extends
                 incarnation = 0;
             }
 
-            this.localBucket = new LocalBucket<>(incarnation.intValue(), initialData);
+            this.localBucket = new LocalBucket<>(incarnation, initialData);
             initialData = null;
             LOG.debug("{}: persisting new incarnation {}", persistenceId(), incarnation);
             persisting = true;
             saveSnapshot(incarnation);
-        } else if (message instanceof SnapshotOffer) {
-            incarnation = (Integer) ((SnapshotOffer)message).snapshot();
+        } else if (message instanceof SnapshotOffer snapshotOffer) {
+            incarnation = (Integer) snapshotOffer.snapshot();
             LOG.debug("{}: recovered incarnation {}", persistenceId(), incarnation);
         } else {
             LOG.warn("{}: ignoring recovery message {}", persistenceId(), message);
index f43a1d9f9613e3871c6190948c12fb7f7172e1e0..bfd06f2b73675a23e010f3d4ead4c53cc505ac25 100644 (file)
@@ -87,7 +87,7 @@ public class Gossiper extends AbstractUntypedActorWithMetering {
 
     Gossiper(final RemoteOpsProviderConfig config, final Boolean autoStartGossipTicks) {
         this.config = requireNonNull(config);
-        this.autoStartGossipTicks = autoStartGossipTicks.booleanValue();
+        this.autoStartGossipTicks = autoStartGossipTicks;
     }
 
     Gossiper(final RemoteOpsProviderConfig config) {
@@ -146,25 +146,25 @@ public class Gossiper extends AbstractUntypedActorWithMetering {
         //These ticks can be sent by another actor as well which is esp. useful while testing
         if (GOSSIP_TICK.equals(message)) {
             receiveGossipTick();
-        } else if (message instanceof GossipStatus) {
+        } else if (message instanceof GossipStatus status) {
             // Message from remote gossiper with its bucket versions
-            receiveGossipStatus((GossipStatus) message);
-        } else if (message instanceof GossipEnvelope) {
+            receiveGossipStatus(status);
+        } else if (message instanceof GossipEnvelope envelope) {
             // Message from remote gossiper with buckets. This is usually in response to GossipStatus
             // message. The contained buckets are newer as determined by the remote gossiper by
             // comparing the GossipStatus message with its local versions.
-            receiveGossip((GossipEnvelope) message);
-        } else if (message instanceof ClusterEvent.MemberUp) {
-            receiveMemberUpOrReachable(((ClusterEvent.MemberUp) message).member());
+            receiveGossip(envelope);
+        } else if (message instanceof ClusterEvent.MemberUp memberUp) {
+            receiveMemberUpOrReachable(memberUp.member());
 
-        } else if (message instanceof ClusterEvent.ReachableMember) {
-            receiveMemberUpOrReachable(((ClusterEvent.ReachableMember) message).member());
+        } else if (message instanceof ClusterEvent.ReachableMember reachableMember) {
+            receiveMemberUpOrReachable(reachableMember.member());
 
-        } else if (message instanceof ClusterEvent.MemberRemoved) {
-            receiveMemberRemoveOrUnreachable(((ClusterEvent.MemberRemoved) message).member());
+        } else if (message instanceof ClusterEvent.MemberRemoved memberRemoved) {
+            receiveMemberRemoveOrUnreachable(memberRemoved.member());
 
-        } else if (message instanceof ClusterEvent.UnreachableMember) {
-            receiveMemberRemoveOrUnreachable(((ClusterEvent.UnreachableMember) message).member());
+        } else if (message instanceof ClusterEvent.UnreachableMember unreachableMember) {
+            receiveMemberRemoveOrUnreachable(unreachableMember.member());
 
         } else {
             unhandled(message);