public interface LeaderElector<T> extends SyncPrimitive
LeaderElector provides the same functionality as AsyncLeaderElector with
the only difference that all its methods block until the corresponding operation completes.DEFAULT_OPERATION_TIMEOUT_MILLIS| Modifier and Type | Method and Description |
|---|---|
void |
addListener(LeadershipEventListener<T> listener)
Registers a listener to be notified of Leadership changes for all topics.
|
void |
addListener(String topic,
LeadershipEventListener<T> listener)
Registers a listener to be notified of Leadership changes for all topics.
|
boolean |
anoint(String topic,
T identifier)
Attempts to promote a node to leadership displacing the current leader.
|
AsyncLeaderElector<T> |
async()
Returns the underlying asynchronous primitive.
|
void |
evict(T identifier)
Attempts to evict a node from all leadership elections it is registered for.
|
Leadership<T> |
getLeadership(String topic)
Returns the
Leadership for the specified topic. |
Map<String,Leadership<T>> |
getLeaderships()
Returns the current
Leaderships for all topics. |
boolean |
promote(String topic,
T identifier)
Attempts to promote a node to top of candidate list.
|
void |
removeListener(LeadershipEventListener<T> listener)
Unregisters a previously registered change notification listener.
|
void |
removeListener(String topic,
LeadershipEventListener<T> listener)
Unregisters a previously registered change notification listener.
|
Leadership<T> |
run(String topic,
T identifier)
Attempts to become leader for a topic.
|
void |
withdraw(String topic,
T identifier)
Withdraws from leadership race for a topic.
|
close, deleteaddStateChangeListener, name, protocol, removeStateChangeListener, typeLeadership<T> run(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the candidatevoid withdraw(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the candidate to withdrawboolean anoint(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the node to anointtrue if leadership transfer was successfully executed; false if it failed.
This operation can return false if the node to be made new leader is not registered to
run for election for the topic.boolean promote(String topic, T identifier)
topic - leadership topicidentifier - instance identifier of the node to promotetrue if node is now the top candidate. This operation can fail (i.e. return
false) if the node is not registered to run for election for the topic.void evict(T identifier)
If the node the current leader for a topic, this call will force the next candidate (if one exists) to be promoted to leadership.
identifier - instance identifierLeadership<T> getLeadership(String topic)
Leadership for the specified topic.topic - leadership topicMap<String,Leadership<T>> getLeaderships()
Leaderships for all topics.void addListener(LeadershipEventListener<T> listener)
listener - listener to notifyvoid removeListener(LeadershipEventListener<T> listener)
If the specified listener was not previously registered, this operation will be a noop.
listener - listener to removevoid addListener(String topic, LeadershipEventListener<T> listener)
topic - leadership topiclistener - listener to notifyvoid 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 removeAsyncLeaderElector<T> async()
SyncPrimitiveasync in interface SyncPrimitiveCopyright © 2013–2018. All rights reserved.