public interface LeadershipService extends ListenerService<LeadershipEvent,LeadershipEventListener>
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.
| Modifier and Type | Method and Description |
|---|---|
default List<NodeId> |
getCandidates(String topic)
Returns the candidate nodes for a given topic.
|
default NodeId |
getLeader(String topic)
Returns the
node identifier that is the current leader for a topic. |
Leadership |
getLeadership(String topic)
Returns the current
leadership for a topic. |
Set<String> |
ownedTopics(NodeId nodeId)
Returns the set of topics owned by the specified
node. |
Leadership |
runForLeadership(String topic)
Enters a leadership contest.
|
void |
withdraw(String topic)
Withdraws from a leadership contest.
|
addListener, removeListenerdefault NodeId getLeader(String topic)
node identifier that is the current leader for a topic.topic - leadership topicnull if there is no leader for the topicLeadership getLeadership(String topic)
leadership for a topic.topic - leadership topicnull if no such topic existsSet<String> ownedTopics(NodeId nodeId)
node.nodeId - node identifier.Leadership runForLeadership(String topic)
topic - leadership topicLeadership futurevoid withdraw(String topic)
topic - leadership topic