Interface LockManager
-
- All Known Implementing Classes:
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description org.infinispan.util.concurrent.locks.impl.InfinispanLock
getLock(Object key)
int
getNumberOfLocksHeld()
Object
getOwner(Object key)
Retrieves the owner of the lock for thekey
.boolean
isLocked(Object key)
Tests if thekey
is locked.KeyAwareLockPromise
lock(Object key, Object lockOwner, long time, TimeUnit unit)
Attempts to lock thekey
if the lock isn't already held by thelockOwner
.KeyAwareLockPromise
lockAll(Collection<?> keys, Object lockOwner, long time, TimeUnit unit)
Same aslock(Object, Object, long, TimeUnit)
but for multiple keys.boolean
ownsLock(Object key, Object lockOwner)
Tests if thelockOwner
owns a lock on thekey
.String
printLockInfo()
Prints lock information for all locks.void
unlock(Object key, Object lockOwner)
Releases the lock for thekey
if thelockOwner
is the lock owner.void
unlockAll(Collection<?> keys, Object lockOwner)
Same asunlock(Object, Object)
but for multiple keys.void
unlockAll(InvocationContext context)
Same asunlockAll(context.getLockedKeys(), context.getKeyLockOwner();
.
-
-
-
Method Detail
-
lock
KeyAwareLockPromise lock(Object key, Object lockOwner, long time, TimeUnit unit)
Attempts to lock thekey
if the lock isn't already held by thelockOwner
.This method is non-blocking and return immediately a
LockPromise
. TheLockPromise
can (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 thetime
argument- Returns:
- the
KeyAwareLockPromise
associated to this keys.
-
lockAll
KeyAwareLockPromise lockAll(Collection<?> keys, Object lockOwner, long time, TimeUnit unit)
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 thetime
argument- Returns:
- the
KeyAwareLockPromise
associated to this keys.
-
unlock
void unlock(Object key, Object lockOwner)
Releases the lock for thekey
if thelockOwner
is 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
void unlockAll(Collection<?> keys, Object lockOwner)
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
void unlockAll(InvocationContext context)
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
boolean ownsLock(Object key, Object lockOwner)
Tests if thelockOwner
owns a lock on thekey
.- Parameters:
key
- key to test.lockOwner
- the owner of the lock.- Returns:
true
if the owner does own the lock on the key,false
otherwise.
-
isLocked
boolean isLocked(Object key)
Tests if thekey
is locked.- Parameters:
key
- key to test.- Returns:
true
if the key is locked,false
otherwise.
-
getOwner
Object getOwner(Object key)
Retrieves the owner of the lock for thekey
.- Returns:
- the owner of the lock, or
null
if 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
org.infinispan.util.concurrent.locks.impl.InfinispanLock getLock(Object key)
-
-