public class StaticLeaderElection extends Object implements LeaderElection<String>
LeaderElection.LeadershipStateListener| Constructor and Description |
|---|
StaticLeaderElection() |
| Modifier and Type | Method and Description |
|---|---|
void |
addStateListener(LeaderElection.LeadershipStateListener listener)
Register listeners to get notified when leadership changes.
|
void |
close() |
String |
getName()
Get the name of this leader candidate
|
boolean |
isLeader()
Getting the result of election.
|
void |
setName(String name)
Set the name of this leader candidate
|
void |
tryBeLeader(org.apache.hadoop.conf.Configuration conf,
String hostName)
Place where election happens
|
public void tryBeLeader(org.apache.hadoop.conf.Configuration conf,
String hostName)
throws LeaderException
LeaderElectiontryBeLeader in interface LeaderElection<String>conf - configurationhostName - a global mutex for leader election.
It can be a path in Zookeeper, or a table that going to be locked.LeaderExceptionpublic boolean isLeader()
LeaderElectionisLeader in interface LeaderElection<String>public void addStateListener(LeaderElection.LeadershipStateListener listener)
LeaderElectionaddStateListener in interface LeaderElection<String>listener - The listener to be addedpublic void setName(String name)
LeaderElectionsetName in interface LeaderElection<String>name - the namepublic String getName()
LeaderElectiongetName in interface LeaderElection<String>public void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2024 The Apache Software Foundation. All rights reserved.