Interface RaftActorBehavior
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractLeader,AbstractRaftActorBehavior,Candidate,Follower,IsolatedLeader,Leader,PreLeader
The interface for a class that implements a specific behavior of a RaftActor. The types of behaviors are enumerated
by
RaftState. Each handles the same Raft messages differently.-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()@Nullable StringReturns the id of the leader.shortReturns the leader's payload data version.longReturns the index of the last log entry that has been replicated to all peers.@Nullable RaftActorBehaviorhandleMessage(akka.actor.ActorRef sender, Object message) Handle a message.voidsetReplicatedToAllIndex(long replicatedToAllIndex) Sets the index of the last log entry that has been replicated to all peers.state()Returns the state associated with this behavior.switchBehavior(RaftActorBehavior behavior) Closes the current behavior and switches to the specified behavior, if possible.
-
Method Details
-
handleMessage
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
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:
closein interfaceAutoCloseable
-