Class DefaultLeaderElectionService
- java.lang.Object
-
- org.apache.flink.runtime.leaderelection.DefaultLeaderElectionService
-
- All Implemented Interfaces:
AutoCloseable,LeaderElectionDriver.Listener,LeaderElectionService
public class DefaultLeaderElectionService extends Object implements LeaderElectionService, LeaderElectionDriver.Listener, AutoCloseable
Default implementation for leader election service. Composed with differentLeaderElectionDriver, we could perform a leader election for the contender, and then persist the leader information to various storage.DefaultLeaderElectionServicehandles a singleLeaderContender.
-
-
Constructor Summary
Constructors Constructor Description DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory)DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory, org.apache.flink.runtime.rpc.FatalErrorHandler fallbackErrorHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voidconfirmLeadership(String componentId, UUID leaderSessionID, String leaderAddress)LeaderElectioncreateLeaderElection(String componentId)Creates a newLeaderElectioninstance that is registered to thisLeaderElectionServiceinstance.UUIDgetLeaderSessionID(String componentId)Returns the current leader session ID for the givencomponentIdornull, if the session wasn't confirmed.protected booleanhasLeadership(String componentId, UUID leaderSessionId)voidonError(Throwable t)Notifies the listener if an error occurred.voidonGrantLeadership(UUID leaderSessionID)Callback that is called once the driver obtains the leadership.voidonLeaderInformationChange(String componentId, LeaderInformation leaderInformation)Notifies the listener about a changed leader information for the given component.voidonLeaderInformationChange(LeaderInformationRegister changedLeaderInformation)Notifies the listener about all currently known leader information.voidonRevokeLeadership()Callback that is called once the driver loses the leadership.protected voidregister(String componentId, LeaderContender contender)protected voidremove(String componentId)
-
-
-
Constructor Detail
-
DefaultLeaderElectionService
public DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory)
-
DefaultLeaderElectionService
@VisibleForTesting public DefaultLeaderElectionService(LeaderElectionDriverFactory leaderElectionDriverFactory, org.apache.flink.runtime.rpc.FatalErrorHandler fallbackErrorHandler)
-
-
Method Detail
-
createLeaderElection
public LeaderElection createLeaderElection(String componentId)
Description copied from interface:LeaderElectionServiceCreates a newLeaderElectioninstance that is registered to thisLeaderElectionServiceinstance.- Specified by:
createLeaderElectionin interfaceLeaderElectionService- Parameters:
componentId- a unique identifier that refers to the stored leader information that the newly createdLeaderElectionmanages.
-
register
protected void register(String componentId, LeaderContender contender) throws Exception
- Throws:
Exception
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
confirmLeadership
protected void confirmLeadership(String componentId, UUID leaderSessionID, String leaderAddress)
-
getLeaderSessionID
@VisibleForTesting @Nullable public UUID getLeaderSessionID(String componentId)
Returns the current leader session ID for the givencomponentIdornull, if the session wasn't confirmed.
-
onGrantLeadership
public void onGrantLeadership(UUID leaderSessionID)
Description copied from interface:LeaderElectionDriver.ListenerCallback that is called once the driver obtains the leadership.- Specified by:
onGrantLeadershipin interfaceLeaderElectionDriver.Listener
-
onRevokeLeadership
public void onRevokeLeadership()
Description copied from interface:LeaderElectionDriver.ListenerCallback that is called once the driver loses the leadership.- Specified by:
onRevokeLeadershipin interfaceLeaderElectionDriver.Listener
-
onLeaderInformationChange
public void onLeaderInformationChange(String componentId, LeaderInformation leaderInformation)
Description copied from interface:LeaderElectionDriver.ListenerNotifies the listener about a changed leader information for the given component.- Specified by:
onLeaderInformationChangein interfaceLeaderElectionDriver.Listener- Parameters:
componentId- identifying the component whose leader information has changedleaderInformation- new leader information
-
onLeaderInformationChange
public void onLeaderInformationChange(LeaderInformationRegister changedLeaderInformation)
Description copied from interface:LeaderElectionDriver.ListenerNotifies the listener about all currently known leader information.- Specified by:
onLeaderInformationChangein interfaceLeaderElectionDriver.Listener
-
onError
public void onError(Throwable t)
Description copied from interface:LeaderElectionDriver.ListenerNotifies the listener if an error occurred.- Specified by:
onErrorin interfaceLeaderElectionDriver.Listener
-
-