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:

Since:
3.0
Author:
Artem Bilan
  • Field Details

    • DEFAULT_TABLE_NAME

      public static final String DEFAULT_TABLE_NAME
      The "SpringIntegrationLockRegistry" default name for the locks table in the DynamoDB.
      See Also:
    • KEY_ATTR

      public static final String KEY_ATTR
      The "lockKey" name for the partition key in the table.
      See Also:
    • OWNER_ATTR

      public static final String OWNER_ATTR
      The "lockOwner" name for the owner of lock in the table.
      See Also:
    • CREATED_ATTR

      public static final String CREATED_ATTR
      The "createdAt" date for lock item.
      See Also:
    • TTL_ATTR

      public static final String TTL_ATTR
      The "expireAt" for how long the lock is valid.
      See Also:
    • DEFAULT_LEASE_DURATION

      public static final Duration DEFAULT_LEASE_DURATION
      Default value for the leaseDuration 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

      public void setOwner(String owner)
      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

      public void setLeaseDuration(Duration leaseDuration)
      How long to hold the item after last update.
      Parameters:
      leaseDuration - the duration for how long to keep the lock after last update.
    • getTableName

      public String getTableName()
    • getOwner

      public String getOwner()
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • isAcquired

      public boolean isAcquired(String lock)
      Check if a lock is held by this repository.
      Parameters:
      lock - the lock to check.
      Returns:
      acquired or not.
    • delete

      public void delete(String lock)
      Remove a lock from this repository.
      Parameters:
      lock - the lock to remove.
    • deleteExpired

      public void deleteExpired()
      Remove all the expired locks.
    • acquire

      public boolean acquire(String lock) throws InterruptedException
      Acquire a lock for a key.
      Parameters:
      lock - the key for lock to acquire.
      Returns:
      acquired or not.
      Throws:
      InterruptedException
    • renew

      public boolean renew(String lock)
      Renew the lease for a lock.
      Parameters:
      lock - the lock to renew.
      Returns:
      renewed or not.
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable