public class PartitionedAsyncLeaderElector extends Object implements AsyncLeaderElector
AsyncLeaderElector that has its topics partitioned horizontally across
several leader electors.DistributedPrimitive.Status, DistributedPrimitive.TypeDEFAULT_OPERTATION_TIMEOUT_MILLIS| Constructor and Description |
|---|
PartitionedAsyncLeaderElector(String name,
Map<PartitionId,AsyncLeaderElector> partitions,
Hasher<String> topicHasher) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
addChangeListener(Consumer<Change<Leadership>> listener)
Registers a listener to be notified of Leadership changes for all topics.
|
void |
addStatusChangeListener(Consumer<DistributedPrimitive.Status> listener)
Registers a listener to be called when the primitive's status changes.
|
CompletableFuture<Boolean> |
anoint(String topic,
NodeId nodeId)
Attempts to promote a node to leadership displacing the current leader.
|
CompletableFuture<Void> |
evict(NodeId nodeId)
Attempts to evict a node from all leadership elections it is registered for.
|
CompletableFuture<Leadership> |
getLeadership(String topic)
Returns the
Leadership for the specified topic. |
CompletableFuture<Map<String,Leadership>> |
getLeaderships()
Returns the current
Leaderships for all topics. |
String |
name()
Returns the name of this primitive.
|
CompletableFuture<Boolean> |
promote(String topic,
NodeId nodeId)
Attempts to promote a node to top of candidate list without displacing the current leader.
|
CompletableFuture<Void> |
removeChangeListener(Consumer<Change<Leadership>> listener)
Unregisters a previously registered change notification listener.
|
void |
removeStatusChangeListener(Consumer<DistributedPrimitive.Status> listener)
Unregisters a previously registered listener to be called when the primitive's status changes.
|
CompletableFuture<Leadership> |
run(String topic,
NodeId nodeId)
Attempts to become leader for a topic.
|
Collection<Consumer<DistributedPrimitive.Status>> |
statusChangeListeners()
Returns the collection of status change listeners previously registered.
|
CompletableFuture<Void> |
withdraw(String topic)
Withdraws from leadership race for a topic.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasLeaderElector, asLeaderElector, primitiveTypeapplicationId, destroypublic PartitionedAsyncLeaderElector(String name, Map<PartitionId,AsyncLeaderElector> partitions, Hasher<String> topicHasher)
public String name()
DistributedPrimitivename in interface DistributedPrimitivepublic CompletableFuture<Leadership> run(String topic, NodeId nodeId)
AsyncLeaderElectorrun in interface AsyncLeaderElectortopic - leadership topicnodeId - instance identifier of the nodepublic CompletableFuture<Void> withdraw(String topic)
AsyncLeaderElectorwithdraw in interface AsyncLeaderElectortopic - leadership topicpublic CompletableFuture<Boolean> anoint(String topic, NodeId nodeId)
AsyncLeaderElectoranoint in interface AsyncLeaderElectortopic - leadership topicnodeId - instance identifier of the new leaderpublic CompletableFuture<Boolean> promote(String topic, NodeId nodeId)
AsyncLeaderElectorpromote in interface AsyncLeaderElectortopic - leadership topicnodeId - instance identifier of the new top candidatepublic CompletableFuture<Void> evict(NodeId nodeId)
AsyncLeaderElectorIf the node is the current leader for a topic, this call will promote the next top candidate (if one exists) to leadership.
evict in interface AsyncLeaderElectornodeId - node instance identifierpublic CompletableFuture<Leadership> getLeadership(String topic)
AsyncLeaderElectorLeadership for the specified topic.getLeadership in interface AsyncLeaderElectortopic - leadership topicpublic CompletableFuture<Map<String,Leadership>> getLeaderships()
AsyncLeaderElectorLeaderships for all topics.getLeaderships in interface AsyncLeaderElectorpublic CompletableFuture<Void> addChangeListener(Consumer<Change<Leadership>> listener)
AsyncLeaderElectoraddChangeListener in interface AsyncLeaderElectorlistener - listener to notifypublic CompletableFuture<Void> removeChangeListener(Consumer<Change<Leadership>> listener)
AsyncLeaderElectorIf the specified listener was not previously registered, this operation will be a noop.
removeChangeListener in interface AsyncLeaderElectorlistener - listener to removepublic void addStatusChangeListener(Consumer<DistributedPrimitive.Status> listener)
DistributedPrimitiveaddStatusChangeListener in interface DistributedPrimitivelistener - The listener to be called when the status changes.public void removeStatusChangeListener(Consumer<DistributedPrimitive.Status> listener)
DistributedPrimitiveremoveStatusChangeListener in interface DistributedPrimitivelistener - The listener to unregisterpublic Collection<Consumer<DistributedPrimitive.Status>> statusChangeListeners()
DistributedPrimitivestatusChangeListeners in interface DistributedPrimitive