public class DefaultLeaderElectionService extends Object implements LeaderElectionService, LeaderElectionDriver.Listener, AutoCloseable
LeaderElectionDriver, we could perform a leader election for the contender, and then persist the
leader information to various storage.
DefaultLeaderElectionService handles a single LeaderContender.
| 构造器和说明 |
|---|
DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory) |
DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory,
org.apache.flink.runtime.rpc.FatalErrorHandler fallbackErrorHandler) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
protected void |
confirmLeadership(String componentId,
UUID leaderSessionID,
String leaderAddress)
Confirms the leadership with the
leaderSessionID and leaderAddress for
the LeaderContender that is associated with the componentId. |
LeaderElection |
createLeaderElection(String componentId)
Creates a new
LeaderElection instance that is registered to this LeaderElectionService instance. |
UUID |
getLeaderSessionID(String componentId)
Returns the current leader session ID for the given
componentId or null, if
the session wasn't confirmed. |
protected boolean |
hasLeadership(String componentId,
UUID leaderSessionId)
Checks whether the
ParentService has the leadership acquired for the componentId and leaderSessionID. |
void |
onError(Throwable t)
Notifies the listener if an error occurred.
|
void |
onGrantLeadership(UUID leaderSessionID)
Callback that is called once the driver obtains the leadership.
|
void |
onLeaderInformationChange(LeaderInformationRegister changedLeaderInformation)
Notifies the listener about all currently known leader information.
|
void |
onLeaderInformationChange(String componentId,
LeaderInformation leaderInformation)
Notifies the listener about a changed leader information for the given component.
|
void |
onRevokeLeadership()
Callback that is called once the driver loses the leadership.
|
protected void |
register(String componentId,
LeaderContender contender)
|
protected void |
remove(String componentId)
Removes the
LeaderContender from the ParentService that is associated
with the componentId. |
public DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory)
@VisibleForTesting public DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory, org.apache.flink.runtime.rpc.FatalErrorHandler fallbackErrorHandler)
public LeaderElection createLeaderElection(String componentId)
LeaderElectionServiceLeaderElection instance that is registered to this LeaderElectionService instance.createLeaderElection 在接口中 LeaderElectionServicecomponentId - a unique identifier that refers to the stored leader information that the
newly created LeaderElection manages.protected void register(String componentId, LeaderContender contender) throws Exception
LeaderContender under the componentId with the underlying
ParentService. Leadership changes are starting to be reported to the LeaderContender.Exceptionprotected final void remove(String componentId) throws Exception
LeaderContender from the ParentService that is associated
with the componentId.Exceptionpublic void close()
throws Exception
close 在接口中 AutoCloseableExceptionprotected void confirmLeadership(String componentId, UUID leaderSessionID, String leaderAddress)
leaderSessionID and leaderAddress for
the LeaderContender that is associated with the componentId.protected boolean hasLeadership(String componentId, UUID leaderSessionId)
ParentService has the leadership acquired for the componentId and leaderSessionID.true if the service has leadership with the passed leaderSessionID acquired; false otherwise.@VisibleForTesting @Nullable public UUID getLeaderSessionID(String componentId)
componentId or null, if
the session wasn't confirmed.public void onGrantLeadership(UUID leaderSessionID)
LeaderElectionDriver.Listenerpublic void onRevokeLeadership()
LeaderElectionDriver.Listenerpublic void onLeaderInformationChange(String componentId, LeaderInformation leaderInformation)
LeaderElectionDriver.ListeneronLeaderInformationChange 在接口中 LeaderElectionDriver.ListenercomponentId - identifying the component whose leader information has changedleaderInformation - new leader informationpublic void onLeaderInformationChange(LeaderInformationRegister changedLeaderInformation)
LeaderElectionDriver.Listenerpublic void onError(Throwable t)
LeaderElectionDriver.ListeneronError 在接口中 LeaderElectionDriver.ListenerCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.