public class MockLeaderElector extends Object implements ILeaderElector
Constructor and Description |
---|
MockLeaderElector() |
MockLeaderElector(boolean isLeader) |
MockLeaderElector(boolean isLeader,
String host,
int port) |
Modifier and Type | Method and Description |
---|---|
void |
addToLeaderLockQueue()
queue up for leadership lock.
|
boolean |
awaitLeadership(long timeout,
TimeUnit timeUnit)
Wait for the caller to gain leadership.
|
void |
close()
Method called to allow for cleanup.
|
List<NimbusInfo> |
getAllNimbuses()
Get list of current nimbus addresses.
|
NimbusInfo |
getLeader()
Get the current leader’s address.
|
boolean |
isLeader()
Decide if the caller currently has the leader lock.
|
void |
prepare(Map<String,Object> conf)
Method guaranteed to be called as part of initialization of leader elector instance.
|
void |
quitElectionFor(int delayMs)
Removes the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.
|
public MockLeaderElector()
public MockLeaderElector(boolean isLeader)
public MockLeaderElector(boolean isLeader, String host, int port)
public void prepare(Map<String,Object> conf)
ILeaderElector
Method guaranteed to be called as part of initialization of leader elector instance.
prepare
in interface ILeaderElector
conf
- configurationpublic void addToLeaderLockQueue() throws Exception
ILeaderElector
queue up for leadership lock. The call returns immediately and the caller must check isLeader() to perform any leadership action. This method can be called multiple times so it needs to be idempotent.
addToLeaderLockQueue
in interface ILeaderElector
Exception
public void quitElectionFor(int delayMs) throws Exception
ILeaderElector
Removes the caller from leadership election, relinquishing leadership if acquired, then requeues for leadership after the specified delay.
quitElectionFor
in interface ILeaderElector
delayMs
- The delay to wait before re-entering the electionException
public boolean isLeader() throws Exception
ILeaderElector
Decide if the caller currently has the leader lock.
isLeader
in interface ILeaderElector
Exception
public boolean awaitLeadership(long timeout, TimeUnit timeUnit) throws InterruptedException
ILeaderElector
Wait for the caller to gain leadership. This should only be used in single-Nimbus clusters, and is only useful to allow testing code to wait for a LocalCluster’s Nimbus to gain leadership before trying to submit topologies.
awaitLeadership
in interface ILeaderElector
InterruptedException
public NimbusInfo getLeader()
ILeaderElector
Get the current leader’s address.
getLeader
in interface ILeaderElector
public List<NimbusInfo> getAllNimbuses() throws Exception
ILeaderElector
Get list of current nimbus addresses.
getAllNimbuses
in interface ILeaderElector
Exception
public void close()
ILeaderElector
Method called to allow for cleanup. Relinquishes leadership if owned by the caller.
close
in interface AutoCloseable
close
in interface ILeaderElector
Copyright © 2020 The Apache Software Foundation. All rights reserved.