Turn LeaderTransitioning into a singleton 15/34615/4
authorRobert Varga <rovarga@cisco.com>
Sat, 13 Feb 2016 23:49:14 +0000 (00:49 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 15 Feb 2016 14:08:10 +0000 (14:08 +0000)
The message does not carry any state and can be made a singleton.

Change-Id: Iadcbe0cb8de949dbc57240772bcfd9ddf23d42ad
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActorLeadershipTransferCohort.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/base/messages/LeaderTransitioning.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java

index b83bfd3..d5dfcf3 100644 (file)
@@ -76,11 +76,10 @@ public class RaftActorLeadershipTransferCohort {
                     currentBehavior.getLeaderPayloadVersion()), raftActor.self());
         }
 
-        LeaderTransitioning leaderTransitioning = new LeaderTransitioning();
         for(String peerId: context.getPeerIds()) {
             ActorSelection followerActor = context.getPeerActorSelection(peerId);
             if(followerActor != null) {
-                followerActor.tell(leaderTransitioning, context.getActor());
+                followerActor.tell(LeaderTransitioning.INSTANCE, context.getActor());
             }
         }
 
index 4974f8f..cfa9166 100644 (file)
@@ -14,6 +14,16 @@ import java.io.Serializable;
  *
  * @author Thomas Pantelis
  */
-public class LeaderTransitioning implements Serializable {
+public final class LeaderTransitioning implements Serializable {
     private static final long serialVersionUID = 1L;
+    public static final LeaderTransitioning INSTANCE = new LeaderTransitioning();
+
+    private LeaderTransitioning() {
+        // Hidden on purpose
+    }
+
+    @SuppressWarnings({ "static-method", "unused" })
+    private LeaderTransitioning readResolve() {
+        return INSTANCE;
+    }
 }
index f4846d2..35cbc0d 100644 (file)
@@ -1360,7 +1360,7 @@ public class RaftActorTest extends AbstractActorTest {
 
         MessageCollectorActor.clearMessages(notifierActor);
 
-        raftActorRef.tell(new LeaderTransitioning(), ActorRef.noSender());
+        raftActorRef.tell(LeaderTransitioning.INSTANCE, ActorRef.noSender());
 
         leaderStateChange = MessageCollectorActor.expectFirstMatching(notifierActor, LeaderStateChanged.class);
         assertEquals("getMemberId", persistenceId, leaderStateChange.getMemberId());