Fixup checkstyle
[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 package org.opendaylight.controller.cluster.raft.behaviors;
9
10 import akka.actor.ActorRef;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.controller.cluster.raft.RaftState;
13
14 /**
15  * The interface for a class that implements a specific behavior of a RaftActor. The types of behaviors are enumerated
16  * by {@link RaftState}. Each handles the same Raft messages differently.
17  */
18 public interface RaftActorBehavior extends AutoCloseable {
19
20     /**
21      * Handle a message. If the processing of the message warrants a state
22      * change then a new behavior should be returned otherwise this method should
23      * return the current behavior.
24      *
25      * @param sender The sender of the message
26      * @param message A message that needs to be processed
27      *
28      * @return The new behavior or current behavior, or null if the message was not handled.
29      */
30     @Nullable RaftActorBehavior handleMessage(ActorRef sender, Object message);
31
32     /**
33      * Returns the state associated with this behavior.
34      *
35      * @return the RaftState
36      */
37     RaftState state();
38
39     /**
40      * Returns the id of the leader.
41      *
42      * @return the id of the leader or null if not known
43      */
44     @Nullable String getLeaderId();
45
46     /**
47      * Sets the index of the last log entry that has been replicated to all peers.
48      *
49      * @param replicatedToAllIndex the index
50      */
51     void setReplicatedToAllIndex(long replicatedToAllIndex);
52
53     /**
54      * Returns the index of the last log entry that has been replicated to all peers.
55      *
56      * @return the index or -1 if not known
57      */
58     long getReplicatedToAllIndex();
59
60     /**
61      * Returns the leader's payload data version.
62      *
63      * @return a short representing the version
64      */
65     short getLeaderPayloadVersion();
66
67     /**
68      * Closes the current behavior and switches to the specified behavior, if possible.
69      *
70      * @param behavior the new behavior to switch to
71      * @return the new behavior
72      */
73     RaftActorBehavior switchBehavior(RaftActorBehavior behavior);
74
75     @Override
76     void close();
77 }