Class BaseElection

java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.raft.election.BaseElection
All Implemented Interfaces:
org.jgroups.Lifecycle
Direct Known Subclasses:
ELECTION, ELECTION2

public abstract class BaseElection extends org.jgroups.stack.Protocol
Abstract leader election algorithm functionalities.

This abstraction includes the voting mechanism and handles messages and events from the stack. All the election algorithms extend this class. For more information, see the concrete implementations.

Author:
Bela Ban
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected static final short
     
    protected static final short
     
    protected RAFT
     
    protected org.jgroups.View
     
    protected static final short
     
    protected long
     

    Fields inherited from class org.jgroups.stack.Protocol

    after_creation_hook, down_prot, ergonomics, id, local_addr, log, policies, stack, stats, up_prot
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.jgroups.Address
     
    down(org.jgroups.Event evt)
     
    org.jgroups.util.ResponseCollector<VoteResponse>
     
    protected void
    handleMessage(org.jgroups.Message msg, RaftHeader hdr)
     
    protected abstract void
    handleView(org.jgroups.View v)
     
    void
     
    protected final boolean
     
    protected boolean
     
    boolean
     
     
     
    void
     
    protected void
    The mechanism for deciding a new leader.
    boolean
     
    protected void
    sendLeaderElectedMessage(org.jgroups.Address leader, long term)
     
    protected void
    sendVoteRequest(long new_term)
     
    protected void
    sendVoteResponse(org.jgroups.Address dest, long term, long last_log_term, long last_log_index)
     
     
    void
     
     
    up(org.jgroups.Event evt)
     
    up(org.jgroups.Message msg)
     
    void
    up(org.jgroups.util.MessageBatch batch)
     
    long
     
    voteTimeout(long timeoutMs)
    Defines the default timeout in milliseconds to utilize during any election operation.

    Methods inherited from class org.jgroups.stack.Protocol

    accept, addPolicy, addr, addr, afterCreationHook, destroy, down, down, enableStats, getAddress, getComponents, getDownProtocol, getDownServices, getId, getIdsAbove, getLevel, getLog, getName, getPolicies, getProtocolStack, getSocketFactory, getThreadFactory, getTransport, getUpProtocol, getUpServices, getValue, isErgonomics, level, parse, policies, providedDownServices, providedUpServices, removePolicy, requiredDownServices, requiredUpServices, resetStatistics, setAddress, setDownProtocol, setErgonomics, setId, setLevel, setPolicies, setProtocolStack, setSocketFactory, setUpProtocol, setValue, start, statsEnabled, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • VOTE_REQ

      protected static final short VOTE_REQ
      See Also:
    • PRE_VOTE_REQ

      protected static final short PRE_VOTE_REQ
      See Also:
    • PRE_VOTE_RSP

      protected static final short PRE_VOTE_RSP
      See Also:
    • raft

      protected RAFT raft
    • view

      protected volatile org.jgroups.View view
    • vote_timeout

      protected long vote_timeout
    • num_voting_rounds

      protected int num_voting_rounds
  • Constructor Details

    • BaseElection

      public BaseElection()
  • Method Details

    • voteTimeout

      public long voteTimeout()
    • voteTimeout

      public BaseElection voteTimeout(long timeoutMs)
      Defines the default timeout in milliseconds to utilize during any election operation.
      Parameters:
      timeoutMs - Timeout value in milliseconds.
      Returns:
      This election instance.
      Throws:
      IllegalArgumentException - In case timeout is less than or equal to 0.
    • raft

      public RAFT raft()
    • raft

      public BaseElection raft(RAFT r)
    • getVotes

      public org.jgroups.util.ResponseCollector<VoteResponse> getVotes()
    • isVotingThreadRunning

      public boolean isVotingThreadRunning()
    • runVotingThread

      public boolean runVotingThread()
    • handleView

      protected abstract void handleView(org.jgroups.View v)
    • resetStats

      public void resetStats()
      Overrides:
      resetStats in class org.jgroups.stack.Protocol
    • init

      public void init() throws Exception
      Specified by:
      init in interface org.jgroups.Lifecycle
      Overrides:
      init in class org.jgroups.stack.Protocol
      Throws:
      Exception
    • stop

      public void stop()
      Specified by:
      stop in interface org.jgroups.Lifecycle
      Overrides:
      stop in class org.jgroups.stack.Protocol
    • down

      public Object down(org.jgroups.Event evt)
      Overrides:
      down in class org.jgroups.stack.Protocol
    • up

      public Object up(org.jgroups.Event evt)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • up

      public Object up(org.jgroups.Message msg)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • up

      public void up(org.jgroups.util.MessageBatch batch)
      Overrides:
      up in class org.jgroups.stack.Protocol
    • handleMessage

      protected void handleMessage(org.jgroups.Message msg, RaftHeader hdr)
    • isViewCoordinator

      protected boolean isViewCoordinator()
    • determineLeader

      protected org.jgroups.Address determineLeader()
    • runVotingProcess

      protected void runVotingProcess()
      The mechanism for deciding a new leader.

      Increases its term and queries all participants about their term and log index information. The thread blocks (with a timeout) wait for responses. If the majority replies, the process with the highest term and index is elected.

      The process keeps running until a leader is elected or the majority is lost.

    • isMajorityAvailable

      protected final boolean isMajorityAvailable()
    • startVotingThread

      public BaseElection startVotingThread()
    • sendVoteRequest

      protected void sendVoteRequest(long new_term)
    • sendLeaderElectedMessage

      protected void sendLeaderElectedMessage(org.jgroups.Address leader, long term)
    • sendVoteResponse

      protected void sendVoteResponse(org.jgroups.Address dest, long term, long last_log_term, long last_log_index)
    • stopVotingThread

      public BaseElection stopVotingThread()