BUG-5626: do not allow overriding of RaftActor.handleCommand()
[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 javax.annotation.Nullable;
13 import org.opendaylight.controller.cluster.raft.RaftState;
14
15 /**
16  * A RaftActorBehavior represents the specific behavior of a RaftActor
17  * <p>
18  * A RaftActor can behave as one of the following,
19  * <ul>
20  *     <li> Follower </li>
21  *     <li> Candidate </li>
22  *     <li> Leader </li>
23  * </ul>
24  * <p>
25  * In each of these behaviors the Raft Actor handles the same Raft messages
26  * differently.
27  */
28 public interface RaftActorBehavior extends AutoCloseable{
29
30     /**
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.
34      *
35      * @param sender The sender of the message
36      * @param message A message that needs to be processed
37      *
38      * @return The new behavior or current behavior, or null if the message was not handled.
39      */
40     @Nullable RaftActorBehavior handleMessage(ActorRef sender, Object message);
41
42     /**
43      *
44      * @return The state associated with a given behavior
45      */
46     RaftState state();
47
48     /**
49      *
50      * @return The Id of the Leader if known else null
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      * @return the index of the log entry which is replicated to all nodes
62      */
63     long getReplicatedToAllIndex();
64
65     /**
66      * @return the leader's payload data version.
67      */
68     short getLeaderPayloadVersion();
69
70     /**
71      * switchBehavior makes sure that the current behavior is shutdown before it switches to the new
72      * behavior
73      *
74      * @param behavior The new behavior to switch to
75      * @return The new behavior
76      */
77     RaftActorBehavior switchBehavior(RaftActorBehavior behavior);
78
79     @Override
80     void close();
81 }