public class ZooKeeperLeaderElectionService extends Object implements LeaderElectionService, org.apache.curator.framework.recipes.leader.LeaderLatchListener, org.apache.curator.framework.recipes.cache.NodeCacheListener
| Constructor and Description |
|---|
ZooKeeperLeaderElectionService(org.apache.curator.framework.CuratorFramework client,
String latchPath,
String leaderPath)
Creates a ZooKeeperLeaderElectionService object.
|
| 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.
|
UUID |
getLeaderSessionID()
Returns the current leader session ID or null, if the contender is not the leader.
|
protected void |
handleStateChange(org.apache.curator.framework.state.ConnectionState newState) |
boolean |
hasLeadership()
Returns true if the
LeaderContender with which the service has been started owns
currently the leadership. |
void |
isLeader() |
void |
nodeChanged() |
void |
notLeader() |
void |
start(LeaderContender contender)
Starts the leader election service.
|
void |
stop()
Stops the leader election service.
|
protected void |
writeLeaderInformation(UUID leaderSessionID)
Writes the current leader's address as well the given leader session ID to ZooKeeper.
|
public ZooKeeperLeaderElectionService(org.apache.curator.framework.CuratorFramework client,
String latchPath,
String leaderPath)
client - Client which is connected to the ZooKeeper quorumlatchPath - ZooKeeper node path for the leader election latchleaderPath - ZooKeeper node path for the node which stores the current leader informationpublic UUID getLeaderSessionID()
public void start(LeaderContender contender) throws Exception
LeaderElectionServicestart in interface LeaderElectionServicecontender - LeaderContender which applies for the leadershipExceptionpublic void stop()
throws Exception
LeaderElectionServicestop in interface LeaderElectionServiceExceptionpublic 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()
LeaderElectionServiceLeaderContender with which the service has been started owns
currently the leadership.hasLeadership in interface LeaderElectionServiceLeaderContender is the leader, otherwise falsepublic void isLeader()
isLeader in interface org.apache.curator.framework.recipes.leader.LeaderLatchListenerpublic void notLeader()
notLeader in interface org.apache.curator.framework.recipes.leader.LeaderLatchListenerpublic void nodeChanged()
throws Exception
nodeChanged in interface org.apache.curator.framework.recipes.cache.NodeCacheListenerExceptionprotected void writeLeaderInformation(UUID leaderSessionID)
leaderSessionID - Leader session ID which is written to ZooKeeperprotected void handleStateChange(org.apache.curator.framework.state.ConnectionState newState)
Copyright © 2014–2016 The Apache Software Foundation. All rights reserved.