public interface AsyncLeaderElection<T> extends AsyncPrimitive
AsyncLeaderElector facilitates mutually exclusive access to a shared resource by various cluster members.
Each resource is identified by a unique topic name and members register their desire to access the resource by
calling the run method. Access is grated on a FIFO basis. An instance can
unregister itself from the leadership election by calling withdraw method.
If an instance currently holding the resource dies then the next instance waiting to be leader (in FIFO order)
will be automatically granted access to the resource.
One can register listeners to be notified when a leadership change occurs. The Listeners are notified via a
LeadershipEvent.
Additionally, AsyncLeaderElector provides methods to query the current state of leadership for topics.
All methods of this interface return a future immediately after a successful invocation.
The operation itself is executed asynchronous and the returned future will be
completed when the operation finishes.
DEFAULT_OPERATION_TIMEOUT_MILLIS| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
addListener(LeadershipEventListener<T> listener)
Registers a listener to be notified of Leadership changes for all topics.
|
CompletableFuture<Boolean> |
anoint(T identifier)
Attempts to promote a node to leadership displacing the current leader.
|
CompletableFuture<Void> |
evict(T identifier)
Attempts to evict a node from all leadership elections it is registered for.
|
CompletableFuture<Leadership<T>> |
getLeadership()
Returns the
Leadership for the specified topic. |
CompletableFuture<Boolean> |
promote(T identifier)
Attempts to promote a node to top of candidate list without displacing the current leader.
|
CompletableFuture<Void> |
removeListener(LeadershipEventListener<T> listener)
Unregisters a previously registered change notification listener.
|
CompletableFuture<Leadership<T>> |
run(T identifier)
Attempts to become leader for a topic.
|
default LeaderElection<T> |
sync()
Returns a synchronous wrapper around the asynchronous primitive.
|
LeaderElection<T> |
sync(Duration operationTimeout)
Returns a synchronous wrapper around the asynchronous primitive.
|
CompletableFuture<Void> |
withdraw(T identifier)
Withdraws from leadership race for a topic.
|
close, deleteaddStateChangeListener, name, protocol, removeStateChangeListener, typeCompletableFuture<Leadership<T>> run(T identifier)
identifier - instance identifier of the nodeCompletableFuture<Void> withdraw(T identifier)
identifier - instance identifier of the node to withdrawCompletableFuture<Boolean> anoint(T identifier)
identifier - instance identifier of the new leaderCompletableFuture<Void> evict(T identifier)
If the node is the current leader for a topic, this call will promote the next top candidate (if one exists) to leadership.
identifier - node instance identifierCompletableFuture<Boolean> promote(T identifier)
identifier - instance identifier of the new top candidateCompletableFuture<Leadership<T>> getLeadership()
Leadership for the specified topic.CompletableFuture<Void> addListener(LeadershipEventListener<T> listener)
listener - listener to notifyCompletableFuture<Void> removeListener(LeadershipEventListener<T> listener)
If the specified listener was not previously registered, this operation will be a noop.
listener - listener to removedefault LeaderElection<T> sync()
AsyncPrimitivesync in interface AsyncPrimitiveLeaderElection<T> sync(Duration operationTimeout)
AsyncPrimitivesync in interface AsyncPrimitiveoperationTimeout - the synchronous operation timeoutCopyright © 2013–2018. All rights reserved.