public interface LeaderElector extends DistributedPrimitive
LeaderElector
provides the same functionality as AsyncLeaderElector
with
the only difference that all its methods block until the corresponding operation completes.DistributedPrimitive.Status, DistributedPrimitive.Type
DEFAULT_OPERATION_TIMEOUT_MILLIS, DEFAULT_OPERTATION_TIMEOUT_MILLIS
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(Consumer<Change<Leadership>> consumer)
Registers a listener to be notified of Leadership changes for all topics.
|
boolean |
anoint(String topic,
NodeId nodeId)
Attempts to promote a node to leadership displacing the current leader.
|
void |
evict(NodeId nodeId)
Attempts to evict a node from all leadership elections it is registered for.
|
Leadership |
getLeadership(String topic)
Returns the
Leadership for the specified topic. |
Map<String,Leadership> |
getLeaderships()
Returns the current
Leadership s for all topics. |
default DistributedPrimitive.Type |
primitiveType()
Returns the type of primitive.
|
boolean |
promote(String topic,
NodeId nodeId)
Attempts to promote a node to top of candidate list.
|
void |
removeChangeListener(Consumer<Change<Leadership>> consumer)
Unregisters a previously registered change notification listener.
|
Leadership |
run(String topic,
NodeId nodeId)
Attempts to become leader for a topic.
|
void |
withdraw(String topic)
Withdraws from leadership race for a topic.
|
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
default DistributedPrimitive.Type primitiveType()
DistributedPrimitive
primitiveType
in interface DistributedPrimitive
Leadership run(String topic, NodeId nodeId)
topic
- leadership topicnodeId
- instance identifier of the nodevoid withdraw(String topic)
topic
- leadership topicboolean anoint(String topic, NodeId nodeId)
topic
- leadership topicnodeId
- instance identifier of the new leadertrue
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, NodeId nodeId)
topic
- leadership topicnodeId
- instance identifier of the new top candidatetrue
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(NodeId nodeId)
If the node the current leader for a topic, this call will force the next candidate (if one exists) to be promoted to leadership.
nodeId
- node instance identifierLeadership getLeadership(String topic)
Leadership
for the specified topic.topic
- leadership topicMap<String,Leadership> getLeaderships()
Leadership
s for all topics.void addChangeListener(Consumer<Change<Leadership>> consumer)
consumer
- listener to addvoid removeChangeListener(Consumer<Change<Leadership>> consumer)
If the specified listener was not previously registered, this operation will be a noop.
consumer
- listener to remove