Merge "Bug 2682 - Switch sal-binding-dom-it to sal-test-model"
[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      * The state associated with a given behavior
43      *
44      * @return
45      */
46     RaftState state();
47
48     /**
49      *
50      * @return
51      */
52     String getLeaderId();
53
54     /**
55      * setting the index of the log entry which is replicated to all nodes
56      * @param replicatedToAllIndex
57      */
58     void setReplicatedToAllIndex(long replicatedToAllIndex);
59
60     /**
61      * getting the index of the log entry which is replicated to all nodes
62      * @return
63      */
64     long getReplicatedToAllIndex();
65 }