public class DefaultLockManager extends Object implements LockManager
LockManager
implementation for transactional and non-transactional caches.Modifier and Type | Field and Description |
---|---|
protected Configuration |
configuration |
protected LockContainer |
lockContainer |
protected ScheduledExecutorService |
scheduler |
Constructor and Description |
---|
DefaultLockManager() |
Modifier and Type | Method and Description |
---|---|
int |
getConcurrencyLevel() |
InfinispanLock |
getLock(Object key) |
int |
getNumberOfLocksAvailable() |
int |
getNumberOfLocksHeld() |
Object |
getOwner(Object key)
Retrieves the owner of the lock for the
key . |
void |
inject(LockContainer container,
Configuration configuration,
ScheduledExecutorService executorService) |
boolean |
isLocked(Object key)
Tests if the
key is locked. |
KeyAwareLockPromise |
lock(Object key,
Object lockOwner,
long time,
TimeUnit unit)
Attempts to lock the
key if the lock isn't already held by the lockOwner . |
KeyAwareLockPromise |
lockAll(Collection<?> keys,
Object lockOwner,
long time,
TimeUnit unit)
Same as
LockManager.lock(Object, Object, long, TimeUnit) but for multiple keys. |
boolean |
ownsLock(Object key,
Object lockOwner)
Tests if the
lockOwner owns a lock on the key . |
String |
printLockInfo()
Prints lock information for all locks.
|
void |
unlock(Object key,
Object lockOwner)
Releases the lock for the
key if the lockOwner is the lock owner. |
void |
unlockAll(Collection<?> keys,
Object lockOwner)
Same as
LockManager.unlock(Object, Object) but for multiple keys. |
void |
unlockAll(InvocationContext context)
Same as
unlockAll(context.getLockedKeys(), context.getKeyLockOwner(); . |
protected LockContainer lockContainer
protected Configuration configuration
protected ScheduledExecutorService scheduler
public void inject(LockContainer container, Configuration configuration, ScheduledExecutorService executorService)
public KeyAwareLockPromise lock(Object key, Object lockOwner, long time, TimeUnit unit)
LockManager
key
if the lock isn't already held by the lockOwner
.
This method is non-blocking and return immediately a LockPromise
. The LockPromise
can (and should)
be used by the invoker to check when the lock is really acquired by invoking LockPromise.lock()
.
lock
in interface LockManager
key
- key to lock.lockOwner
- the owner of the lock.time
- the maximum time to wait for the lockunit
- the time unit of the time
argumentKeyAwareLockPromise
associated to this keys.public KeyAwareLockPromise lockAll(Collection<?> keys, Object lockOwner, long time, TimeUnit unit)
LockManager
LockManager.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.
lockAll
in interface LockManager
keys
- keys to lock.lockOwner
- the owner of the lock.time
- the maximum time to wait for the lockunit
- the time unit of the time
argumentKeyAwareLockPromise
associated to this keys.public void unlock(Object key, Object lockOwner)
LockManager
key
if the lockOwner
is the lock owner.unlock
in interface LockManager
key
- key to unlock.lockOwner
- the owner of the lock.public void unlockAll(Collection<?> keys, Object lockOwner)
LockManager
LockManager.unlock(Object, Object)
but for multiple keys.unlockAll
in interface LockManager
keys
- keys to unlock.lockOwner
- the owner of the lock.public void unlockAll(InvocationContext context)
LockManager
unlockAll(context.getLockedKeys(), context.getKeyLockOwner();
.unlockAll
in interface LockManager
context
- the context with the locked keys and the lock owner.public boolean ownsLock(Object key, Object lockOwner)
LockManager
lockOwner
owns a lock on the key
.ownsLock
in interface LockManager
key
- key to test.lockOwner
- the owner of the lock.true
if the owner does own the lock on the key, false
otherwise.public boolean isLocked(Object key)
LockManager
key
is locked.isLocked
in interface LockManager
key
- key to test.true
if the key is locked, false
otherwise.public Object getOwner(Object key)
LockManager
key
.getOwner
in interface LockManager
null
if not locked.public String printLockInfo()
LockManager
printLockInfo
in interface LockManager
public int getNumberOfLocksHeld()
getNumberOfLocksHeld
in interface LockManager
public int getConcurrencyLevel()
public int getNumberOfLocksAvailable()
public InfinispanLock getLock(Object key)
getLock
in interface LockManager
Copyright © 2020 JBoss, a division of Red Hat. All rights reserved.