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. |
void |
confirmLeadership(UUID leaderSessionID,
String leaderAddress)
Confirms that the
LeaderContender has accepted the leadership identified by the given
leader session id. |
boolean |
hasLeadership(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
LeaderElection
LeaderContender
with the leader election process.startLeaderElection
in interface LeaderElection
Exception
public void confirmLeadership(UUID leaderSessionID, String leaderAddress)
LeaderElection
LeaderContender
has accepted the leadership identified by the given
leader session id. It also publishes the leader address under which the leader is reachable.
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.
confirmLeadership
in interface LeaderElection
leaderSessionID
- The new leader session IDleaderAddress
- The address of the new leaderpublic boolean hasLeadership(UUID leaderSessionId)
LeaderElection
true
if the service's LeaderContender
has the leadership under the
given leader session ID acquired.hasLeadership
in interface LeaderElection
leaderSessionId
- identifying the current leaderLeaderContender
is the leader, otherwise falsepublic void close() throws Exception
LeaderElection
LeaderElection
by deregistering the LeaderContender
from the
underlying leader election. LeaderContender.revokeLeadership()
will be called if the
service still holds the leadership.close
in interface AutoCloseable
close
in interface LeaderElection
Exception
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.