org.infinispan.util.concurrent.locks.containers
Class AbstractPerEntryLockContainer<L extends RefCountingLock>
java.lang.Object
org.infinispan.util.concurrent.locks.containers.AbstractLockContainer<L>
org.infinispan.util.concurrent.locks.containers.AbstractPerEntryLockContainer<L>
- All Implemented Interfaces:
- LockContainer<L>
- Direct Known Subclasses:
- OwnableReentrantPerEntryLockContainer, ReentrantPerEntryLockContainer
public abstract class AbstractPerEntryLockContainer<L extends RefCountingLock>
- extends AbstractLockContainer<L>
An abstract lock container that creates and maintains a new lock per entry
- Since:
- 4.0
- Author:
- Manik Surtani
locks
protected final ConcurrentHashMapV8<Object,L extends RefCountingLock> locks
AbstractPerEntryLockContainer
protected AbstractPerEntryLockContainer(int concurrencyLevel)
newLock
protected abstract L newLock()
getLock
public final L getLock(Object key)
- Parameters:
key
- object
- Returns:
- the lock for a specific object. May be null if the object is not locked, but may also be an unlocked lock.
getNumLocksHeld
public int getNumLocksHeld()
- Returns:
- number of locks held
size
public int size()
- Returns:
- the size of the shared lock pool
acquireLock
public L acquireLock(Object lockOwner,
Object key,
long timeout,
TimeUnit unit)
throws InterruptedException
- Description copied from interface:
LockContainer
- Attempts to acquire a lock for the given object within certain time boundaries defined by the timeout and
time unit parameters.
key
- Object to acquire lock ontimeout
- Time after which the lock acquisition will failunit
- Time unit of the given timeout
- Returns:
- If lock was acquired it returns the corresponding Lock object. If lock was not acquired, it returns null
- Throws:
InterruptedException
- If the lock acquisition was interrupted
releaseLock
public void releaseLock(Object lockOwner,
Object key)
- Description copied from interface:
LockContainer
- Release lock on the given key.
key
- Object on which lock is to be removed
getLockId
public int getLockId(Object key)
- Description copied from interface:
LockContainer
- Returns the 'id' of the lock that will be used to guard access to a given key in the cache. Particularly useful
if Lock Striping is used and locks may guard more than one key. This mechanism can be used to check whether
keys may end up sharing the same lock.
If lock-striping is not used, the identity hash code of the lock created for this specific key is returned, if the
key is locked, or -1 if the key is not locked and a lock does not exist for the key.
- Parameters:
key
- key to test for
- Returns:
- the ID of the lock.
toString
public String toString()
- Overrides:
toString
in class Object
Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.