From 6dba41de29d71c0ce5b7220056bec56ee9d3d30e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 28 Oct 2024 21:24:53 +0100 Subject: [PATCH] Use a switch expression to dispatch server configuration RaftActorServerConfigurationSupport uses an if/else cascade, which we can easily replace with switch expression. Change-Id: Ib570d8a3dd2ddac1d8dbe7ba3907b19875fb99c1 Signed-off-by: Robert Varga --- .../RaftActorServerConfigurationSupport.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java index 23ce97e8f5..6c5645b236 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupport.java @@ -67,29 +67,34 @@ class RaftActorServerConfigurationSupport { } boolean handleMessage(final Object message, final ActorRef sender) { - if (message instanceof AddServer addServer) { - onAddServer(addServer, sender); - return true; - } else if (message instanceof RemoveServer removeServer) { - onRemoveServer(removeServer, sender); - return true; - } else if (message instanceof ChangeServersVotingStatus changeServersVotingStatus) { - onChangeServersVotingStatus(changeServersVotingStatus, sender); - return true; - } else if (message instanceof ServerOperationTimeout serverOperationTimeout) { - currentOperationState.onServerOperationTimeout(serverOperationTimeout); - return true; - } else if (message instanceof UnInitializedFollowerSnapshotReply uninitFollowerSnapshotReply) { - currentOperationState.onUnInitializedFollowerSnapshotReply(uninitFollowerSnapshotReply); - return true; - } else if (message instanceof ApplyState applyState) { - return onApplyState(applyState); - } else if (message instanceof SnapshotComplete) { - currentOperationState.onSnapshotComplete(); - return false; - } else { - return false; - } + return switch (message) { + case ApplyState msg -> onApplyState(msg); + case AddServer msg -> { + onAddServer(msg, sender); + yield true; + } + case RemoveServer msg -> { + onRemoveServer(msg, sender); + yield true; + } + case ChangeServersVotingStatus msg -> { + onChangeServersVotingStatus(msg, sender); + yield true; + } + case ServerOperationTimeout msg -> { + currentOperationState.onServerOperationTimeout(msg); + yield true; + } + case UnInitializedFollowerSnapshotReply msg -> { + currentOperationState.onUnInitializedFollowerSnapshotReply(msg); + yield true; + } + case SnapshotComplete msg -> { + currentOperationState.onSnapshotComplete(); + yield false; + } + default -> false; + }; } void onNewLeader(final String leaderId) { -- 2.36.6