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;
+ }
}
public static void waitUntilLeader(ActorRef actorRef) {
FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
for(int i = 0; i < 20 * 5; i++) {
- Future<Object> future = Patterns.ask(actorRef, new FindLeader(), new Timeout(duration));
+ Future<Object> future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration));
try {
FindLeaderReply resp = (FindLeaderReply) Await.result(future, duration);
if(resp.getLeaderActor() != null) {
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());
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());
public static String waitUntilLeader(ActorRef shard) {
FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
for(int i = 0; i < 20 * 5; i++) {
- Future<Object> future = Patterns.ask(shard, new FindLeader(), new Timeout(duration));
+ Future<Object> future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration));
try {
FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration);
if(resp.getLeaderActor() != null) {
FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
Object lastResponse = null;
for(int i = 0; i < 20 * 5; i++) {
- Future<Object> future = Patterns.ask(shard, new FindLeader(), new Timeout(duration));
+ Future<Object> future = Patterns.ask(shard, FindLeader.INSTANCE, new Timeout(duration));
try {
FindLeaderReply resp = (FindLeaderReply)Await.result(future, duration);
if(resp.getLeaderActor() == null) {