Interface LeaderElection<T>
- All Superinterfaces:
AutoCloseable
Leader election controller.
-
Method Summary
Modifier and TypeMethodDescriptionClose the leader election controller and release the leadership (if it was acquired).Try to become the leader.Get the value set by the elected leader, or empty if there's currently no leader.Get the value set by the elected leader, or empty if there's currently no leader.getState()Get the current leader election state.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
elect
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
LeaderElectionState 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
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
-