Class DynamoDbLockRepository
java.lang.Object
org.springframework.integration.aws.lock.DynamoDbLockRepository
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
public class DynamoDbLockRepository
extends Object
implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, Closeable
Encapsulation of the DynamoDB shunting that is needed for locks.
The DynamoDb table must have these attributes:
-
KEY_ATTR
ScalarAttributeType.S
- partition keyKeyType.HASH
-
OWNER_ATTR
ScalarAttributeType.S
-
CREATED_ATTR
ScalarAttributeType.N
-
TTL_ATTR
ScalarAttributeType.N
- Since:
- 3.0
- Author:
- Artem Bilan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The "createdAt" date for lock item.static final Duration
Default value for theleaseDuration
property.static final String
The "SpringIntegrationLockRegistry" default name for the locks table in the DynamoDB.static final String
The "lockKey" name for the partition key in the table.static final String
The "lockOwner" name for the owner of lock in the table.static final String
The "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 TypeMethodDescriptionboolean
Acquire a lock for a key.void
void
close()
void
Remove a lock from this repository.void
Remove all the expired locks.void
destroy()
getOwner()
boolean
isAcquired
(String lock) Check if a lock is held by this repository.boolean
Renew the lease for a lock.void
setBillingMode
(software.amazon.awssdk.services.dynamodb.model.BillingMode billingMode) void
setLeaseDuration
(Duration leaseDuration) How long to hold the item after last update.void
Specify a custom client id (owner) for locks in DB.void
setReadCapacity
(long readCapacity) void
setWriteCapacity
(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
The "createdAt" date for lock item.- See Also:
-
TTL_ATTR
The "expireAt" for how long the lock is valid.- See Also:
-
DEFAULT_LEASE_DURATION
Default value for theleaseDuration
property.
-
-
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.
-
setLeaseDuration
How long to hold the item after last update.- Parameters:
leaseDuration
- the duration for how long to keep the lock after last update.
-
getTableName
-
getOwner
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
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.- Returns:
- acquired or not.
- Throws:
InterruptedException
-
renew
Renew the lease for a lock.- Parameters:
lock
- the lock to renew.- Returns:
- renewed or not.
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-