Class StandaloneLeaderElection
- java.lang.Object
-
- org.apache.flink.runtime.leaderelection.StandaloneLeaderElection
-
- All Implemented Interfaces:
AutoCloseable,LeaderElection
public class StandaloneLeaderElection extends Object implements LeaderElection
StandaloneLeaderElectionimplementsLeaderElectionfor 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 Summary
Constructors Constructor Description StandaloneLeaderElection(UUID sessionID)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes theLeaderElectionby deregistering theLeaderContenderfrom the underlying leader election.CompletableFuture<Void>confirmLeadershipAsync(UUID leaderSessionID, String leaderAddress)Confirms that theLeaderContenderhas accepted the leadership identified by the given leader session id.CompletableFuture<Boolean>hasLeadershipAsync(UUID leaderSessionId)Returnstrueif the service'sLeaderContenderhas the leadership under the given leader session ID acquired.voidstartLeaderElection(LeaderContender contender)Registers the passedLeaderContenderwith the leader election process.
-
-
-
Constructor Detail
-
StandaloneLeaderElection
public StandaloneLeaderElection(UUID sessionID)
-
-
Method Detail
-
startLeaderElection
public void startLeaderElection(LeaderContender contender) throws Exception
Description copied from interface:LeaderElectionRegisters the passedLeaderContenderwith the leader election process.- Specified by:
startLeaderElectionin interfaceLeaderElection- Throws:
Exception
-
confirmLeadershipAsync
public CompletableFuture<Void> confirmLeadershipAsync(UUID leaderSessionID, String leaderAddress)
Description copied from interface:LeaderElectionConfirms that theLeaderContenderhas 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
LeaderContenderand publishing the new leader session ID and the related leader address to the leader retrieval services.- Specified by:
confirmLeadershipAsyncin interfaceLeaderElection- Parameters:
leaderSessionID- The new leader session IDleaderAddress- The address of the new leader
-
hasLeadershipAsync
public CompletableFuture<Boolean> hasLeadershipAsync(UUID leaderSessionId)
Description copied from interface:LeaderElectionReturnstrueif the service'sLeaderContenderhas the leadership under the given leader session ID acquired.- Specified by:
hasLeadershipAsyncin interfaceLeaderElection- Parameters:
leaderSessionId- identifying the current leader- Returns:
- true if the associated
LeaderContenderis the leader, otherwise false
-
close
public void close() throws ExceptionDescription copied from interface:LeaderElectionCloses theLeaderElectionby deregistering theLeaderContenderfrom the underlying leader election.LeaderContender.revokeLeadership()will be called if the service still holds the leadership.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLeaderElection- Throws:
Exception
-
-