Interface LockManager
- All Known Implementing Classes:
DefaultLockManager,ExtendedStatisticLockManager,TopKeyLockManager
public interface LockManager
An interface to deal with all aspects of acquiring and releasing locks for cache entries.
- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org), Mircea.Markus@jboss.com, Pedro Ruivo
-
Method Summary
Modifier and TypeMethodDescriptionintRetrieves 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.voidReleases the lock for thekeyif thelockOwneris the lock owner.voidunlockAll(Collection<?> keys, Object lockOwner) Same asunlock(Object, Object)but for multiple keys.voidunlockAll(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.
-
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.
-
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.
-
ownsLock
Tests if thelockOwnerowns a lock on thekey.- Parameters:
key- key to test.lockOwner- the owner of the lock.- Returns:
trueif the owner does own the lock on the key,falseotherwise.
-
isLocked
Tests if thekeyis locked.- Parameters:
key- key to test.- Returns:
trueif the key is locked,falseotherwise.
-
getOwner
Retrieves the owner of the lock for thekey.- Returns:
- the owner of the lock, or
nullif not locked.
-
printLockInfo
String printLockInfo()Prints lock information for all locks.- Returns:
- the lock information
-
getNumberOfLocksHeld
int getNumberOfLocksHeld()- Returns:
- the number of locks held.
-
getLock
-