Class Candidate
java.lang.Object
org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior
org.opendaylight.controller.cluster.raft.behaviors.Candidate
- All Implemented Interfaces:
AutoCloseable,RaftActorBehavior
The behavior of a RaftActor when it is in the Candidate raft state.
Candidates (ยง5.2):
- On conversion to candidate, start election:
- Increment currentTerm
- Vote for self
- Reset election timer
- Send RequestVote RPCs to all other servers
- If votes received from majority of servers: become leader
- If AppendEntries RPC received from new leader: convert to follower
- If election timeout elapses: start new election
-
Field Summary
Fields inherited from class org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior
context, log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected scala.concurrent.duration.FiniteDurationReturns a duration for election with an additional variance for randomness.Returns the id of the leader.shortReturns the leader's payload data version.protected RaftActorBehaviorhandleAppendEntries(ActorRef sender, AppendEntries appendEntries) Derived classes should not directly handle AppendEntries messages it should let the base class handle it first.protected RaftActorBehaviorhandleAppendEntriesReply(ActorRef sender, AppendEntriesReply appendEntriesReply) Derived classes should not directly handle AppendEntriesReply messages it should let the base class handle it first.handleMessage(ActorRef sender, Object message) Handle a message.protected RaftActorBehaviorhandleRequestVoteReply(ActorRef sender, RequestVoteReply requestVoteReply) Derived classes should not directly handle RequestVoteReply messages it should let the base class handle it first.Methods inherited from class org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior
actor, appendEntries, applyLogToStateMachine, canGrantVote, canStartElection, createBehavior, currentTerm, getId, getLogEntryIndex, getLogEntryOrSnapshotTerm, getLogEntryTerm, getMajorityVoteCount, getReplicatedToAllIndex, internalSwitchBehavior, internalSwitchBehavior, lastIndex, lastTerm, logName, performSnapshotWithoutCapture, requestVote, scheduleElection, setReplicatedToAllIndex, shouldUpdateTerm, state, stopElection, switchBehavior, votedFor
-
Constructor Details
-
Candidate
-
-
Method Details
-
getLeaderId
Description copied from interface:RaftActorBehaviorReturns the id of the leader.- Returns:
- the id of the leader or null if not known
-
getLeaderPayloadVersion
public short getLeaderPayloadVersion()Description copied from interface:RaftActorBehaviorReturns the leader's payload data version.- Returns:
- a short representing the version
-
handleAppendEntries
Description copied from class:AbstractRaftActorBehaviorDerived classes should not directly handle AppendEntries messages it should let the base class handle it first. Once the base class handles the AppendEntries message and does the common actions that are applicable in all RaftState's it will delegate the handling of the AppendEntries message to the derived class to do more state specific handling by calling this method- Specified by:
handleAppendEntriesin classAbstractRaftActorBehavior- Parameters:
sender- The actor that sent this messageappendEntries- The AppendEntries message- Returns:
- a new behavior if it was changed or the current behavior
-
handleAppendEntriesReply
protected RaftActorBehavior handleAppendEntriesReply(ActorRef sender, AppendEntriesReply appendEntriesReply) Description copied from class:AbstractRaftActorBehaviorDerived classes should not directly handle AppendEntriesReply messages it should let the base class handle it first. Once the base class handles the AppendEntriesReply message and does the common actions that are applicable in all RaftState's it will delegate the handling of the AppendEntriesReply message to the derived class to do more state specific handling by calling this method- Specified by:
handleAppendEntriesReplyin classAbstractRaftActorBehavior- Parameters:
sender- The actor that sent this messageappendEntriesReply- The AppendEntriesReply message- Returns:
- a new behavior if it was changed or the current behavior
-
handleRequestVoteReply
protected RaftActorBehavior handleRequestVoteReply(ActorRef sender, RequestVoteReply requestVoteReply) Description copied from class:AbstractRaftActorBehaviorDerived classes should not directly handle RequestVoteReply messages it should let the base class handle it first. Once the base class handles the RequestVoteReply message and does the common actions that are applicable in all RaftState's it will delegate the handling of the RequestVoteReply message to the derived class to do more state specific handling by calling this method- Specified by:
handleRequestVoteReplyin classAbstractRaftActorBehavior- Parameters:
sender- The actor that sent this messagerequestVoteReply- The RequestVoteReply message- Returns:
- a new behavior if it was changed or the current behavior
-
electionDuration
protected scala.concurrent.duration.FiniteDuration electionDuration()Description copied from class:AbstractRaftActorBehaviorReturns a duration for election with an additional variance for randomness.- Overrides:
electionDurationin classAbstractRaftActorBehavior- Returns:
- a random election duration
-
handleMessage
Description copied from interface:RaftActorBehaviorHandle 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.- Specified by:
handleMessagein interfaceRaftActorBehavior- Overrides:
handleMessagein classAbstractRaftActorBehavior- 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.
-
close
public void close()
-