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 Detail

      • getLeader

        default NodeId getLeader​(java.lang.String topic)
        Returns the node 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 current leadership 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 specified node.
        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
      • getCandidates

        default java.util.List<NodeId> getCandidates​(java.lang.String topic)
        Returns the candidate nodes for a given topic.
        Parameters:
        topic - leadership topic
        Returns:
        A lists of nodeIds, which may be empty.