2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.raft.behaviors;
11 import akka.actor.ActorRef;
12 import javax.annotation.Nullable;
13 import org.opendaylight.controller.cluster.raft.RaftState;
16 * A RaftActorBehavior represents the specific behavior of a RaftActor
18 * A RaftActor can behave as one of the following,
21 * <li> Candidate </li>
25 * In each of these behaviors the Raft Actor handles the same Raft messages
28 public interface RaftActorBehavior extends AutoCloseable{
31 * Handle a message. If the processing of the message warrants a state
32 * change then a new behavior should be returned otherwise this method should
33 * return the current behavior.
35 * @param sender The sender of the message
36 * @param message A message that needs to be processed
38 * @return The new behavior or current behavior, or null if the message was not handled.
40 @Nullable RaftActorBehavior handleMessage(ActorRef sender, Object message);
44 * @return The state associated with a given behavior
50 * @return The Id of the Leader if known else null
55 * setting the index of the log entry which is replicated to all nodes
56 * @param replicatedToAllIndex
58 void setReplicatedToAllIndex(long replicatedToAllIndex);
61 * @return the index of the log entry which is replicated to all nodes
63 long getReplicatedToAllIndex();
66 * @return the leader's payload data version.
68 short getLeaderPayloadVersion();
71 * switchBehavior makes sure that the current behavior is shutdown before it switches to the new
74 * @param behavior The new behavior to switch to
75 * @return The new behavior
77 RaftActorBehavior switchBehavior(RaftActorBehavior behavior);