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
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.raft.behaviors;
10
11 import akka.actor.ActorRef;
12 import org.opendaylight.controller.cluster.raft.RaftState;
13
14 /**
15  * A RaftActorBehavior represents the specific behavior of a RaftActor
16  * <p>
17  * A RaftActor can behave as one of the following,
18  * <ul>
19  *     <li> Follower </li>
20  *     <li> Candidate </li>
21  *     <li> Leader </li>
22  * </ul>
23  * <p>
24  * In each of these behaviors the Raft Actor handles the same Raft messages
25  * differently.
26  */
27 public interface RaftActorBehavior extends AutoCloseable{
28
29     /**
30      * Handle a message. If the processing of the message warrants a state
31      * change then a new behavior should be returned otherwise this method should
32      * return the current behavior.
33      *
34      * @param sender The sender of the message
35      * @param message A message that needs to be processed
36      *
37      * @return The new behavior or current behavior
38      */
39     RaftActorBehavior handleMessage(ActorRef sender, Object message);
40
41     /**
42      *
43      * @return The state associated with a given behavior
44      */
45     RaftState state();
46
47     /**
48      *
49      * @return The Id of the Leader if known else null
50      */
51     String getLeaderId();
52
53     /**
54      * setting the index of the log entry which is replicated to all nodes
55      * @param replicatedToAllIndex
56      */
57     void setReplicatedToAllIndex(long replicatedToAllIndex);
58
59     /**
60      * @return the index of the log entry which is replicated to all nodes
61      */
62     long getReplicatedToAllIndex();
63
64     /**
65      * @return the leader's payload data version.
66      */
67     short getLeaderPayloadVersion();
68
69     /**
70      * switchBehavior makes sure that the current behavior is shutdown before it switches to the new
71      * behavior
72      *
73      * @param behavior The new behavior to switch to
74      * @return The new behavior
75      */
76     RaftActorBehavior switchBehavior(RaftActorBehavior behavior);
77 }