Class JdbcLockRegistry

java.lang.Object
org.springframework.integration.jdbc.lock.JdbcLockRegistry
All Implemented Interfaces:
ExpirableLockRegistry<DistributedLock>, LockRegistry<DistributedLock>, RenewableLockRegistry<DistributedLock>

public class JdbcLockRegistry extends Object implements ExpirableLockRegistry<DistributedLock>, RenewableLockRegistry<DistributedLock>
An ExpirableLockRegistry using a shared database to co-ordinate the locks. Provides the same semantics as the DefaultLockRegistry, but the locks taken will be global, as long as the underlying database supports the "serializable" isolation level in its transactions.
Since:
4.3
Author:
Dave Syer, Artem Bilan, Vedran Pavic, Kai Zimmermann, Bartosz Rempuszewski, Gary Russell, Alexandre Strubel, Stefan Vassilev, Olivier Hubaut, Fran Aranda, Unseok Kim, Christian Tzolov, Myeonghyeon Lee, Eddie Cho
  • Field Details

    • DEFAULT_TTL

      public static final Duration DEFAULT_TTL
      Default value for the time-to-live property.
      Since:
      7.0
  • Constructor Details

    • JdbcLockRegistry

      public JdbcLockRegistry(LockRepository client)
      Construct an instance based on the provided LockRepository.
      Parameters:
      client - the LockRepository to rely on.
    • JdbcLockRegistry

      public JdbcLockRegistry(LockRepository client, Duration expireAfter)
      Create a lock registry with the supplied lock expiration.
      Parameters:
      client - the LockRepository to rely on.
      expireAfter - The expiration in Duration.
      Since:
      7.0
  • Method Details

    • setIdleBetweenTries

      public void setIdleBetweenTries(Duration idleBetweenTries)
      Specify a Duration to sleep between lock record insert/update attempts. Defaults to 100 milliseconds.
      Parameters:
      idleBetweenTries - the Duration to sleep between insert/update attempts.
      Since:
      5.1.8
    • setCacheCapacity

      public void setCacheCapacity(int cacheCapacity)
      Set the capacity of cached locks.
      Parameters:
      cacheCapacity - The capacity of cached lock, (default 100_000).
      Since:
      5.5.6
    • obtain

      public DistributedLock obtain(Object lockKey)
      Description copied from interface: LockRegistry
      Obtain the lock associated with the parameter object.
      Specified by:
      obtain in interface LockRegistry<DistributedLock>
      Parameters:
      lockKey - The object with which the lock is associated.
      Returns:
      The associated lock.
    • pathFor

      protected String pathFor(String input)
    • expireUnusedOlderThan

      public void expireUnusedOlderThan(long age)
      Description copied from interface: ExpirableLockRegistry
      Remove locks last acquired more than 'age' ago that are not currently locked.
      Specified by:
      expireUnusedOlderThan in interface ExpirableLockRegistry<DistributedLock>
      Parameters:
      age - the time since the lock was last obtained.
    • renewLock

      public void renewLock(Object lockKey)
      Description copied from interface: RenewableLockRegistry
      Renew the time to live of the lock is associated with the parameter object. The lock must be held by the current thread
      Specified by:
      renewLock in interface RenewableLockRegistry<DistributedLock>
      Parameters:
      lockKey - The object with which the lock is associated.
    • renewLock

      public void renewLock(Object lockKey, Duration customTtl)
      Description copied from interface: RenewableLockRegistry
      Renew the time to live of the lock is associated with the parameter object with a specific value. The lock must be held by the current thread
      Specified by:
      renewLock in interface RenewableLockRegistry<DistributedLock>
      Parameters:
      lockKey - The object with which the lock is associated.
      customTtl - the specific time-to-live for the lock status data