public class DynamoDBLeaseRefresher extends Object implements LeaseRefresher
LeaseRefresher that uses DynamoDB.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
consistentReads |
protected software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient |
dynamoDBClient |
protected LeaseSerializer |
serializer |
protected String |
table |
| Constructor and Description |
|---|
DynamoDBLeaseRefresher(String table,
software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient,
LeaseSerializer serializer,
boolean consistentReads)
Deprecated.
|
DynamoDBLeaseRefresher(String table,
software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient,
LeaseSerializer serializer,
boolean consistentReads,
TableCreatorCallback tableCreatorCallback)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected DependencyException |
convertAndRethrowExceptions(String operation,
String leaseKey,
Exception e) |
boolean |
createLeaseIfNotExists(Lease lease)
Create a new lease.
|
boolean |
createLeaseTableIfNotExists(Long readCapacity,
Long writeCapacity)
Creates the table that will store leases.
|
void |
deleteAll()
Delete all leases from DynamoDB.
|
void |
deleteLease(Lease lease)
Delete the given lease from DynamoDB.
|
boolean |
evictLease(Lease lease)
Evict the current owner of lease by setting owner to null.
|
ExtendedSequenceNumber |
getCheckpoint(String shardId)
Gets the current checkpoint of the shard.
|
Lease |
getLease(String leaseKey) |
boolean |
isLeaseTableEmpty()
Check (synchronously) if there are any leases in the lease table.
|
boolean |
leaseTableExists() |
List<Lease> |
listLeases()
List all objects in table synchronously.
|
boolean |
renewLease(Lease lease)
Renew a lease by incrementing the lease counter.
|
boolean |
takeLease(Lease lease,
String owner)
Take a lease for the given owner by incrementing its leaseCounter and setting its owner field.
|
boolean |
updateLease(Lease lease)
Update application-specific fields of the given lease in DynamoDB.
|
boolean |
waitUntilLeaseTableExists(long secondsBetweenPolls,
long timeoutSeconds)
Blocks until the lease table exists by polling leaseTableExists.
|
protected final String table
protected final software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient
protected final LeaseSerializer serializer
protected final boolean consistentReads
@Deprecated public DynamoDBLeaseRefresher(String table, software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient, LeaseSerializer serializer, boolean consistentReads)
NOTE: This constructor is deprecated and will be removed in a future release.
table - dynamoDBClient - serializer - consistentReads - public DynamoDBLeaseRefresher(String table, software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient, LeaseSerializer serializer, boolean consistentReads, @NonNull TableCreatorCallback tableCreatorCallback)
table - dynamoDBClient - serializer - consistentReads - tableCreatorCallback - public boolean createLeaseTableIfNotExists(@NonNull
Long readCapacity,
@NonNull
Long writeCapacity)
throws ProvisionedThroughputException,
DependencyException
createLeaseTableIfNotExists in interface LeaseRefresherProvisionedThroughputException - if we cannot create the lease table due to per-AWS-account capacity
restrictions.DependencyException - if DynamoDB createTable fails in an unexpected waypublic boolean leaseTableExists()
throws DependencyException
leaseTableExists in interface LeaseRefresherDependencyException - if DynamoDB describeTable fails in an unexpected waypublic boolean waitUntilLeaseTableExists(long secondsBetweenPolls,
long timeoutSeconds)
throws DependencyException
LeaseRefresherwaitUntilLeaseTableExists in interface LeaseRefreshersecondsBetweenPolls - time to wait between polls in secondstimeoutSeconds - total time to wait in secondsDependencyException - if DynamoDB describeTable fails in an unexpected waypublic List<Lease> listLeases() throws DependencyException, InvalidStateException, ProvisionedThroughputException
listLeases in interface LeaseRefresherDependencyException - if DynamoDB scan fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB scan fails due to lack of capacitypublic boolean isLeaseTableEmpty()
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
isLeaseTableEmpty in interface LeaseRefresherDependencyException - if DynamoDB scan fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB scan fails due to lack of capacitypublic boolean createLeaseIfNotExists(@NonNull
Lease lease)
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
createLeaseIfNotExists in interface LeaseRefresherlease - the lease to createDependencyException - if DynamoDB put fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB put fails due to lack of capacitypublic Lease getLease(@NonNull String leaseKey) throws DependencyException, InvalidStateException, ProvisionedThroughputException
getLease in interface LeaseRefresherleaseKey - Get the lease for this shardIdDependencyException - if DynamoDB get fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB get fails due to lack of capacitypublic boolean renewLease(@NonNull
Lease lease)
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
renewLease in interface LeaseRefresherlease - the lease to renewDependencyException - if DynamoDB update fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB update fails due to lack of capacitypublic boolean takeLease(@NonNull
Lease lease,
@NonNull
String owner)
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
takeLease in interface LeaseRefresherlease - the lease to takeowner - the new ownerDependencyException - if DynamoDB update fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB update fails due to lack of capacitypublic boolean evictLease(@NonNull
Lease lease)
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
evictLease in interface LeaseRefresherlease - the lease to voidDependencyException - if DynamoDB update fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB update fails due to lack of capacitypublic void deleteAll()
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
deleteAll in interface LeaseRefresherDependencyException - if DynamoDB scan or delete fail in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB scan or delete fail due to lack of capacitypublic void deleteLease(@NonNull
Lease lease)
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
deleteLease in interface LeaseRefresherlease - the lease to deleteDependencyException - if DynamoDB delete fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB delete fails due to lack of capacitypublic boolean updateLease(@NonNull
Lease lease)
throws DependencyException,
InvalidStateException,
ProvisionedThroughputException
updateLease in interface LeaseRefresherDependencyException - if DynamoDB update fails in an unexpected wayInvalidStateException - if lease table does not existProvisionedThroughputException - if DynamoDB update fails due to lack of capacitypublic ExtendedSequenceNumber getCheckpoint(String shardId) throws ProvisionedThroughputException, InvalidStateException, DependencyException
getCheckpoint in interface LeaseRefreshershardId - Checkpoint of this shard will be returnedProvisionedThroughputException - if DynamoDB update fails due to lack of capacityInvalidStateException - if lease table does not existDependencyException - if DynamoDB update fails in an unexpected wayprotected DependencyException convertAndRethrowExceptions(String operation, String leaseKey, Exception e) throws ProvisionedThroughputException, InvalidStateException
Copyright © 2019. All rights reserved.