|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.curator.framework.recipes.leader.LeaderSelector
public class LeaderSelector
Abstraction to select a "leader" amongst multiple contenders in a group of JMVs connected to a Zookeeper cluster. If a group of N thread/processes contends for leadership, one will be assigned leader until it releases leadership at which time another one from the group will be chosen.
Note that this class uses an underlying InterProcessMutex and as a result leader
election is "fair" - each user will become leader in the order originally requested
(from ZK's point of view).
| Constructor Summary | |
|---|---|
LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
org.apache.curator.utils.CloseableExecutorService executorService,
LeaderSelectorListener listener)
|
|
LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
ExecutorService executorService,
LeaderSelectorListener listener)
|
|
LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
LeaderSelectorListener listener)
|
|
LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
ThreadFactory threadFactory,
Executor executor,
LeaderSelectorListener listener)
Deprecated. This constructor was poorly thought out. Custom executor is useless. Use this version instead: LeaderSelector(CuratorFramework, String, ExecutorService, LeaderSelectorListener) |
|
| Method Summary | |
|---|---|
void |
autoRequeue()
By default, when LeaderSelectorListener.takeLeadership(CuratorFramework) returns, this
instance is not requeued. |
void |
close()
Shutdown this selector and remove yourself from the leadership group |
String |
getId()
Return the ID that was set via setId(String) |
Participant |
getLeader()
Return the id for the current leader. |
Collection<Participant> |
getParticipants()
Returns the set of current participants in the leader selection |
boolean |
hasLeadership()
Return true if leadership is currently held by this instance |
boolean |
internalRequeue()
|
void |
interruptLeadership()
Attempt to cancel and interrupt the current leadership if this instance has leadership |
boolean |
requeue()
Re-queue an attempt for leadership. |
void |
setId(String id)
Sets the ID to store for this leader. |
void |
start()
Attempt leadership. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
LeaderSelectorListener listener)
client - the clientleaderPath - the path for this leadership grouplistener - listener
@Deprecated
public LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
ThreadFactory threadFactory,
Executor executor,
LeaderSelectorListener listener)
LeaderSelector(CuratorFramework, String, ExecutorService, LeaderSelectorListener)
client - the clientleaderPath - the path for this leadership groupthreadFactory - factory to use for making internal threadsexecutor - the executor to run inlistener - listener
public LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
ExecutorService executorService,
LeaderSelectorListener listener)
client - the clientleaderPath - the path for this leadership groupexecutorService - thread pool to uselistener - listener
public LeaderSelector(org.apache.curator.framework.CuratorFramework client,
String leaderPath,
org.apache.curator.utils.CloseableExecutorService executorService,
LeaderSelectorListener listener)
client - the clientleaderPath - the path for this leadership groupexecutorService - thread pool to uselistener - listener| Method Detail |
|---|
public void autoRequeue()
LeaderSelectorListener.takeLeadership(CuratorFramework) returns, this
instance is not requeued. Calling this method puts the leader selector into a mode where it
will always requeue itself.
public void setId(String id)
getParticipants() is called. IMPORTANT: must be called
prior to start() to have effect.
id - IDpublic String getId()
setId(String)
public void start()
requeue() for this purpose.
public boolean requeue()
public boolean internalRequeue()
public void close()
close in interface Closeable
public Collection<Participant> getParticipants()
throws Exception
Returns the set of current participants in the leader selection
NOTE - this method polls the ZK server. Therefore it can possibly
return a value that does not match hasLeadership() as hasLeadership
uses a local field of the class.
Exception - ZK errors, interruptions, etc.
public Participant getLeader()
throws Exception
Return the id for the current leader. If for some reason there is no current leader, a dummy participant is returned.
NOTE - this method polls the ZK server. Therefore it can possibly
return a value that does not match hasLeadership() as hasLeadership
uses a local field of the class.
Exception - ZK errors, interruptions, etc.public boolean hasLeadership()
public void interruptLeadership()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||