Interface Candidate
-
public interface Candidate
Leader election candidate.Implementations of this interface can be registered within the
ElectionService
in order to participate in the leader election process. If this candidate wins then itsbecomeLeader(LeaderContext)
method will be called. If some other candidate wins then this candidate will be notified viabecomeFollower(FollowerContext)
method. If later on the existing leader leaves the cluster oryeilds leadship
then this candidate will try again to become a new leader. If it finally succeeds thenbecomeLeader(LeaderContext)
method will be called.For more details about the leader election process please see the documentation of
ElectionService
interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
becomeFollower(FollowerContext ctx)
Gets called when this candidate couldn't win elections and switched to the follower state.void
becomeLeader(LeaderContext ctx)
Gets called when this candidate becomes a group leader.void
terminate()
Gets called when candidate must be terminated because of theElectionService
being stopped.
-
-
-
Method Detail
-
becomeLeader
void becomeLeader(LeaderContext ctx)
Gets called when this candidate becomes a group leader.IMPORTANT: Implementations of this method should not block the calling thread for a long time and should execute all long running computations asynchronously.
- Parameters:
ctx
- Leader context.
-
becomeFollower
void becomeFollower(FollowerContext ctx)
Gets called when this candidate couldn't win elections and switched to the follower state. Information about the current leader can be obtained viaFollowerContext.leader()
.IMPORTANT: Implementations of this method should not block the calling thread for a long time and should execute all long running computations asynchronously.
- Parameters:
ctx
- Follower context.
-
terminate
void terminate()
Gets called when candidate must be terminated because of theElectionService
being stopped.Note that this method will NOT be called if this candidate never reached any of the Leader/Follower state (i.e. if
becomeLeader(LeaderContext)
orbecomeFollower(FollowerContext)
were never called).
-
-