Interface LockRegistry
- All Known Subinterfaces:
ExpirableLockRegistry
,RenewableLockRegistry
- All Known Implementing Classes:
DefaultLockRegistry
,HazelcastLockRegistry
,JdbcLockRegistry
,PassThruLockRegistry
,RedisLockRegistry
,ZookeeperLockRegistry
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Strategy for maintaining a registry of shared locks.
- Since:
- 2.1.1
- Author:
- Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T,
E extends Throwable>
TexecuteLocked
(Object lockKey, Duration waitLockDuration, CheckedCallable<T, E> callable) Perform the provided task when the lock for the key is locked.default <E extends Throwable>
voidexecuteLocked
(Object lockKey, Duration waitLockDuration, CheckedRunnable<E> runnable) Perform the provided task when the lock for the key is locked.default <T,
E extends Throwable>
TexecuteLocked
(Object lockKey, CheckedCallable<T, E> callable) Perform the provided task when the lock for the key is locked.default <E extends Throwable>
voidexecuteLocked
(Object lockKey, CheckedRunnable<E> runnable) Perform the provided task when the lock for the key is locked.Obtain the lock associated with the parameter object.
-
Method Details
-
obtain
Obtain the lock associated with the parameter object.- Parameters:
lockKey
- The object with which the lock is associated.- Returns:
- The associated lock.
-
executeLocked
default <E extends Throwable> void executeLocked(Object lockKey, CheckedRunnable<E> runnable) throws E, InterruptedException Perform the provided task when the lock for the key is locked.- Type Parameters:
E
- type of exception runnable throws- Parameters:
lockKey
- the lock key to userunnable
- theCheckedRunnable
to execute within a lock- Throws:
InterruptedException
- from a lock operationE extends Throwable
- Since:
- 6.2
-
executeLocked
default <T,E extends Throwable> T executeLocked(Object lockKey, CheckedCallable<T, E> callable) throws E, InterruptedExceptionPerform the provided task when the lock for the key is locked.- Type Parameters:
T
- type of callable resultE
- type of exception callable throws- Parameters:
lockKey
- the lock key to usecallable
- theCheckedCallable
to execute within a lock- Returns:
- the result of callable
- Throws:
InterruptedException
- from a lock operationE extends Throwable
- Since:
- 6.2
-
executeLocked
default <E extends Throwable> void executeLocked(Object lockKey, Duration waitLockDuration, CheckedRunnable<E> runnable) throws E, InterruptedException, TimeoutException Perform the provided task when the lock for the key is locked.- Type Parameters:
E
- type of exception runnable throws- Parameters:
lockKey
- the lock key to usewaitLockDuration
- theDuration
forLock.tryLock(long, TimeUnit)
runnable
- theCheckedRunnable
to execute within a lock- Throws:
InterruptedException
- from a lock operationTimeoutException
- whenLock.tryLock(long, TimeUnit)
has elapsedE extends Throwable
- Since:
- 6.2
-
executeLocked
default <T,E extends Throwable> T executeLocked(Object lockKey, Duration waitLockDuration, CheckedCallable<T, E> callable) throws E, InterruptedException, TimeoutExceptionPerform the provided task when the lock for the key is locked.- Type Parameters:
E
- type of exception callable throws- Parameters:
lockKey
- the lock key to usewaitLockDuration
- theDuration
forLock.tryLock(long, TimeUnit)
callable
- theCheckedCallable
to execute within a lock- Throws:
InterruptedException
- from a lock operationTimeoutException
- whenLock.tryLock(long, TimeUnit)
has elapsedE extends Throwable
- Since:
- 6.2
-