public class DefaultMultipleComponentLeaderElectionService extends Object implements MultipleComponentLeaderElectionService, MultipleComponentLeaderElectionDriver.Listener
MultipleComponentLeaderElectionService
that allows to
register multiple LeaderElectionEventHandler
.Constructor and Description |
---|
DefaultMultipleComponentLeaderElectionService(FatalErrorHandler fatalErrorHandler,
MultipleComponentLeaderElectionDriverFactory multipleComponentLeaderElectionDriverFactory) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this service.
|
LeaderElectionDriverFactory |
createDriverFactory(String componentId)
Creates a
LeaderElectionDriverFactory for the given leader name. |
boolean |
hasLeadership(String componentId)
Returns whether the given component has leadership.
|
void |
isLeader()
Callback that is called once the driver obtains the leadership.
|
void |
notifyAllKnownLeaderInformation(Collection<LeaderInformationWithComponentId> leaderInformationWithComponentIds)
Notifies the listener about all currently known leader information.
|
void |
notifyLeaderInformationChange(String componentId,
LeaderInformation leaderInformation)
Notifies the listener about a changed leader information for the given component.
|
void |
notLeader()
Callback that is called once the driver loses the leadership.
|
void |
publishLeaderInformation(String componentId,
LeaderInformation leaderInformation)
Publishes the given leader information for the component identified by the given leader name.
|
void |
registerLeaderElectionEventHandler(String componentId,
LeaderElectionEventHandler leaderElectionEventHandler)
Registers a new leader election event handler under the given component id.
|
void |
unregisterLeaderElectionEventHandler(String componentId)
Unregisters the leader election event handler with the given component id.
|
public DefaultMultipleComponentLeaderElectionService(FatalErrorHandler fatalErrorHandler, MultipleComponentLeaderElectionDriverFactory multipleComponentLeaderElectionDriverFactory) throws Exception
Exception
public void close() throws Exception
MultipleComponentLeaderElectionService
close
in interface MultipleComponentLeaderElectionService
Exception
- if the service failed to closepublic LeaderElectionDriverFactory createDriverFactory(String componentId)
MultipleComponentLeaderElectionService
LeaderElectionDriverFactory
for the given leader name.createDriverFactory
in interface MultipleComponentLeaderElectionService
componentId
- identifying the component for which to create a leader election driver
factorypublic void publishLeaderInformation(String componentId, LeaderInformation leaderInformation)
MultipleComponentLeaderElectionService
publishLeaderInformation
in interface MultipleComponentLeaderElectionService
componentId
- identifying the componentleaderInformation
- leader informationpublic void registerLeaderElectionEventHandler(String componentId, LeaderElectionEventHandler leaderElectionEventHandler)
MultipleComponentLeaderElectionService
registerLeaderElectionEventHandler
in interface MultipleComponentLeaderElectionService
componentId
- identifying the leader election event handlerleaderElectionEventHandler
- leader election event handler to registerpublic void unregisterLeaderElectionEventHandler(String componentId) throws Exception
MultipleComponentLeaderElectionService
unregisterLeaderElectionEventHandler
in interface MultipleComponentLeaderElectionService
componentId
- identifying the componentException
- if the leader election event handler could not be unregisteredpublic boolean hasLeadership(String componentId)
MultipleComponentLeaderElectionService
hasLeadership
in interface MultipleComponentLeaderElectionService
componentId
- identifying the componenttrue
if the component has leadership otherwise false
public void isLeader()
MultipleComponentLeaderElectionDriver.Listener
isLeader
in interface MultipleComponentLeaderElectionDriver.Listener
public void notLeader()
MultipleComponentLeaderElectionDriver.Listener
notLeader
in interface MultipleComponentLeaderElectionDriver.Listener
public void notifyLeaderInformationChange(String componentId, LeaderInformation leaderInformation)
MultipleComponentLeaderElectionDriver.Listener
notifyLeaderInformationChange
in interface MultipleComponentLeaderElectionDriver.Listener
componentId
- identifying the component whose leader information has changedleaderInformation
- new leader informationpublic void notifyAllKnownLeaderInformation(Collection<LeaderInformationWithComponentId> leaderInformationWithComponentIds)
MultipleComponentLeaderElectionDriver.Listener
notifyAllKnownLeaderInformation
in interface MultipleComponentLeaderElectionDriver.Listener
leaderInformationWithComponentIds
- leader information with component idsCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.