public class StandaloneLeaderElection extends Object implements LeaderElection
StandaloneLeaderElection implements LeaderElection for non-HA cases. This
implementation can be used for testing, and for cluster setups that do not tolerate failures of
the main components (e.g. ResourceManager or Dispatcher).| Constructor and Description |
|---|
StandaloneLeaderElection(UUID sessionID) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the
LeaderElection by deregistering the LeaderContender from the
underlying leader election. |
CompletableFuture<Void> |
confirmLeadershipAsync(UUID leaderSessionID,
String leaderAddress)
Confirms that the
LeaderContender has accepted the leadership identified by the given
leader session id. |
CompletableFuture<Boolean> |
hasLeadershipAsync(UUID leaderSessionId)
Returns
true if the service's LeaderContender has the leadership under the
given leader session ID acquired. |
void |
startLeaderElection(LeaderContender contender)
Registers the passed
LeaderContender with the leader election process. |
public StandaloneLeaderElection(UUID sessionID)
public void startLeaderElection(LeaderContender contender) throws Exception
LeaderElectionLeaderContender with the leader election process.startLeaderElection in interface LeaderElectionExceptionpublic CompletableFuture<Void> confirmLeadershipAsync(UUID leaderSessionID, String leaderAddress)
LeaderElectionLeaderContender has accepted the leadership identified by the given
leader session id. It also publishes the leader address under which the leader is reachable.
The data is only confirmed if the leadership is still acquired.
The intention of this method is to establish an order between setting the new leader
session ID in the LeaderContender and publishing the new leader session ID and the
related leader address to the leader retrieval services.
confirmLeadershipAsync in interface LeaderElectionleaderSessionID - The new leader session IDleaderAddress - The address of the new leaderpublic CompletableFuture<Boolean> hasLeadershipAsync(UUID leaderSessionId)
LeaderElectiontrue if the service's LeaderContender has the leadership under the
given leader session ID acquired.hasLeadershipAsync in interface LeaderElectionleaderSessionId - identifying the current leaderLeaderContender is the leader, otherwise falsepublic void close()
throws Exception
LeaderElectionLeaderElection by deregistering the LeaderContender from the
underlying leader election. LeaderContender.revokeLeadership() will be called if the
service still holds the leadership.close in interface AutoCloseableclose in interface LeaderElectionExceptionCopyright © 2014–2025 The Apache Software Foundation. All rights reserved.