Class DynamoDbLockRepository
java.lang.Object
io.awspring.cloud.dynamodb.DynamoDbLockRepository
- All Implemented Interfaces:
Closeable,AutoCloseable,DisposableBean,InitializingBean
public class DynamoDbLockRepository
extends Object
implements InitializingBean, DisposableBean, Closeable
Encapsulation of the DynamoDB shunting that is needed for locks.
The DynamoDb table must have these attributes:
KEY_ATTRScalarAttributeType.S- partition keyKeyType.HASHOWNER_ATTRScalarAttributeType.SCREATED_ATTRScalarAttributeType.NTTL_ATTRScalarAttributeType.N
- Since:
- 4.0
- Author:
- Artem Bilan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe "createdAt" date for lock item.static final StringThe "SpringIntegrationLockRegistry" default name for the locks table in the DynamoDB.static final StringThe "lockKey" name for the partition key in the table.static final StringThe "lockOwner" name for the owner of lock in the table.static final StringThe "expireAt" for how long the lock is valid. -
Constructor Summary
ConstructorsConstructorDescriptionDynamoDbLockRepository(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDB) DynamoDbLockRepository(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDB, String tableName) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAcquire a lock for a key.voidvoidclose()voidRemove a lock from this repository.voidRemove all the expired locks.voiddestroy()getOwner()booleanisAcquired(String lock) Check if a lock is held by this repository.booleanRenew the lease for a lock.voidsetBillingMode(software.amazon.awssdk.services.dynamodb.model.BillingMode billingMode) voidSpecify a custom client id (owner) for locks in DB.voidsetReadCapacity(long readCapacity) voidsetWriteCapacity(long writeCapacity)
-
Field Details
-
DEFAULT_TABLE_NAME
The "SpringIntegrationLockRegistry" default name for the locks table in the DynamoDB.- See Also:
-
KEY_ATTR
The "lockKey" name for the partition key in the table.- See Also:
-
OWNER_ATTR
The "lockOwner" name for the owner of lock in the table.- See Also:
-
CREATED_ATTR
-
TTL_ATTR
-
-
Constructor Details
-
DynamoDbLockRepository
public DynamoDbLockRepository(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDB) -
DynamoDbLockRepository
public DynamoDbLockRepository(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDB, String tableName)
-
-
Method Details
-
setBillingMode
public void setBillingMode(software.amazon.awssdk.services.dynamodb.model.BillingMode billingMode) -
setReadCapacity
public void setReadCapacity(long readCapacity) -
setWriteCapacity
public void setWriteCapacity(long writeCapacity) -
setOwner
Specify a custom client id (owner) for locks in DB. Must be unique per cluster to avoid interlocking between different instances.- Parameters:
owner- the client id to be associated with locks handled by the repository.
-
getTableName
-
getOwner
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
isAcquired
Check if a lock is held by this repository.- Parameters:
lock- the lock to check.- Returns:
- acquired or not.
-
delete
Remove a lock from this repository.- Parameters:
lock- the lock to remove.
-
deleteExpired
public void deleteExpired()Remove all the expired locks. -
acquire
Acquire a lock for a key.- Parameters:
lock- the key for lock to acquire.ttl- the lease duration for the lock record.- Returns:
- acquired or not.
- Throws:
InterruptedException
-
renew
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-