-
Notifications
You must be signed in to change notification settings - Fork 435
Leader Election
In distributed computing, leader election is the process of designating a single process as the organizer of some task distributed among several computers (nodes). Before the task is begun, all network nodes are unaware which node will serve as the "leader," or coordinator, of the task. After a leader election algorithm has been run, however, each node throughout the network recognizes a particular, unique node as the task leader.
- LeaderSelector
- LeaderSelectorListener
public LeaderSelector(CuratorFramework client,
String mutexPath,
LeaderSelectorListener listener)
Parameters:
client - the client
mutexPath - the path for this leadership group
listener - listener
public LeaderSelector(CuratorFramework client,
String mutexPath,
ThreadFactory threadFactory,
Executor executor,
LeaderSelectorListener listener)
Parameters:
client - the client
mutexPath - the path for this leadership group
threadFactory - factory to use for making internal threads
executor - the executor to run in
listener - listener
LeaderSelectors must be started:
leaderSelector.start();
Once started, the takeLeadership()
of your listener will be called when you have leadership. Your takeLeadership()
method should only return when leadership is being relinquished.
When you are through with the LeaderSelector instance, you should call close:
leaderSelector.close();
The LeaderSelectorListener
class extends ConnectionStateListener
. When the LeaderSelector is started, it adds the listener to the Curator instance. Users of the LeaderSelector
must pay attention to any connection state changes. If an instance becomes the leader, it should respond to notification of being SUSPENDED or LOST.
If the SUSPENDED state is reported, the instance must assume that it might no longer be the leader until it receives a RECONNECTED state. If the LOST state is reported, the instance is no longer the leader and its takeLeadership
method should exit.
- Curator
- Javadoc
- Coverage Report
- Getting Started
- Examples
- FAQ
- Client
- Framework
-
Recipes
- Leader Latch
- Leader Election
- Shared Reentrant Lock
- Shared Lock
- Shared Reentrant Read Write Lock
- Shared Semaphore
- Multi Shared Lock
- Distributed Queue
- Distributed Id Queue
- Distributed Priority Queue
- Distributed Delay Queue
- Simple Distributed Queue
- Barrier
- Double Barrier
- Shared counter
- Distributed Atomic Long
- Path Cache
- Node Cache
- Utilities – Test Server, Test Cluster, ZKPaths, EnsurePath, QueueSharder, Reaper, ChildReaper
- Tech Notes
- Errors
- Exhibitor Integration
- Extensions
- Logging and Tracing