Class StandaloneLeaderElection
- java.lang.Object
-
- org.apache.flink.runtime.leaderelection.StandaloneLeaderElection
-
- All Implemented Interfaces:
AutoCloseable
,LeaderElection
public class StandaloneLeaderElection extends Object implements LeaderElection
StandaloneLeaderElection
implementsLeaderElection
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 Summary
Constructors Constructor Description StandaloneLeaderElection(UUID sessionID)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes theLeaderElection
by deregistering theLeaderContender
from the underlying leader election.CompletableFuture<Void>
confirmLeadershipAsync(UUID leaderSessionID, String leaderAddress)
Confirms that theLeaderContender
has accepted the leadership identified by the given leader session id.CompletableFuture<Boolean>
hasLeadershipAsync(UUID leaderSessionId)
Returnstrue
if the service'sLeaderContender
has the leadership under the given leader session ID acquired.void
startLeaderElection(LeaderContender contender)
Registers the passedLeaderContender
with 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:LeaderElection
Registers the passedLeaderContender
with the leader election process.- Specified by:
startLeaderElection
in interfaceLeaderElection
- Throws:
Exception
-
confirmLeadershipAsync
public CompletableFuture<Void> confirmLeadershipAsync(UUID leaderSessionID, String leaderAddress)
Description copied from interface:LeaderElection
Confirms that theLeaderContender
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.- Specified by:
confirmLeadershipAsync
in 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:LeaderElection
Returnstrue
if the service'sLeaderContender
has the leadership under the given leader session ID acquired.- Specified by:
hasLeadershipAsync
in interfaceLeaderElection
- Parameters:
leaderSessionId
- identifying the current leader- Returns:
- true if the associated
LeaderContender
is the leader, otherwise false
-
close
public void close() throws Exception
Description copied from interface:LeaderElection
Closes theLeaderElection
by deregistering theLeaderContender
from the underlying leader election.LeaderContender.revokeLeadership()
will be called if the service still holds the leadership.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceLeaderElection
- Throws:
Exception
-
-