public class DynamoDBLeaseCoordinator extends Object implements LeaseCoordinator
| Modifier and Type | Field and Description |
|---|---|
protected MetricsFactory |
metricsFactory |
| Constructor and Description |
|---|
DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
long initialLeaseTableReadCapacity,
long initialLeaseTableWriteCapacity,
MetricsFactory metricsFactory)
Constructor.
|
DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher,
String workerIdentifier,
long leaseDurationMillis,
long epsilonMillis,
int maxLeasesForWorker,
int maxLeasesToStealAtOneTime,
int maxLeaseRenewerThreadCount,
MetricsFactory metricsFactory)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
List<Lease> |
allLeases()
Default implementation returns an empty list and concrete implementation is expected to return all leases
for the application that are in the lease table.
|
static ShardInfo |
convertLeaseToAssignment(Lease lease) |
void |
dropLease(Lease lease)
Requests that renewals for the given lease are stopped.
|
Collection<Lease> |
getAssignments() |
List<ShardInfo> |
getCurrentAssignments() |
Lease |
getCurrentlyHeldLease(String leaseKey) |
void |
initialize()
Initialize the lease coordinator (create the lease table if needed).
|
DynamoDBLeaseCoordinator |
initialLeaseTableReadCapacity(long readCapacity)
Deprecated.
|
DynamoDBLeaseCoordinator |
initialLeaseTableWriteCapacity(long writeCapacity)
Deprecated.
|
boolean |
isRunning() |
LeaseRefresher |
leaseRefresher() |
void |
runLeaseRenewer()
Runs a single iteration of the lease renewer - used by integration tests.
|
void |
runLeaseTaker()
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 specific amount of time for all background tasks to complete.
|
void |
stopLeaseTaker()
Requests the cancellation of the lease taker.
|
boolean |
updateLease(Lease lease,
UUID concurrencyToken,
String operation,
String shardId)
Updates application-specific lease values in DynamoDB.
|
String |
workerIdentifier() |
protected final MetricsFactory metricsFactory
@Deprecated public DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, MetricsFactory metricsFactory)
NOTE: This constructor is deprecated and will be removed in a future release.
leaseRefresher - LeaseRefresher 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 DynamoDBLeaseCoordinator(LeaseRefresher leaseRefresher, String workerIdentifier, long leaseDurationMillis, long epsilonMillis, int maxLeasesForWorker, int maxLeasesToStealAtOneTime, int maxLeaseRenewerThreadCount, long initialLeaseTableReadCapacity, long initialLeaseTableWriteCapacity, MetricsFactory metricsFactory)
leaseRefresher - LeaseRefresher 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)initialLeaseTableReadCapacity - Initial dynamodb lease table read iops if creating the lease tableinitialLeaseTableWriteCapacity - Initial dynamodb lease table write iops if creating the lease tablemetricsFactory - Used to publish metrics about lease operationspublic void initialize()
throws ProvisionedThroughputException,
DependencyException,
IllegalStateException
LeaseCoordinatorinitialize in interface LeaseCoordinatorProvisionedThroughputExceptionDependencyExceptionIllegalStateExceptionpublic void start()
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
LeaseCoordinatorstart in interface LeaseCoordinatorDependencyException - If we encountered exception taking to DynamoDBInvalidStateException - If the lease table doesn't existProvisionedThroughputException - If we can't talk to DynamoDB due to insufficient capacity.public void runLeaseTaker()
throws DependencyException,
InvalidStateException
LeaseCoordinatorrunLeaseTaker in interface LeaseCoordinatorDependencyExceptionInvalidStateExceptionpublic void runLeaseRenewer()
throws DependencyException,
InvalidStateException
LeaseCoordinatorrunLeaseRenewer in interface LeaseCoordinatorDependencyExceptionInvalidStateExceptionpublic Collection<Lease> getAssignments()
getAssignments in interface LeaseCoordinatorpublic List<Lease> allLeases()
LeaseCoordinatorallLeases in interface LeaseCoordinatorpublic Lease getCurrentlyHeldLease(String leaseKey)
getCurrentlyHeldLease in interface LeaseCoordinatorleaseKey - lease key to fetch currently held lease forpublic String workerIdentifier()
workerIdentifier in interface LeaseCoordinatorpublic LeaseRefresher leaseRefresher()
leaseRefresher in interface LeaseCoordinatorLeaseRefresherpublic void stop()
LeaseCoordinatorstop in interface LeaseCoordinatorpublic void stopLeaseTaker()
LeaseCoordinatorstopLeaseTaker in interface LeaseCoordinatorpublic void dropLease(Lease lease)
LeaseCoordinatordropLease in interface LeaseCoordinatorlease - the lease to stop renewing.public boolean isRunning()
isRunning in interface LeaseCoordinatorpublic boolean updateLease(Lease lease, UUID concurrencyToken, String operation, String shardId) throws DependencyException, InvalidStateException, ProvisionedThroughputException
LeaseCoordinatorupdateLease in interface LeaseCoordinatorlease - lease object containing updated valuesconcurrencyToken - 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 List<ShardInfo> getCurrentAssignments()
getCurrentAssignments in interface LeaseCoordinator@Deprecated public DynamoDBLeaseCoordinator initialLeaseTableReadCapacity(long readCapacity)
NOTE: This method is deprecated. Please set the initial capacity through the constructor.
initialLeaseTableReadCapacity in interface LeaseCoordinatorreadCapacity - The DynamoDB table used for tracking leases will be provisioned with the specified initial
read capacity@Deprecated public DynamoDBLeaseCoordinator initialLeaseTableWriteCapacity(long writeCapacity)
NOTE: This method is deprecated. Please set the initial capacity through the constructor.
initialLeaseTableWriteCapacity in interface LeaseCoordinatorwriteCapacity - The DynamoDB table used for tracking leases will be provisioned with the specified initial
write capacityCopyright © 2019. All rights reserved.