Class DefaultLeaderElector

    • Constructor Detail

      • DefaultLeaderElector

        public DefaultLeaderElector​(AsyncLeaderElector asyncElector,
                                    long operationTimeoutMillis)
    • Method Detail

      • run

        public Leadership run​(java.lang.String topic,
                              NodeId nodeId)
        Description copied from interface: LeaderElector
        Attempts to become leader for a topic.
        Specified by:
        run in interface LeaderElector
        Parameters:
        topic - leadership topic
        nodeId - instance identifier of the node
        Returns:
        current Leadership state of the topic
      • withdraw

        public void withdraw​(java.lang.String topic)
        Description copied from interface: LeaderElector
        Withdraws from leadership race for a topic.
        Specified by:
        withdraw in interface LeaderElector
        Parameters:
        topic - leadership topic
      • anoint

        public boolean anoint​(java.lang.String topic,
                              NodeId nodeId)
        Description copied from interface: LeaderElector
        Attempts to promote a node to leadership displacing the current leader.
        Specified by:
        anoint in interface LeaderElector
        Parameters:
        topic - leadership topic
        nodeId - instance identifier of the new leader
        Returns:
        true 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.
      • promote

        public boolean promote​(java.lang.String topic,
                               NodeId nodeId)
        Description copied from interface: LeaderElector
        Attempts to promote a node to top of candidate list.
        Specified by:
        promote in interface LeaderElector
        Parameters:
        topic - leadership topic
        nodeId - instance identifier of the new top candidate
        Returns:
        true 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.
      • evict

        public void evict​(NodeId nodeId)
        Description copied from interface: LeaderElector
        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.

        Specified by:
        evict in interface LeaderElector
        Parameters:
        nodeId - node instance identifier
      • getLeadership

        public Leadership getLeadership​(java.lang.String topic)
        Description copied from interface: LeaderElector
        Returns the Leadership for the specified topic.
        Specified by:
        getLeadership in interface LeaderElector
        Parameters:
        topic - leadership topic
        Returns:
        current Leadership state of the topic
      • addChangeListener

        public void addChangeListener​(java.util.function.Consumer<Change<Leadership>> consumer)
        Description copied from interface: LeaderElector
        Registers a listener to be notified of Leadership changes for all topics.
        Specified by:
        addChangeListener in interface LeaderElector
        Parameters:
        consumer - listener to add
      • removeChangeListener

        public void removeChangeListener​(java.util.function.Consumer<Change<Leadership>> consumer)
        Description copied from interface: LeaderElector
        Unregisters a previously registered change notification listener.

        If the specified listener was not previously registered, this operation will be a noop.

        Specified by:
        removeChangeListener in interface LeaderElector
        Parameters:
        consumer - listener to remove