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.| 构造器和说明 |
|---|
StandaloneLeaderElectionService() |
| 限定符和类型 | 方法和说明 |
|---|---|
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 在接口中 LeaderElectionServicenewContender - LeaderContender which applies for the leadershipExceptionpublic void stop()
LeaderElectionServicestop 在接口中 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 在接口中 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 在接口中 LeaderElectionServiceleaderSessionId - identifying the current leaderLeaderContender is the leader, otherwise falseCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.