Package org.apache.storm.nimbus
Interface ILeaderElector
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
LeaderElectorImp,MockLeaderElector
public interface ILeaderElector extends AutoCloseable
The interface for leader election.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddToLeaderLockQueue()queue up for leadership lock.booleanawaitLeadership(long timeout, TimeUnit timeUnit)Wait for the caller to gain leadership.voidclose()Method called to allow for cleanup.List<NimbusInfo>getAllNimbuses()Get list of current nimbus addresses.NimbusInfogetLeader()Get the current leader's address.booleanisLeader()Decide if the caller currently has the leader lock.voidprepare(Map<String,Object> conf)Method guaranteed to be called as part of initialization of leader elector instance.voidquitElectionFor(int delayMs)Removes the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.
-
-
-
Method Detail
-
prepare
void prepare(Map<String,Object> conf)
Method guaranteed to be called as part of initialization of leader elector instance.- Parameters:
conf- configuration
-
addToLeaderLockQueue
void addToLeaderLockQueue() throws Exceptionqueue up for leadership lock. The call returns immediately and the caller must check isLeader() to perform any leadership action. This method can be called multiple times so it needs to be idempotent.- Throws:
Exception
-
quitElectionFor
void quitElectionFor(int delayMs) throws ExceptionRemoves the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.- Parameters:
delayMs- The delay to wait before re-entering the election- Throws:
Exception
-
isLeader
boolean isLeader() throws ExceptionDecide if the caller currently has the leader lock.- Returns:
- true if the caller currently has the leader lock.
- Throws:
Exception
-
getLeader
NimbusInfo getLeader()
Get the current leader's address.- Returns:
- the current leader's address, may return null if no one has the lock.
-
awaitLeadership
boolean awaitLeadership(long timeout, TimeUnit timeUnit) throws InterruptedExceptionWait for the caller to gain leadership. This should only be used in single-Nimbus clusters, and is only useful to allow testing code to wait for a LocalCluster's Nimbus to gain leadership before trying to submit topologies.- Returns:
- true is leadership was acquired, false otherwise
- Throws:
InterruptedException
-
getAllNimbuses
List<NimbusInfo> getAllNimbuses() throws Exception
Get list of current nimbus addresses.- Returns:
- list of current nimbus addresses, includes leader.
- Throws:
Exception
-
close
void close() throws ExceptionMethod called to allow for cleanup. Relinquishes leadership if owned by the caller.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
-