Class Candidate
- java.lang.Object
-
- org.opendaylight.controller.cluster.raft.behaviors.AbstractRaftActorBehavior
-
- org.opendaylight.controller.cluster.raft.behaviors.Candidate
-
- All Implemented Interfaces:
AutoCloseable
,RaftActorBehavior
public class Candidate extends AbstractRaftActorBehavior
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 Constructor Description Candidate(RaftActorContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected scala.concurrent.duration.FiniteDuration
electionDuration()
Returns a duration for election with an additional variance for randomness.String
getLeaderId()
Returns the id of the leader.short
getLeaderPayloadVersion()
Returns the leader's payload data version.protected RaftActorBehavior
handleAppendEntries(ActorRef sender, AppendEntries appendEntries)
Derived classes should not directly handle AppendEntries messages it should let the base class handle it first.protected RaftActorBehavior
handleAppendEntriesReply(ActorRef sender, AppendEntriesReply appendEntriesReply)
Derived classes should not directly handle AppendEntriesReply messages it should let the base class handle it first.RaftActorBehavior
handleMessage(ActorRef sender, Object message)
Handle a message.protected RaftActorBehavior
handleRequestVoteReply(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 Detail
-
Candidate
public Candidate(RaftActorContext context)
-
-
Method Detail
-
getLeaderId
public final String getLeaderId()
Description copied from interface:RaftActorBehavior
Returns the id of the leader.- Returns:
- the id of the leader or null if not known
-
getLeaderPayloadVersion
public final short getLeaderPayloadVersion()
Description copied from interface:RaftActorBehavior
Returns the leader's payload data version.- Returns:
- a short representing the version
-
handleAppendEntries
protected RaftActorBehavior handleAppendEntries(ActorRef sender, AppendEntries appendEntries)
Description copied from class:AbstractRaftActorBehavior
Derived 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:
handleAppendEntries
in 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:AbstractRaftActorBehavior
Derived 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:
handleAppendEntriesReply
in 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:AbstractRaftActorBehavior
Derived 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:
handleRequestVoteReply
in 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:AbstractRaftActorBehavior
Returns a duration for election with an additional variance for randomness.- Overrides:
electionDuration
in classAbstractRaftActorBehavior
- Returns:
- a random election duration
-
handleMessage
public RaftActorBehavior handleMessage(ActorRef sender, Object message)
Description copied from interface:RaftActorBehavior
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.- Specified by:
handleMessage
in interfaceRaftActorBehavior
- Overrides:
handleMessage
in 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()
-
-