public class DefaultLeaderElectionService extends Object implements LeaderElectionService, LeaderElectionEventHandler
LeaderElectionDriver, we could perform a leader election for the contender, and then persist the
leader information to various storage.| 构造器和说明 |
|---|
DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
confirmLeadership(UUID leaderSessionID,
String leaderAddress)
Confirms that the
LeaderContender has accepted the leadership identified by the given
leader session id. |
UUID |
getLeaderSessionID()
Returns the current leader session ID or null, if the contender is not the leader.
|
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 |
onGrantLeadership(UUID newLeaderSessionId)
Called by specific
LeaderElectionDriver when the leadership is granted. |
void |
onLeaderInformationChange(LeaderInformation leaderInformation)
Called by specific
LeaderElectionDriver when the leader information is changed. |
void |
onRevokeLeadership()
Called by specific
LeaderElectionDriver when the leadership is revoked. |
void |
start(LeaderContender contender)
Starts the leader election service.
|
void |
stop()
Stops the leader election service.
|
public DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory)
public final void start(LeaderContender contender) throws Exception
LeaderElectionServicestart 在接口中 LeaderElectionServicecontender - LeaderContender which applies for the leadershipExceptionpublic final void stop()
throws Exception
LeaderElectionServicestop 在接口中 LeaderElectionServiceExceptionpublic 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 false@VisibleForTesting @Nullable public UUID getLeaderSessionID()
public void onGrantLeadership(UUID newLeaderSessionId)
LeaderElectionEventHandlerLeaderElectionDriver when the leadership is granted.onGrantLeadership 在接口中 LeaderElectionEventHandlernewLeaderSessionId - the valid leader session idpublic void onRevokeLeadership()
LeaderElectionEventHandlerLeaderElectionDriver when the leadership is revoked.onRevokeLeadership 在接口中 LeaderElectionEventHandlerpublic void onLeaderInformationChange(LeaderInformation leaderInformation)
LeaderElectionEventHandlerLeaderElectionDriver when the leader information is changed. Then
the LeaderElectionService could write the leader information again if necessary. This
method should only be called when LeaderElectionDriver.hasLeadership() is true.
Duplicated leader change events could happen, so the implementation should check whether the
passed leader information is really different with internal confirmed leader information.onLeaderInformationChange 在接口中 LeaderElectionEventHandlerleaderInformation - leader information which contains leader session id and leader
address.Copyright © 2014–2022 The Apache Software Foundation. All rights reserved.