public interface AsyncLeaderElector<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.
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<Void> |
addListener(String topic,
LeadershipEventListener<T> listener)
Registers a listener to be notified of Leadership changes for all topics.
|
CompletableFuture<Boolean> |
anoint(String topic,
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(String topic)
Returns the
Leadership for the specified topic. |
CompletableFuture<Map<String,Leadership<T>>> |
getLeaderships()
Returns the current
Leaderships for all topics. |
CompletableFuture<Boolean> |
promote(String topic,
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<Void> |
removeListener(String topic,
LeadershipEventListener<T> listener)
Unregisters a previously registered change notification listener.
|
CompletableFuture<Leadership<T>> |
run(String topic,
T identifier)
Attempts to become leader for a topic.
|
default LeaderElector<T> |
sync()
Returns a synchronous wrapper around the asynchronous primitive.
|
LeaderElector<T> |
sync(Duration operationTimeout)
Returns a synchronous wrapper around the asynchronous primitive.
|
CompletableFuture<Void> |
withdraw(String topic,
T identifier)
Withdraws from leadership race for a topic.
|
close, deleteaddStateChangeListener, name, protocol, removeStateChangeListener, typeCompletableFuture<Leadership<T>> run(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the candidateCompletableFuture<Void> withdraw(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the candidate to withdrawCompletableFuture<Boolean> anoint(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the candidate to anointCompletableFuture<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 - instance identifierCompletableFuture<Boolean> promote(String topic, T identifier)
topic - leadership topicidentifier - instance identifierCompletableFuture<Leadership<T>> getLeadership(String topic)
Leadership for the specified topic.topic - leadership topicCompletableFuture<Map<String,Leadership<T>>> getLeaderships()
Leaderships for all topics.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 removeCompletableFuture<Void> addListener(String topic, LeadershipEventListener<T> listener)
topic - leadership topiclistener - listener to notifyCompletableFuture<Void> removeListener(String topic, LeadershipEventListener<T> listener)
If the specified listener was not previously registered, this operation will be a noop.
topic - leadership topiclistener - listener to removedefault LeaderElector<T> sync()
AsyncPrimitivesync in interface AsyncPrimitiveLeaderElector<T> sync(Duration operationTimeout)
AsyncPrimitivesync in interface AsyncPrimitiveoperationTimeout - the synchronous operation timeoutCopyright © 2013–2018. All rights reserved.