org.jboss.cache.util.concurrent.locks
Class PerElementLockContainer<E>

java.lang.Object
  extended by org.jboss.cache.util.concurrent.locks.PerElementLockContainer<E>
All Implemented Interfaces:
LockContainer<E>
Direct Known Subclasses:
PerElementOwnableReentrantLockContainer, PerElementReentrantLockContainer

public abstract class PerElementLockContainer<E>
extends Object
implements LockContainer<E>

A lock container that maintains a new lock per element

Since:
3.1.0
Author:
Manik Surtani

Field Summary
protected  ConcurrentMap<E,Lock> locks
           
 
Constructor Summary
protected PerElementLockContainer(int concurrencyLevel)
           
 
Method Summary
 void acquireLock(E object)
           
 boolean acquireLock(E object, long timeout, TimeUnit unit)
           
 Lock getLock(E object)
           
 int getNumLocksHeld()
           
protected abstract  Lock newLock()
           
 void releaseLock(E object)
           
 void reset()
          Clears all locks held and re-initialises stripes.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.cache.util.concurrent.locks.LockContainer
isLocked, ownsLock
 

Field Detail

locks

protected final ConcurrentMap<E,Lock> locks
Constructor Detail

PerElementLockContainer

protected PerElementLockContainer(int concurrencyLevel)
Method Detail

newLock

protected abstract Lock newLock()

getLock

public final Lock getLock(E object)
Specified by:
getLock in interface LockContainer<E>
Parameters:
object - object
Returns:
the lock for a specific object

getNumLocksHeld

public int getNumLocksHeld()
Specified by:
getNumLocksHeld in interface LockContainer<E>
Returns:
number of locks held

reset

public void reset()
Description copied from interface: LockContainer
Clears all locks held and re-initialises stripes.

Specified by:
reset in interface LockContainer<E>

size

public int size()
Specified by:
size in interface LockContainer<E>

acquireLock

public void acquireLock(E object)
Specified by:
acquireLock in interface LockContainer<E>

acquireLock

public boolean acquireLock(E object,
                           long timeout,
                           TimeUnit unit)
                    throws InterruptedException
Specified by:
acquireLock in interface LockContainer<E>
Throws:
InterruptedException

releaseLock

public void releaseLock(E object)
Specified by:
releaseLock in interface LockContainer<E>


Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.