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)
Deprecated.
|
DynamoDBLeaseRefresher(String table,
software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient,
LeaseSerializer serializer,
boolean consistentReads,
TableCreatorCallback tableCreatorCallback,
Duration dynamoDbRequestTimeout)
Deprecated.
|
DynamoDBLeaseRefresher(String table,
software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient,
LeaseSerializer serializer,
boolean consistentReads,
TableCreatorCallback tableCreatorCallback,
Duration dynamoDbRequestTimeout,
software.amazon.awssdk.services.dynamodb.model.BillingMode billingMode)
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 leaseKey)
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.
|
List<Lease> |
listLeasesForStream(StreamIdentifier streamIdentifier)
List all leases for a given stream 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.
|
void |
updateLeaseWithMetaInfo(Lease lease,
UpdateField updateField)
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
- @Deprecated public DynamoDBLeaseRefresher(String table, software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient, LeaseSerializer serializer, boolean consistentReads, @NonNull TableCreatorCallback tableCreatorCallback)
table
- dynamoDBClient
- serializer
- consistentReads
- tableCreatorCallback
- @Deprecated public DynamoDBLeaseRefresher(String table, software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient, LeaseSerializer serializer, boolean consistentReads, @NonNull TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout)
table
- dynamoDBClient
- serializer
- consistentReads
- tableCreatorCallback
- dynamoDbRequestTimeout
- public DynamoDBLeaseRefresher(String table, software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDBClient, LeaseSerializer serializer, boolean consistentReads, @NonNull TableCreatorCallback tableCreatorCallback, Duration dynamoDbRequestTimeout, software.amazon.awssdk.services.dynamodb.model.BillingMode billingMode)
table
- dynamoDBClient
- serializer
- consistentReads
- tableCreatorCallback
- dynamoDbRequestTimeout
- billingMode
- public boolean createLeaseTableIfNotExists(@NonNull Long readCapacity, @NonNull Long writeCapacity) throws ProvisionedThroughputException, DependencyException
createLeaseTableIfNotExists
in interface LeaseRefresher
ProvisionedThroughputException
- 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 LeaseRefresher
DependencyException
- if DynamoDB describeTable fails in an unexpected waypublic boolean waitUntilLeaseTableExists(long secondsBetweenPolls, long timeoutSeconds) throws DependencyException
LeaseRefresher
waitUntilLeaseTableExists
in interface LeaseRefresher
secondsBetweenPolls
- time to wait between polls in secondstimeoutSeconds
- total time to wait in secondsDependencyException
- if DynamoDB describeTable fails in an unexpected waypublic List<Lease> listLeasesForStream(StreamIdentifier streamIdentifier) throws DependencyException, InvalidStateException, ProvisionedThroughputException
listLeasesForStream
in interface LeaseRefresher
DependencyException
- if DynamoDB scan fails in an unexpected wayInvalidStateException
- if lease table does not existProvisionedThroughputException
- if DynamoDB scan fails due to lack of capacitypublic List<Lease> listLeases() throws DependencyException, InvalidStateException, ProvisionedThroughputException
listLeases
in interface LeaseRefresher
DependencyException
- 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 LeaseRefresher
DependencyException
- 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 LeaseRefresher
lease
- 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 LeaseRefresher
leaseKey
- Get the lease for this leasekeyDependencyException
- 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 LeaseRefresher
lease
- 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 LeaseRefresher
lease
- 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 LeaseRefresher
lease
- 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 LeaseRefresher
DependencyException
- 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 LeaseRefresher
lease
- 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 LeaseRefresher
DependencyException
- if DynamoDB update fails in an unexpected wayInvalidStateException
- if lease table does not existProvisionedThroughputException
- if DynamoDB update fails due to lack of capacitypublic void updateLeaseWithMetaInfo(Lease lease, UpdateField updateField) throws DependencyException, InvalidStateException, ProvisionedThroughputException
LeaseRefresher
updateLeaseWithMetaInfo
in interface LeaseRefresher
DependencyException
- 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 leaseKey) throws ProvisionedThroughputException, InvalidStateException, DependencyException
getCheckpoint
in interface LeaseRefresher
leaseKey
- 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 © 2021. All rights reserved.