Interface RaftActorBehavior
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractLeader
,AbstractRaftActorBehavior
,Candidate
,Follower
,IsolatedLeader
,Leader
,PreLeader
public interface RaftActorBehavior extends AutoCloseable
The interface for a class that implements a specific behavior of a RaftActor. The types of behaviors are enumerated byRaftState
. Each handles the same Raft messages differently.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
@Nullable String
getLeaderId()
Returns the id of the leader.short
getLeaderPayloadVersion()
Returns the leader's payload data version.long
getReplicatedToAllIndex()
Returns the index of the last log entry that has been replicated to all peers.@Nullable RaftActorBehavior
handleMessage(ActorRef sender, Object message)
Handle a message.void
setReplicatedToAllIndex(long replicatedToAllIndex)
Sets the index of the last log entry that has been replicated to all peers.RaftState
state()
Returns the state associated with this behavior.RaftActorBehavior
switchBehavior(RaftActorBehavior behavior)
Closes the current behavior and switches to the specified behavior, if possible.
-
-
-
Method Detail
-
handleMessage
@Nullable RaftActorBehavior handleMessage(ActorRef sender, Object message)
Handle a message. If the processing of the message warrants a state change then a new behavior should be returned otherwise this method should return the current behavior.- Parameters:
sender
- The sender of the messagemessage
- A message that needs to be processed- Returns:
- The new behavior or current behavior, or null if the message was not handled.
-
state
RaftState state()
Returns the state associated with this behavior.- Returns:
- the RaftState
-
getLeaderId
@Nullable String getLeaderId()
Returns the id of the leader.- Returns:
- the id of the leader or null if not known
-
setReplicatedToAllIndex
void setReplicatedToAllIndex(long replicatedToAllIndex)
Sets the index of the last log entry that has been replicated to all peers.- Parameters:
replicatedToAllIndex
- the index
-
getReplicatedToAllIndex
long getReplicatedToAllIndex()
Returns the index of the last log entry that has been replicated to all peers.- Returns:
- the index or -1 if not known
-
getLeaderPayloadVersion
short getLeaderPayloadVersion()
Returns the leader's payload data version.- Returns:
- a short representing the version
-
switchBehavior
RaftActorBehavior switchBehavior(RaftActorBehavior behavior)
Closes the current behavior and switches to the specified behavior, if possible.- Parameters:
behavior
- the new behavior to switch to- Returns:
- the new behavior
-
close
void close()
- Specified by:
close
in interfaceAutoCloseable
-
-