Class 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
    • 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 class AbstractRaftActorBehavior
        Parameters:
        sender - The actor that sent this message
        appendEntries - 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 class AbstractRaftActorBehavior
        Parameters:
        sender - The actor that sent this message
        appendEntriesReply - 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 class AbstractRaftActorBehavior
        Parameters:
        sender - The actor that sent this message
        requestVoteReply - The RequestVoteReply message
        Returns:
        a new behavior if it was changed or the current behavior
      • 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 interface RaftActorBehavior
        Overrides:
        handleMessage in class AbstractRaftActorBehavior
        Parameters:
        sender - The sender of the message
        message - 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()