BUG 2185 : Introduce the SwitchBehavior message
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / behaviors / RaftActorBehavior.java
index 6811678aaa9cfeb820e1169d530e112e5174e3ce..b0a7638b92abdec6aef770cc6170a5c5353cc434 100644 (file)
@@ -24,16 +24,54 @@ import org.opendaylight.controller.cluster.raft.RaftState;
  * In each of these behaviors the Raft Actor handles the same Raft messages
  * differently.
  */
-public interface RaftActorBehavior {
+public interface RaftActorBehavior extends AutoCloseable{
+
     /**
      * Handle a message. If the processing of the message warrants a state
-     * change then a new state should be returned otherwise this method should
-     * return the state for the current behavior.
+     * change then a new behavior should be returned otherwise this method should
+     * return the current behavior.
      *
      * @param sender The sender of the message
      * @param message A message that needs to be processed
      *
-     * @return The new state or self (this)
+     * @return The new behavior or current behavior
+     */
+    RaftActorBehavior handleMessage(ActorRef sender, Object message);
+
+    /**
+     *
+     * @return The state associated with a given behavior
+     */
+    RaftState state();
+
+    /**
+     *
+     * @return The Id of the Leader if known else null
+     */
+    String getLeaderId();
+
+    /**
+     * setting the index of the log entry which is replicated to all nodes
+     * @param replicatedToAllIndex
+     */
+    void setReplicatedToAllIndex(long replicatedToAllIndex);
+
+    /**
+     * @return the index of the log entry which is replicated to all nodes
+     */
+    long getReplicatedToAllIndex();
+
+    /**
+     * @return the leader's payload data version.
+     */
+    short getLeaderPayloadVersion();
+
+    /**
+     * switchBehavior makes sure that the current behavior is shutdown before it switches to the new
+     * behavior
+     *
+     * @param behavior The new behavior to switch to
+     * @return The new behavior
      */
-    RaftState handleMessage(ActorRef sender, Object message);
+    RaftActorBehavior switchBehavior(RaftActorBehavior behavior);
 }