Package org.onosproject.cluster
Interface LeadershipService
-
- All Superinterfaces:
ListenerService<LeadershipEvent,LeadershipEventListener>
public interface LeadershipService extends ListenerService<LeadershipEvent,LeadershipEventListener>
Service for leader election.Leadership contests are organized around topics. A instance can join the leadership race for a topic or withdraw from a race it has previously joined.
Listeners can be added to receive notifications asynchronously for various leadership contests.
When a node gets elected as a leader for a topic, all nodes receive notifications indicating a change in leadership.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.List<NodeId>
getCandidates(java.lang.String topic)
Returns the candidate nodes for a given topic.default NodeId
getLeader(java.lang.String topic)
Returns thenode identifier
that is the current leader for a topic.Leadership
getLeadership(java.lang.String topic)
Returns the currentleadership
for a topic.java.util.Set<java.lang.String>
ownedTopics(NodeId nodeId)
Returns the set of topics owned by the specifiednode
.Leadership
runForLeadership(java.lang.String topic)
Enters a leadership contest.void
withdraw(java.lang.String topic)
Withdraws from a leadership contest.-
Methods inherited from interface org.onosproject.event.ListenerService
addListener, removeListener
-
-
-
-
Method Detail
-
getLeader
default NodeId getLeader(java.lang.String topic)
Returns thenode identifier
that is the current leader for a topic.- Parameters:
topic
- leadership topic- Returns:
- node identifier of the current leader;
null
if there is no leader for the topic
-
getLeadership
Leadership getLeadership(java.lang.String topic)
Returns the currentleadership
for a topic.- Parameters:
topic
- leadership topic- Returns:
- leadership or
null
if no such topic exists
-
ownedTopics
java.util.Set<java.lang.String> ownedTopics(NodeId nodeId)
Returns the set of topics owned by the specifiednode
.- Parameters:
nodeId
- node identifier.- Returns:
- set of topics for which this node is the current leader.
-
runForLeadership
Leadership runForLeadership(java.lang.String topic)
Enters a leadership contest.- Parameters:
topic
- leadership topic- Returns:
Leadership
future
-
withdraw
void withdraw(java.lang.String topic)
Withdraws from a leadership contest.- Parameters:
topic
- leadership topic
-
-