Class DefaultLockRepository

java.lang.Object
org.springframework.integration.jdbc.lock.DefaultLockRepository
All Implemented Interfaces:
Closeable, AutoCloseable, Aware, InitializingBean, SmartInitializingSingleton, ApplicationContextAware, LockRepository

public class DefaultLockRepository extends Object implements LockRepository, InitializingBean, ApplicationContextAware, SmartInitializingSingleton
The default implementation of the LockRepository based on the table from the script presented in the org/springframework/integration/jdbc/schema-*.sql.

This repository can't be shared between different JdbcLockRegistry instances. Otherwise, it opens a possibility to break Lock contract, where JdbcLockRegistry uses non-shared ReentrantLocks for local synchronizations.

Since:
4.3
Author:
Dave Syer, Artem Bilan, Glenn Renfro, Gary Russell, Alexandre Strubel, Ruslan Stelmachenko
  • Field Details

    • DEFAULT_TABLE_PREFIX

      public static final String DEFAULT_TABLE_PREFIX
      Default value for the table prefix property.
      See Also:
    • DEFAULT_TTL

      public static final int DEFAULT_TTL
      Default value for the time-to-live property.
      See Also:
  • Constructor Details

    • DefaultLockRepository

      public DefaultLockRepository(DataSource dataSource)
      Constructor that initializes the client id that will be associated for all the locks persisted by the store instance to a random UUID.
      Parameters:
      dataSource - the DataSource used to maintain the lock repository.
    • DefaultLockRepository

      public DefaultLockRepository(DataSource dataSource, String id)
      Constructor that allows the user to specify a client id that will be associated for all the locks persisted by the store instance.
      Parameters:
      dataSource - the DataSource used to maintain the lock repository.
      id - the client id to be associated with locks handled by the repository.
      Since:
      4.3.13
  • Method Details

    • setRegion

      public void setRegion(String region)
      A unique grouping identifier for all locks persisted with this store. Using multiple regions allows the store to be partitioned (if necessary) for different purposes. Defaults to DEFAULT.
      Parameters:
      region - the region name to set
    • setPrefix

      public void setPrefix(String prefix)
      Specify the prefix for target database table used from queries.
      Parameters:
      prefix - the prefix to set (default INT_).
    • setTimeToLive

      public void setTimeToLive(int timeToLive)
      Specify the time (in milliseconds) to expire dead-locks.
      Parameters:
      timeToLive - the time to expire dead-locks.
    • setTransactionManager

      public void setTransactionManager(PlatformTransactionManager transactionManager)
      Set a PlatformTransactionManager for operations. Otherwise, a primary PlatformTransactionManager bean is obtained from the application context.
      Parameters:
      transactionManager - the PlatformTransactionManager to use.
      Since:
      6.0
    • setApplicationContext

      public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
      Specified by:
      setApplicationContext in interface ApplicationContextAware
      Throws:
      BeansException
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • afterSingletonsInstantiated

      public void afterSingletonsInstantiated()
      Specified by:
      afterSingletonsInstantiated in interface SmartInitializingSingleton
    • close

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

      public void delete(String lock)
      Description copied from interface: LockRepository
      Remove a lock from this repository.
      Specified by:
      delete in interface LockRepository
      Parameters:
      lock - the lock to remove.
    • acquire

      public boolean acquire(String lock)
      Description copied from interface: LockRepository
      Acquire a lock for a key.
      Specified by:
      acquire in interface LockRepository
      Parameters:
      lock - the key for lock to acquire.
      Returns:
      acquired or not.
    • isAcquired

      public boolean isAcquired(String lock)
      Description copied from interface: LockRepository
      Check if a lock is held by this repository.
      Specified by:
      isAcquired in interface LockRepository
      Parameters:
      lock - the lock to check.
      Returns:
      acquired or not.
    • deleteExpired

      public void deleteExpired()
      Description copied from interface: LockRepository
      Remove all the expired locks.
      Specified by:
      deleteExpired in interface LockRepository
    • renew

      public boolean renew(String lock)
      Description copied from interface: LockRepository
      Renew the lease for a lock.
      Specified by:
      renew in interface LockRepository
      Parameters:
      lock - the lock to renew.
      Returns:
      renewed or not.