public class StandaloneLeaderElectionService extends Object implements LeaderElectionService
LeaderElectionService
interface. The standalone
implementation assumes that there is only a single LeaderContender
and thus directly
grants him the leadership upon start up. Furthermore, there is no communication needed between
multiple standalone leader election services.Constructor and Description |
---|
StandaloneLeaderElectionService() |
Modifier and Type | Method and Description |
---|---|
void |
confirmLeadership(UUID leaderSessionID,
String leaderAddress)
Confirms that the
LeaderContender has accepted the leadership identified by the given
leader session id. |
boolean |
hasLeadership(UUID leaderSessionId)
Returns true if the
LeaderContender with which the service has been started owns
currently the leadership under the given leader session id. |
void |
start(LeaderContender newContender)
Starts the leader election service.
|
void |
stop()
Stops the leader election service.
|
public void start(LeaderContender newContender) throws Exception
LeaderElectionService
start
in interface LeaderElectionService
newContender
- LeaderContender which applies for the leadershipException
public void stop()
LeaderElectionService
stop
in interface LeaderElectionService
public void confirmLeadership(UUID leaderSessionID, String leaderAddress)
LeaderElectionService
LeaderContender
has accepted the leadership identified by the given
leader session id. It also publishes the leader address under which the leader is reachable.
The rational behind this method is to establish an order between setting the new leader
session ID in the LeaderContender
and publishing the new leader session ID as well as
the leader address to the leader retrieval services.
confirmLeadership
in interface LeaderElectionService
leaderSessionID
- The new leader session IDleaderAddress
- The address of the new leaderpublic boolean hasLeadership(@Nonnull UUID leaderSessionId)
LeaderElectionService
LeaderContender
with which the service has been started owns
currently the leadership under the given leader session id.hasLeadership
in interface LeaderElectionService
leaderSessionId
- identifying the current leaderLeaderContender
is the leader, otherwise falseCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.