Interface LockManager
- All Known Implementing Classes:
DefaultLockManager
- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org), Mircea.Markus@jboss.com, Pedro Ruivo
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPostUnlockListener(Object key, Supplier<CompletionStage<Void>> listener) Registers a listener that will be returned when the current lock owner releases its locks viaunlock(Object, Object),unlockAll(Collection, Object), orunlockAll(InvocationContext).intRetrieves the owner of the lock for thekey.booleanTests if thekeyis locked.Attempts to lock thekeyif the lock isn't already held by thelockOwner.lockAll(Collection<?> keys, Object lockOwner, long time, TimeUnit unit) Same aslock(Object, Object, long, TimeUnit)but for multiple keys.booleanTests if thelockOwnerowns a lock on thekey.Prints lock information for all locks.Releases the lock for thekeyif thelockOwneris the lock owner.unlockAll(Collection<?> keys, Object lockOwner) Same asunlock(Object, Object)but for multiple keys.unlockAll(InvocationContext context) Same asunlockAll(context.getLockedKeys(), context.getKeyLockOwner();.
-
Method Details
-
lock
Attempts to lock thekeyif the lock isn't already held by thelockOwner.This method is non-blocking and return immediately a
LockPromise. TheLockPromisecan (and should) be used by the invoker to check when the lock is really acquired by invokingLockPromise.lock().- Parameters:
key- key to lock.lockOwner- the owner of the lock.time- the maximum time to wait for the lockunit- the time unit of thetimeargument- Returns:
- the
KeyAwareLockPromiseassociated to this keys.
-
lockAll
Same aslock(Object, Object, long, TimeUnit)but for multiple keys.It ensures no deadlocks if the method is invoked by different lock owners for the same set (or subset) of keys.
- Parameters:
keys- keys to lock.lockOwner- the owner of the lock.time- the maximum time to wait for the lockunit- the time unit of thetimeargument- Returns:
- the
KeyAwareLockPromiseassociated to this keys.
-
unlock
Releases the lock for thekeyif thelockOwneris the lock owner.Note this method will unlock a lock where the key is the lockOwner
- Parameters:
key- key to unlock.lockOwner- the owner of the lock.- Returns:
- any post-unlock listener suppliers that were registered for the lock owner.
-
unlockAll
Same asunlock(Object, Object)but for multiple keys.Note this method will not unlock a lock where the key is the lockOwner
- Parameters:
keys- keys to unlock.lockOwner- the owner of the lock.- Returns:
- any post-unlock listener suppliers that were registered for the unlocked keys.
-
unlockAll
Same asunlockAll(context.getLockedKeys(), context.getKeyLockOwner();.Note this method will not unlock a lock where the key is the lockOwner
- Parameters:
context- the context with the locked keys and the lock owner.- Returns:
- any post-unlock listener suppliers that were registered for the unlocked keys.
-
addPostUnlockListener
Registers a listener that will be returned when the current lock owner releases its locks viaunlock(Object, Object),unlockAll(Collection, Object), orunlockAll(InvocationContext).The key must currently be locked. If it is not, an
IllegalStateExceptionis thrown. The listener is associated with the current lock owner and will only be returned when that owner's locks are released.Note: registered listeners are not invoked when the operation that acquired the lock completes with an exception. In that case, the listeners are still drained from the map but are discarded by the interceptor chain.
- Parameters:
key- the key that must be currently locked.listener- a supplier that produces aCompletionStageto be awaited after unlock.- Throws:
IllegalStateException- if the key is not currently locked.
-
ownsLock
-
isLocked
Tests if thekeyis locked.- Parameters:
key- key to test.- Returns:
trueif the key is locked,falseotherwise.
-
getOwner
-
printLockInfo
-
getNumberOfLocksHeld
int getNumberOfLocksHeld()- Returns:
- the number of locks held.
-
getLock
-