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()
Returns true if the
LeaderContender with which the service has been started owns
currently the leadership. |
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
LeaderElectionService
start
in interface LeaderElectionService
contender
- LeaderContender which applies for the leadershipException
public void stop()
LeaderElectionService
stop
in interface LeaderElectionService
public void confirmLeaderSessionID(UUID leaderSessionID)
LeaderElectionService
LeaderContender
.
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 LeaderElectionService
leaderSessionID
- The new leader session IDpublic boolean hasLeadership()
LeaderElectionService
LeaderContender
with which the service has been started owns
currently the leadership.hasLeadership
in interface LeaderElectionService
LeaderContender
is the leader, otherwise falsepublic boolean isShutdown()
public void shutdown()
public LeaderRetrievalService createLeaderRetrievalService()
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.