public class ZooKeeperLeaderElectionService extends Object implements LeaderElectionService, org.apache.flink.shaded.curator4.org.apache.curator.framework.recipes.leader.LeaderLatchListener, org.apache.flink.shaded.curator4.org.apache.curator.framework.recipes.cache.NodeCacheListener, org.apache.flink.shaded.curator4.org.apache.curator.framework.api.UnhandledErrorListener
Constructor and Description |
---|
ZooKeeperLeaderElectionService(org.apache.flink.shaded.curator4.org.apache.curator.framework.CuratorFramework client,
String latchPath,
String leaderPath)
Creates a ZooKeeperLeaderElectionService object.
|
Modifier and Type | Method and Description |
---|---|
void |
confirmLeadership(UUID leaderSessionID,
String leaderAddress)
Confirms that the
LeaderContender has accepted the leadership identified by the given
leader session id. |
UUID |
getLeaderSessionID()
Returns the current leader session ID or null, if the contender is not the leader.
|
protected void |
handleStateChange(org.apache.flink.shaded.curator4.org.apache.curator.framework.state.ConnectionState newState) |
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. |
void |
isLeader() |
void |
nodeChanged() |
void |
notLeader() |
void |
start(LeaderContender contender)
Starts the leader election service.
|
void |
stop()
Stops the leader election service.
|
String |
toString() |
void |
unhandledError(String message,
Throwable e) |
protected void |
writeLeaderInformation()
Writes the current leader's address as well the given leader session ID to ZooKeeper.
|
public ZooKeeperLeaderElectionService(org.apache.flink.shaded.curator4.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
LeaderElectionService
start
in interface LeaderElectionService
contender
- LeaderContender which applies for the leadershipException
public void stop() throws Exception
LeaderElectionService
stop
in interface LeaderElectionService
Exception
public void confirmLeadership(UUID leaderSessionID, String leaderAddress)
LeaderElectionService
LeaderContender
has accepted the leadership identified by the given
leader session id. It also publishes the leader address under which the leader is reachable.
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 as well as
the leader address to the leader retrieval services.
confirmLeadership
in interface LeaderElectionService
leaderSessionID
- The new leader session IDleaderAddress
- The address of the new leaderpublic boolean hasLeadership(@Nonnull UUID leaderSessionId)
LeaderElectionService
LeaderContender
with which the service has been started owns
currently the leadership under the given leader session id.hasLeadership
in interface LeaderElectionService
leaderSessionId
- identifying the current leaderLeaderContender
is the leader, otherwise falsepublic void isLeader()
isLeader
in interface org.apache.flink.shaded.curator4.org.apache.curator.framework.recipes.leader.LeaderLatchListener
public void notLeader()
notLeader
in interface org.apache.flink.shaded.curator4.org.apache.curator.framework.recipes.leader.LeaderLatchListener
public void nodeChanged() throws Exception
nodeChanged
in interface org.apache.flink.shaded.curator4.org.apache.curator.framework.recipes.cache.NodeCacheListener
Exception
protected void writeLeaderInformation()
protected void handleStateChange(org.apache.flink.shaded.curator4.org.apache.curator.framework.state.ConnectionState newState)
public void unhandledError(String message, Throwable e)
unhandledError
in interface org.apache.flink.shaded.curator4.org.apache.curator.framework.api.UnhandledErrorListener
Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.