public class LeaseCoordinator<T extends Lease> extends Object
| Modifier and Type | Field and Description |
|---|---|
protected IMetricsFactory |
metricsFactory |
static String |
WORKER_IDENTIFIER_METRIC |
| Constructor and Description |
|---|
LeaseCoordinator(ILeaseManager<T> leaseManager,
LeaseSelector<T> leaseSelector,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis)
Constructor.
|
LeaseCoordinator(ILeaseManager<T> leaseManager,
LeaseSelector<T> leaseSelector,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
IMetricsFactory metricsFactory)
Constructor.
|
LeaseCoordinator(ILeaseManager<T> leaseManager,
LeaseSelector<T> leaseSelector,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
IMetricsFactory metricsFactory) |
LeaseCoordinator(ILeaseManager<T> leaseManager,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis)
Constructor.
|
LeaseCoordinator(ILeaseManager<T> leaseManager,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
IMetricsFactory metricsFactory)
Constructor.
|
LeaseCoordinator(ILeaseManager<T> leaseManager,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
IMetricsFactory metricsFactory)
Constructor.
|
LeaseCoordinator(ILeaseTaker<T> leaseTaker,
ILeaseRenewer<T> leaseRenewer,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
IMetricsFactory metricsFactory) |
| Modifier and Type | Method and Description |
|---|---|
void |
dropLease(T lease)
Requests that renewals for the given lease are stopped.
|
Collection<T> |
getAssignments() |
T |
getCurrentlyHeldLease(String leaseKey) |
static ExecutorService |
getDefaultLeaseRenewalExecutorService(int maximumPoolSize)
Returns executor service that should be used for lease renewal.
|
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. |
void |
stopLeaseTaker()
Requests the cancellation of the lease taker.
|
boolean |
updateLease(T lease,
UUID concurrencyToken)
Updates application-specific lease values in DynamoDB.
|
public static final String WORKER_IDENTIFIER_METRIC
protected final IMetricsFactory metricsFactory
public LeaseCoordinator(ILeaseManager<T> leaseManager, 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, LeaseSelector<T> leaseSelector, String workerIdentifier, long leaseDurationMillis, long epsilonMillis)
leaseManager - LeaseManager instance to useleaseSelector - LeaseSelector 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, 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, LeaseSelector<T> leaseSelector, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, IMetricsFactory metricsFactory)
leaseManager - LeaseManager instance to useleaseSelector - LeaseSelector 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, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, 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 LeaseCoordinator(ILeaseManager<T> leaseManager, LeaseSelector<T> leaseSelector, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, IMetricsFactory metricsFactory)
leaseManager - LeaseManager instance to useleaseSelector - LeaseSelector instance to be used for filtering leases during LeaseTaker execution.workerIdentifier - 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)maxLeaseRenewerThreadCount - Number of threads to use for lease renewal callsmetricsFactory - Used to publish metrics about lease operationspublic LeaseCoordinator(ILeaseTaker<T> leaseTaker, ILeaseRenewer<T> leaseRenewer, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, IMetricsFactory metricsFactory)
leaseTaker - LeaseTaker instance to be used.leaseRenewer - LeaseRenewer instance to be used.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 Collection<T> getAssignments()
public T getCurrentlyHeldLease(String leaseKey)
leaseKey - lease key to fetch currently held lease forpublic 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 void stopLeaseTaker()
public void dropLease(T lease)
lease - the lease to stop renewing.public boolean isRunning()
public boolean updateLease(T lease, 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 waypublic static ExecutorService getDefaultLeaseRenewalExecutorService(int maximumPoolSize)
maximumPoolSize - Maximum allowed thread pool sizeCopyright © 2023. All rights reserved.