From: Robert Varga Date: Sat, 13 Feb 2016 20:48:08 +0000 (+0100) Subject: Document FindLeader message X-Git-Tag: release/boron~383 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=d617f1570fb165d02e18785b8b1704df7f830087 Document FindLeader message Add Javadoc documentation and turn the message into a proper singleton, as it does not currently hold any data. Change-Id: Ib696b32234f048c4a9c7abb7a9972a00118219e5 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FindLeader.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FindLeader.java index eebbde3393..f99dc773c0 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FindLeader.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/client/messages/FindLeader.java @@ -8,9 +8,27 @@ package org.opendaylight.controller.cluster.raft.client.messages; +import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; -public class FindLeader implements Serializable{ +/** + * Request to locate the leader raft actor. Each {@link org.opendaylight.controller.cluster.raft.RaftActor} must + * respond with a {@link FindLeaderReply} containing the address of the leader, as it is known to that particular + * actor. + * + * This message is intended for testing purposes only. + */ +@VisibleForTesting +public final class FindLeader implements Serializable { private static final long serialVersionUID = 1L; + public static final FindLeader INSTANCE = new FindLeader(); + + private FindLeader() { + // Hidden to force reuse + } + @SuppressWarnings({ "static-method", "unused" }) + private FindLeader readResolve() { + return INSTANCE; + } } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java index 8150474234..3d9214151f 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTestKit.java @@ -61,7 +61,7 @@ public class RaftActorTestKit extends JavaTestKit { public static void waitUntilLeader(ActorRef actorRef) { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); for(int i = 0; i < 20 * 5; i++) { - Future future = Patterns.ask(actorRef, new FindLeader(), new Timeout(duration)); + Future future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration)); try { FindLeaderReply resp = (FindLeaderReply) Await.result(future, duration); if(resp.getLeaderActor() != null) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index c31acdad93..d9d0b9bc8c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -230,7 +230,7 @@ public class ShardTest extends AbstractShardTest { assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); // Sanity check - verify the shard is not the leader yet. - shard.tell(new FindLeader(), getRef()); + shard.tell(FindLeader.INSTANCE, getRef()); final FindLeaderReply findLeadeReply = expectMsgClass(duration("5 seconds"), FindLeaderReply.class); assertNull("Expected the shard not to be the leader", findLeadeReply.getLeaderActor()); @@ -329,7 +329,7 @@ public class ShardTest extends AbstractShardTest { RegisterDataTreeChangeListenerReply.class); assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath()); - shard.tell(new FindLeader(), getRef()); + shard.tell(FindLeader.INSTANCE, getRef()); final FindLeaderReply findLeadeReply = expectMsgClass(duration("5 seconds"), FindLeaderReply.class); assertNull("Expected the shard not to be the leader", findLeadeReply.getLeaderActor()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java index 8f3231b417..9df933b5ba 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java @@ -49,7 +49,7 @@ public class ShardTestKit extends JavaTestKit { public static String waitUntilLeader(ActorRef shard) { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); for(int i = 0; i < 20 * 5; i++) { - Future future = Patterns.ask(shard, new FindLeader(), new Timeout(duration)); + Future future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration)); try { FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration); if(resp.getLeaderActor() != null) { @@ -73,7 +73,7 @@ public class ShardTestKit extends JavaTestKit { FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS); Object lastResponse = null; for(int i = 0; i < 20 * 5; i++) { - Future future = Patterns.ask(shard, new FindLeader(), new Timeout(duration)); + Future future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration)); try { FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration); if(resp.getLeaderActor() == null) {