public static enum LeaderElection.State extends Enum<LeaderElection.State>
State Transition +----------------+ | +----------+ | | | LEADER | | | +----------+ | | A | | | | | V | +---------+ | +----------+ | | CREATED |----------->| ELECTING | | +---------+ | +----------+ | | | A | | | | | V | V | +---------+ | +----------+ | | DONE |<--------| | FOLLOWER | | +---------+ | +----------+ | +----------------+
LeaderElection.start() method can be called only when the state
start() method is called when the state
IllegalStateException is thrown.
In the implementation of
start() method, the state is changed
ELECTING before the method returns. This means that
Listener.onStateChanged() is called before
start() method is
returned. In some unusual cases, however, the state is changed to
DONE. This happens when the given
CLOSED, or when you have called
As a result of leader election, the state is changed to either
FOLLOWER. The state
LEADER means that
LeaderElection instance has won the leader election and
now is the leader. The state
FOLLOWER means that the
LeaderElection instance has lost the leader election and now is a
The state may be changed back to
FOLLOWER. This happens when it is detected that the znode
for leader election has been deleted. In this case, another new
leader election will be executed without delay, and as a result, the
state will be changed to either
The implementation of
LeaderElection triggers a ZooKeeper
callback as necessary. At the timing, the state of the given
ZooKeeper instance is checked by calling
ZooKeeper.getState() method. If the ZooKeeper's state is either
CLOSED, a ZooKeeper callback is not
triggered, and instead, the state of
|Enum Constant and Description|
The initial state of a
Leader election is now being conducted.
|Modifier and Type||Method and Description|
Returns the enum constant of this type with the specified name.
Returns an array containing the constants of this enum type, in the order they are declared.
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
public static final LeaderElection.State CREATED
public static final LeaderElection.State LEADER
LeaderElectioninstance is now the leader.
public static final LeaderElection.State FOLLOWER
LeaderElectioninstance is now a follower.
public static final LeaderElection.State ELECTING
public static LeaderElection.State values()
for (LeaderElection.State c : LeaderElection.State.values()) System.out.println(c);
public static LeaderElection.State valueOf(String name)
Copyright © 2015. All rights reserved.