public class SingleLeaderElectionService extends Object implements LeaderElectionService
LeaderElectionService interface that handles a single
leader contender. When started, this service immediately grants the contender the leadership.
The implementation accepts a single static leader session ID and is hence compatible with pre-configured single leader (no leader failover) setups.
This implementation supports a series of leader listeners that receive notifications about the leader contender.
| Constructor and Description |
|---|
SingleLeaderElectionService(Executor notificationsDispatcher,
UUID leaderId)
Creates a new leader election service.
|
| Modifier and Type | Method and Description |
|---|---|
void |
confirmLeaderSessionID(UUID leaderSessionID)
Confirms that the new leader session ID has been successfully received by the new leader.
|
LeaderRetrievalService |
createLeaderRetrievalService() |
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. |
boolean |
isShutdown() |
void |
shutdown() |
void |
start(LeaderContender contender)
Starts the leader election service.
|
void |
stop()
Stops the leader election service.
|
public void start(LeaderContender contender) throws Exception
LeaderElectionServicestart in interface LeaderElectionServicecontender - LeaderContender which applies for the leadershipExceptionpublic void stop()
LeaderElectionServicestop in interface LeaderElectionServicepublic void confirmLeaderSessionID(UUID leaderSessionID)
LeaderElectionServiceLeaderContender.
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 to the
leader retrieval services.confirmLeaderSessionID in interface LeaderElectionServiceleaderSessionID - The new leader session IDpublic boolean hasLeadership(@Nonnull UUID leaderSessionId)
LeaderElectionServiceLeaderContender with which the service has been started owns
currently the leadership under the given leader session id.hasLeadership in interface LeaderElectionServiceleaderSessionId - identifying the current leaderLeaderContender is the leader, otherwise falsepublic boolean isShutdown()
public void shutdown()
public LeaderRetrievalService createLeaderRetrievalService()
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.