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