Package org.onosproject.store.service
Interface LeaderElector
-
- All Superinterfaces:
DistributedPrimitive
- All Known Implementing Classes:
DefaultLeaderElector
public interface LeaderElector extends DistributedPrimitive
LeaderElector
provides the same functionality asAsyncLeaderElector
with the only difference that all its methods block until the corresponding operation completes.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitive
DistributedPrimitive.Status, DistributedPrimitive.Type
-
-
Field Summary
-
Fields inherited from interface org.onosproject.store.service.DistributedPrimitive
DEFAULT_OPERATION_TIMEOUT_MILLIS
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addChangeListener(java.util.function.Consumer<Change<Leadership>> consumer)
Registers a listener to be notified of Leadership changes for all topics.boolean
anoint(java.lang.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(java.lang.String topic)
Returns theLeadership
for the specified topic.java.util.Map<java.lang.String,Leadership>
getLeaderships()
Returns the currentLeadership
s for all topics.default DistributedPrimitive.Type
primitiveType()
Returns the type of primitive.boolean
promote(java.lang.String topic, NodeId nodeId)
Attempts to promote a node to top of candidate list.void
removeChangeListener(java.util.function.Consumer<Change<Leadership>> consumer)
Unregisters a previously registered change notification listener.Leadership
run(java.lang.String topic, NodeId nodeId)
Attempts to become leader for a topic.void
withdraw(java.lang.String topic)
Withdraws from leadership race for a topic.-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Method Detail
-
primitiveType
default DistributedPrimitive.Type primitiveType()
Description copied from interface:DistributedPrimitive
Returns the type of primitive.- Specified by:
primitiveType
in interfaceDistributedPrimitive
- Returns:
- primitive type
-
run
Leadership run(java.lang.String topic, NodeId nodeId)
Attempts to become leader for a topic.- Parameters:
topic
- leadership topicnodeId
- instance identifier of the node- Returns:
- current Leadership state of the topic
-
withdraw
void withdraw(java.lang.String topic)
Withdraws from leadership race for a topic.- Parameters:
topic
- leadership topic
-
anoint
boolean anoint(java.lang.String topic, NodeId nodeId)
Attempts to promote a node to leadership displacing the current leader.- Parameters:
topic
- leadership topicnodeId
- instance identifier of the new leader- Returns:
true
if leadership transfer was successfully executed;false
if it failed. This operation can returnfalse
if the node to be made new leader is not registered to run for election for the topic.
-
promote
boolean promote(java.lang.String topic, NodeId nodeId)
Attempts to promote a node to top of candidate list.- Parameters:
topic
- leadership topicnodeId
- instance identifier of the new top candidate- Returns:
true
if node is now the top candidate. This operation can fail (i.e. returnfalse
) if the node is not registered to run for election for the topic.
-
evict
void evict(NodeId nodeId)
Attempts to evict a node from all leadership elections it is registered for.If the node the current leader for a topic, this call will force the next candidate (if one exists) to be promoted to leadership.
- Parameters:
nodeId
- node instance identifier
-
getLeadership
Leadership getLeadership(java.lang.String topic)
Returns theLeadership
for the specified topic.- Parameters:
topic
- leadership topic- Returns:
- current Leadership state of the topic
-
getLeaderships
java.util.Map<java.lang.String,Leadership> getLeaderships()
Returns the currentLeadership
s for all topics.- Returns:
- topic name to Leadership mapping
-
addChangeListener
void addChangeListener(java.util.function.Consumer<Change<Leadership>> consumer)
Registers a listener to be notified of Leadership changes for all topics.- Parameters:
consumer
- listener to add
-
removeChangeListener
void removeChangeListener(java.util.function.Consumer<Change<Leadership>> consumer)
Unregisters a previously registered change notification listener.If the specified listener was not previously registered, this operation will be a noop.
- Parameters:
consumer
- listener to remove
-
-