public class LeaseCoordinator<T extends Lease>
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected IMetricsFactory |
metricsFactory |
static java.lang.String |
WORKER_IDENTIFIER_METRIC |
| Constructor and Description |
|---|
LeaseCoordinator(ILeaseManager<T> leaseManager,
java.lang.String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis)
Constructor.
|
LeaseCoordinator(ILeaseManager<T> leaseManager,
java.lang.String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
IMetricsFactory metricsFactory)
Constructor.
|
LeaseCoordinator(ILeaseManager<T> leaseManager,
java.lang.String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
IMetricsFactory metricsFactory)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Collection<T> |
getAssignments() |
T |
getCurrentlyHeldLease(java.lang.String leaseKey) |
java.lang.String |
getWorkerIdentifier() |
boolean |
isRunning() |
protected void |
runRenewer()
Runs a single iteration of the lease renewer - used by integration tests.
|
protected void |
runTaker()
Runs a single iteration of the lease taker - used by integration tests.
|
void |
start()
Start background LeaseHolder and LeaseTaker threads.
|
void |
stop()
Stops background threads and waits for
STOP_WAIT_TIME_MILLIS for all background tasks to complete. |
boolean |
updateLease(T lease,
java.util.UUID concurrencyToken)
Updates application-specific lease values in DynamoDB.
|
public static final java.lang.String WORKER_IDENTIFIER_METRIC
protected final IMetricsFactory metricsFactory
public LeaseCoordinator(ILeaseManager<T> leaseManager, java.lang.String workerIdentifier, long leaseDurationMillis, long epsilonMillis)
leaseManager - LeaseManager instance to useworkerIdentifier - Identifies the worker (e.g. useful to track lease ownership)leaseDurationMillis - Duration of a leaseepsilonMillis - Allow for some variance when calculating lease expirationspublic LeaseCoordinator(ILeaseManager<T> leaseManager, java.lang.String workerIdentifier, long leaseDurationMillis, long epsilonMillis, IMetricsFactory metricsFactory)
leaseManager - LeaseManager instance to useworkerIdentifier - Identifies the worker (e.g. useful to track lease ownership)leaseDurationMillis - Duration of a leaseepsilonMillis - Allow for some variance when calculating lease expirationsmetricsFactory - Used to publish metrics about lease operationspublic LeaseCoordinator(ILeaseManager<T> leaseManager, java.lang.String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, IMetricsFactory metricsFactory)
leaseManager - LeaseManager instance to useworkerIdentifier - Identifies the worker (e.g. useful to track lease ownership)leaseDurationMillis - Duration of a leaseepsilonMillis - Allow for some variance when calculating lease expirationsmaxLeasesForWorker - Max leases this Worker can handle at a timemaxLeasesToStealAtOneTime - Steal up to these many leases at a time (for load balancing)metricsFactory - Used to publish metrics about lease operationspublic void start()
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
ProvisionedThroughputException - If we can't talk to DynamoDB due to insufficient capacity.InvalidStateException - If the lease table doesn't existDependencyException - If we encountered exception taking to DynamoDBprotected void runTaker()
throws DependencyException,
InvalidStateException
protected void runRenewer()
throws DependencyException,
InvalidStateException
public java.util.Collection<T> getAssignments()
public T getCurrentlyHeldLease(java.lang.String leaseKey)
leaseKey - lease key to fetch currently held lease forpublic java.lang.String getWorkerIdentifier()
public void stop()
STOP_WAIT_TIME_MILLIS for all background tasks to complete.
If tasks are not completed after this time, method will shutdown thread pool forcefully and return.public boolean isRunning()
public boolean updateLease(T lease, java.util.UUID concurrencyToken) throws DependencyException, InvalidStateException, ProvisionedThroughputException
lease - lease object containing updated valuesconcurrencyToken - obtained by calling Lease.getConcurrencyToken for a currently held leaseInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB update fails due to lack of capacityDependencyException - if DynamoDB update fails in an unexpected way