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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault value for the table prefix property.static final intDefault value for the time-to-live property. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultLockRepository(DataSource dataSource) Constructor that initializes the client id that will be associated for all the locks persisted by the store instance to a randomUUID.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. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAcquire a lock for a key.voidvoidvoidclose()voidRemove a lock from this repository.voidRemove all the expired locks.booleanisAcquired(String lock) Check if a lock is held by this repository.booleanRenew the lease for a lock.voidsetApplicationContext(ApplicationContext applicationContext) voidSpecify the prefix for target database table used from queries.voidA unique grouping identifier for all locks persisted with this store.voidsetTimeToLive(int timeToLive) Specify the time (in milliseconds) to expire dead-locks.voidsetTransactionManager(PlatformTransactionManager transactionManager) Set aPlatformTransactionManagerfor operations.
-
Field Details
-
DEFAULT_TABLE_PREFIX
Default value for the table prefix property.- See Also:
-
DEFAULT_TTL
public static final int DEFAULT_TTLDefault value for the time-to-live property.- See Also:
-
-
Constructor Details
-
DefaultLockRepository
Constructor that initializes the client id that will be associated for all the locks persisted by the store instance to a randomUUID.- Parameters:
dataSource- theDataSourceused to maintain the lock repository.
-
DefaultLockRepository
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- theDataSourceused 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
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 toDEFAULT.- Parameters:
region- the region name to set
-
setPrefix
Specify the prefix for target database table used from queries.- Parameters:
prefix- the prefix to set (defaultINT_).
-
setTimeToLive
public void setTimeToLive(int timeToLive) Specify the time (in milliseconds) to expire dead-locks.- Parameters:
timeToLive- the time to expire dead-locks.
-
setTransactionManager
Set aPlatformTransactionManagerfor operations. Otherwise, a primaryPlatformTransactionManagerbean is obtained from the application context.- Parameters:
transactionManager- thePlatformTransactionManagerto use.- Since:
- 6.0
-
setApplicationContext
- Specified by:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiatedin interfaceSmartInitializingSingleton
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceLockRepository
-
delete
Description copied from interface:LockRepositoryRemove a lock from this repository.- Specified by:
deletein interfaceLockRepository- Parameters:
lock- the lock to remove.
-
acquire
Description copied from interface:LockRepositoryAcquire a lock for a key.- Specified by:
acquirein interfaceLockRepository- Parameters:
lock- the key for lock to acquire.- Returns:
- acquired or not.
-
isAcquired
Description copied from interface:LockRepositoryCheck if a lock is held by this repository.- Specified by:
isAcquiredin interfaceLockRepository- Parameters:
lock- the lock to check.- Returns:
- acquired or not.
-
deleteExpired
public void deleteExpired()Description copied from interface:LockRepositoryRemove all the expired locks.- Specified by:
deleteExpiredin interfaceLockRepository
-
renew
Description copied from interface:LockRepositoryRenew the lease for a lock.- Specified by:
renewin interfaceLockRepository- Parameters:
lock- the lock to renew.- Returns:
- renewed or not.
-