Interface LeaderElection<T>

All Superinterfaces:
AutoCloseable

public interface LeaderElection<T> extends AutoCloseable
Leader election controller.
  • Method Details

    • elect

      CompletableFuture<LeaderElectionState> elect(T proposedValue)
      Try to become the leader.

      Warning: because of the distributed nature of the leader election, having been promoted to "leader" status will never provide a strong guarantee that no one else also thinks it's the leader. The caller will have to deal with these race conditions when using the resource itself (eg. using compareAndSet() or fencing mechanisms).

      Parameters:
      proposedValue - the value to set for the leader, in the case this instance succeeds in becoming leader
      Returns:
      a future that will track the completion of the operation if there's a failure in the leader election
    • getState

      Get the current leader election state.
    • getLeaderValue

      CompletableFuture<Optional<T>> getLeaderValue()
      Get the value set by the elected leader, or empty if there's currently no leader.
      Returns:
      a future that will track the completion of the operation
    • getLeaderValueIfPresent

      Optional<T> getLeaderValueIfPresent()
      Get the value set by the elected leader, or empty if there's currently no leader.

      The call is non blocking and in certain cases can return Optional.empty() even though a leader is technically elected.

      Returns:
      a future that will track the completion of the operation
    • asyncClose

      CompletableFuture<Void> asyncClose()
      Close the leader election controller and release the leadership (if it was acquired).
      Returns:
      a future that will track the completion of the operation