Class DefaultLockManager
- All Implemented Interfaces:
LockManager
LockManager implementation for transactional and non-transactional caches.- Since:
- 8.0
- Author:
- Pedro Ruivo
-
Constructor Summary
Constructors -
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 viaLockManager.unlock(Object, Object),LockManager.unlockAll(Collection, Object), orLockManager.unlockAll(InvocationContext).intintintRetrieves 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 asLockManager.lock(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 asLockManager.unlock(Object, Object)but for multiple keys.unlockAll(InvocationContext context) Same asunlockAll(context.getLockedKeys(), context.getKeyLockOwner();.
-
Constructor Details
-
DefaultLockManager
public DefaultLockManager()
-
-
Method Details
-
lock
Description copied from interface:LockManagerAttempts 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().- Specified by:
lockin interfaceLockManager- 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
Description copied from interface:LockManagerSame asLockManager.lock(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.
- Specified by:
lockAllin interfaceLockManager- 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
Description copied from interface:LockManagerReleases the lock for thekeyif thelockOwneris the lock owner.Note this method will unlock a lock where the key is the lockOwner
- Specified by:
unlockin interfaceLockManager- 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
Description copied from interface:LockManagerSame asLockManager.unlock(Object, Object)but for multiple keys.Note this method will not unlock a lock where the key is the lockOwner
- Specified by:
unlockAllin interfaceLockManager- 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
Description copied from interface:LockManagerSame asunlockAll(context.getLockedKeys(), context.getKeyLockOwner();.Note this method will not unlock a lock where the key is the lockOwner
- Specified by:
unlockAllin interfaceLockManager- 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
Description copied from interface:LockManagerRegisters a listener that will be returned when the current lock owner releases its locks viaLockManager.unlock(Object, Object),LockManager.unlockAll(Collection, Object), orLockManager.unlockAll(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.
- Specified by:
addPostUnlockListenerin interfaceLockManager- Parameters:
key- the key that must be currently locked.listener- a supplier that produces aCompletionStageto be awaited after unlock.
-
ownsLock
Description copied from interface:LockManagerTests if thelockOwnerowns a lock on thekey.- Specified by:
ownsLockin interfaceLockManager- Parameters:
key- key to test.lockOwner- the owner of the lock.- Returns:
trueif the owner does own the lock on the key,falseotherwise.
-
isLocked
Description copied from interface:LockManagerTests if thekeyis locked.- Specified by:
isLockedin interfaceLockManager- Parameters:
key- key to test.- Returns:
trueif the key is locked,falseotherwise.
-
getOwner
Description copied from interface:LockManagerRetrieves the owner of the lock for thekey.- Specified by:
getOwnerin interfaceLockManager- Returns:
- the owner of the lock, or
nullif not locked.
-
printLockInfo
Description copied from interface:LockManagerPrints lock information for all locks.- Specified by:
printLockInfoin interfaceLockManager- Returns:
- the lock information
-
getNumberOfLocksHeld
@ManagedAttribute(description="The number of exclusive locks that are held.", displayName="Number of locks held") public int getNumberOfLocksHeld()- Specified by:
getNumberOfLocksHeldin interfaceLockManager- Returns:
- the number of locks held.
-
getConcurrencyLevel
@ManagedAttribute(description="The concurrency level that the MVCC Lock Manager has been configured with.", displayName="Concurrency level", dataType=TRAIT) public int getConcurrencyLevel() -
getNumberOfLocksAvailable
@ManagedAttribute(description="The number of exclusive locks that are available.", displayName="Number of locks available") public int getNumberOfLocksAvailable() -
getLock
- Specified by:
getLockin interfaceLockManager
-