Class BaseElection
java.lang.Object
org.jgroups.stack.Protocol
org.jgroups.protocols.raft.election.BaseElection
- All Implemented Interfaces:
org.jgroups.Lifecycle
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
FieldsModifier and TypeFieldDescriptionprotected intprotected static final shortprotected static final shortprotected RAFTprotected org.jgroups.Viewprotected static final shortprotected longFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected org.jgroups.Addressdown(org.jgroups.Event evt) org.jgroups.util.ResponseCollector<VoteResponse> getVotes()protected voidhandleMessage(org.jgroups.Message msg, RaftHeader hdr) protected abstract voidhandleView(org.jgroups.View v) voidinit()protected final booleanprotected booleanbooleanraft()voidprotected voidThe mechanism for deciding a new leader.booleanprotected voidsendLeaderElectedMessage(org.jgroups.Address leader, long term) protected voidsendVoteRequest(long new_term) protected voidsendVoteResponse(org.jgroups.Address dest, long term, long last_log_term, long last_log_index) voidstop()up(org.jgroups.Event evt) up(org.jgroups.Message msg) voidup(org.jgroups.util.MessageBatch batch) longvoteTimeout(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
-
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
-
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
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
-
raft
-
getVotes
-
isVotingThreadRunning
public boolean isVotingThreadRunning() -
runVotingThread
public boolean runVotingThread() -
handleView
protected abstract void handleView(org.jgroups.View v) -
resetStats
public void resetStats()- Overrides:
resetStatsin classorg.jgroups.stack.Protocol
-
init
- Specified by:
initin interfaceorg.jgroups.Lifecycle- Overrides:
initin classorg.jgroups.stack.Protocol- Throws:
Exception
-
stop
public void stop()- Specified by:
stopin interfaceorg.jgroups.Lifecycle- Overrides:
stopin classorg.jgroups.stack.Protocol
-
down
- Overrides:
downin classorg.jgroups.stack.Protocol
-
up
- Overrides:
upin classorg.jgroups.stack.Protocol
-
up
- Overrides:
upin classorg.jgroups.stack.Protocol
-
up
public void up(org.jgroups.util.MessageBatch batch) - Overrides:
upin classorg.jgroups.stack.Protocol
-
handleMessage
-
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
-
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
-