public class StandaloneLeaderElectionService extends Object implements LeaderElectionService
LeaderElectionService interface. The standalone
implementation assumes that there is only a single LeaderContender and thus directly
grants him the leadership upon start up. Furthermore, there is no communication needed between
multiple standalone leader election services.| Constructor and Description |
|---|
StandaloneLeaderElectionService() |
| Modifier and Type | Method and Description |
|---|---|
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
LeaderContender with which the service has been started owns
currently the leadership under the given leader session id. |
void |
start(LeaderContender newContender)
Starts the leader election service.
|
void |
stop()
Stops the leader election service.
|
public void start(LeaderContender newContender) throws Exception
LeaderElectionServicestart in interface LeaderElectionServicenewContender - LeaderContender which applies for the leadershipExceptionpublic void stop()
LeaderElectionServicestop in interface LeaderElectionServicepublic void confirmLeadership(UUID leaderSessionID, String leaderAddress)
LeaderElectionServiceLeaderContender has accepted the leadership identified by the
given leader session id. It also publishes the leader address under which the leader is
reachable.
The rational behind this method is to establish an order between setting the new leader
session ID in the LeaderContender and publishing the new leader session ID as well
as the leader address to the leader retrieval services.
confirmLeadership in interface LeaderElectionServiceleaderSessionID - The new leader session IDleaderAddress - The address of the new leaderpublic boolean hasLeadership(@Nonnull UUID leaderSessionId)
LeaderElectionServiceLeaderContender with which the service has been started owns
currently the leadership under the given leader session id.hasLeadership in interface LeaderElectionServiceleaderSessionId - identifying the current leaderLeaderContender is the leader, otherwise falseCopyright © 2014–2020 The Apache Software Foundation. All rights reserved.