public class AtomixLeaderElector extends io.atomix.resource.AbstractResource<AtomixLeaderElector> implements AsyncLeaderElector
AsyncLeaderElector primitive.DistributedPrimitive.Status, DistributedPrimitive.Type| Modifier and Type | Field and Description |
|---|---|
static String |
CHANGE_SUBJECT |
DEFAULT_OPERTATION_TIMEOUT_MILLIS| Constructor and Description |
|---|
AtomixLeaderElector(io.atomix.copycat.client.CopycatClient client,
Properties properties) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
addChangeListener(Consumer<Change<Leadership>> consumer)
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> |
destroy()
Purges state associated with this primitive.
|
CompletableFuture<Void> |
evict(NodeId nodeId)
Attempts to evict a node from all leadership elections it is registered for.
|
CompletableFuture<Set<String>> |
getElectedTopics(NodeId nodeId) |
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<AtomixLeaderElector> |
open() |
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>> consumer)
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.
|
CompletableFuture<AtomixLeaderElector> |
setupCache() |
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.
|
close, config, context, delete, equals, hashCode, isClosed, isOpen, onEvent, onRecovery, onStateChange, options, recover, serializer, state, toString, typeclone, finalize, getClass, notify, notifyAll, wait, wait, waitasLeaderElector, asLeaderElector, primitiveTypeapplicationIdpublic static final String CHANGE_SUBJECT
public AtomixLeaderElector(io.atomix.copycat.client.CopycatClient client,
Properties properties)
public CompletableFuture<Void> destroy()
DistributedPrimitiveImplementations can override and provide appropriate clean up logic for purging any state state associated with the primitive. Whether modifications made within the destroy method have local or global visibility is left unspecified.
destroy in interface DistributedPrimitiveCompletableFuture that is completed when the operation completespublic String name()
DistributedPrimitivename in interface DistributedPrimitivepublic CompletableFuture<AtomixLeaderElector> open()
open in interface io.atomix.catalyst.util.Managed<AtomixLeaderElector>open in interface io.atomix.resource.Resource<AtomixLeaderElector>open in class io.atomix.resource.AbstractResource<AtomixLeaderElector>public CompletableFuture<AtomixLeaderElector> setupCache()
public 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<Set<String>> getElectedTopics(NodeId nodeId)
public CompletableFuture<Void> addChangeListener(Consumer<Change<Leadership>> consumer)
AsyncLeaderElectoraddChangeListener in interface AsyncLeaderElectorconsumer - listener to notifypublic CompletableFuture<Void> removeChangeListener(Consumer<Change<Leadership>> consumer)
AsyncLeaderElectorIf the specified listener was not previously registered, this operation will be a noop.
removeChangeListener in interface AsyncLeaderElectorconsumer - 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