public class DynamoDBLeaseRenewer extends Object implements LeaseRenewer
LeaseRenewer that uses DynamoDB via LeaseRefresher.| Constructor and Description |
|---|
DynamoDBLeaseRenewer(LeaseRefresher leaseRefresher,
String workerIdentifier,
long leaseDurationMillis,
ExecutorService executorService,
MetricsFactory metricsFactory)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLeasesToRenew(Collection<Lease> newLeases)
Adds leases to this LeaseRenewer's set of currently held leases.
|
void |
clearCurrentlyHeldLeases()
Clears this LeaseRenewer's set of currently held leases.
|
void |
dropLease(Lease lease)
Stops the lease renewer from continunig to maintain the given lease.
|
Lease |
getCurrentlyHeldLease(String leaseKey) |
Map<String,Lease> |
getCurrentlyHeldLeases() |
void |
initialize()
Bootstrap initial set of leases from the
LeaseRefresher (e.g. |
void |
renewLeases()
Attempt to renew all currently held leases.
|
boolean |
updateLease(Lease lease,
UUID concurrencyToken,
String operation,
String shardId)
Update application-specific fields in a currently held lease.
|
public DynamoDBLeaseRenewer(LeaseRefresher leaseRefresher, String workerIdentifier, long leaseDurationMillis, ExecutorService executorService, MetricsFactory metricsFactory)
leaseRefresher - LeaseRefresher to useworkerIdentifier - identifier of this workerleaseDurationMillis - duration of a lease in millisecondsexecutorService - ExecutorService to use for renewing leases in parallelpublic void renewLeases()
throws DependencyException,
InvalidStateException
renewLeases in interface LeaseRenewerDependencyException - on unexpected DynamoDB failuresInvalidStateException - if lease table does not existpublic Map<String,Lease> getCurrentlyHeldLeases()
getCurrentlyHeldLeases in interface LeaseRenewerpublic Lease getCurrentlyHeldLease(String leaseKey)
getCurrentlyHeldLease in interface LeaseRenewerleaseKey - key of the lease to retrievepublic boolean updateLease(Lease lease, UUID concurrencyToken, @NonNull String operation, String shardId) throws DependencyException, InvalidStateException, ProvisionedThroughputException
updateLease in interface LeaseRenewerlease - lease object containing updated dataconcurrencyToken - obtained by calling Lease.concurrencyToken for a currently held leaseDependencyException - if DynamoDB update fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB update fails due to lack of capacitypublic void addLeasesToRenew(Collection<Lease> newLeases)
addLeasesToRenew in interface LeaseRenewernewLeases - new leases.public void clearCurrentlyHeldLeases()
clearCurrentlyHeldLeases in interface LeaseRenewerpublic void dropLease(Lease lease)
dropLease in interface LeaseRenewerlease - the lease to drop.public void initialize()
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
LeaseRefresher (e.g. upon process restart, pick up leases we own)initialize in interface LeaseRenewerDependencyException - on unexpected DynamoDB failuresInvalidStateException - if lease table doesn't existProvisionedThroughputException - if DynamoDB reads fail due to insufficient capacityCopyright © 2019. All rights reserved.