public class LeaseRenewer<T extends Lease> extends java.lang.Object implements ILeaseRenewer<T>
Constructor and Description |
---|
LeaseRenewer(ILeaseManager<T> leaseManager,
java.lang.String workerIdentifier,
long leaseDurationMillis,
java.util.concurrent.ExecutorService executorService)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addLeasesToRenew(java.util.Collection<T> newLeases)
Adds leases to this LeaseRenewer's set of currently held leases.
|
void |
clearCurrentlyHeldLeases()
Clears this LeaseRenewer's set of currently held leases.
|
T |
getCurrentlyHeldLease(java.lang.String leaseKey) |
java.util.Map<java.lang.String,T> |
getCurrentlyHeldLeases() |
void |
initialize()
Bootstrap initial set of leases from the LeaseManager (e.g.
|
void |
renewLeases()
Attempt to renew all currently held leases.
|
boolean |
updateLease(T lease,
java.util.UUID concurrencyToken)
Update application-specific fields in a currently held lease.
|
public LeaseRenewer(ILeaseManager<T> leaseManager, java.lang.String workerIdentifier, long leaseDurationMillis, java.util.concurrent.ExecutorService executorService)
leaseManager
- LeaseManager 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 ILeaseRenewer<T extends Lease>
DependencyException
- on unexpected DynamoDB failuresInvalidStateException
- if lease table does not existpublic java.util.Map<java.lang.String,T> getCurrentlyHeldLeases()
getCurrentlyHeldLeases
in interface ILeaseRenewer<T extends Lease>
public T getCurrentlyHeldLease(java.lang.String leaseKey)
getCurrentlyHeldLease
in interface ILeaseRenewer<T extends Lease>
leaseKey
- key of the lease to retrievepublic boolean updateLease(T lease, java.util.UUID concurrencyToken) throws DependencyException, InvalidStateException, ProvisionedThroughputException
updateLease
in interface ILeaseRenewer<T extends Lease>
lease
- lease object containing updated dataconcurrencyToken
- obtained by calling Lease.getConcurrencyToken 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(java.util.Collection<T> newLeases)
addLeasesToRenew
in interface ILeaseRenewer<T extends Lease>
newLeases
- new leases.public void clearCurrentlyHeldLeases()
clearCurrentlyHeldLeases
in interface ILeaseRenewer<T extends Lease>
public void initialize() throws DependencyException, InvalidStateException, ProvisionedThroughputException
initialize
in interface ILeaseRenewer<T extends Lease>
DependencyException
- on unexpected DynamoDB failuresInvalidStateException
- if lease table doesn't existProvisionedThroughputException
- if DynamoDB reads fail due to insufficient capacity