org.entityfs.lock.impl
Class EntityLockReentrantLockAdapterImpl

java.lang.Object
  extended by org.entityfs.support.lang.ObjectProxySupport<ReentrantLock>
      extended by org.entityfs.lock.impl.EntityLockReentrantLockAdapterImpl
All Implemented Interfaces:
Lock, EntityLock

public class EntityLockReentrantLockAdapterImpl
extends ObjectProxySupport<ReentrantLock>
implements EntityLock

This is an adapter to let a ReentrantLock implement the EntityLock interface. The adapter can be a read lock, a write lock or a lock that is both.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Constructor Summary
EntityLockReentrantLockAdapterImpl(boolean fair, Lockable locked, boolean readLock, boolean writeLock)
          Constructor.
 
Method Summary
 int getHoldCount()
          Get the hold count of the lock.
 Lockable getLocked()
          Get the locked object.
 boolean isDummy()
          Is this lock a dummy lock.
 boolean isHeldByCurrentThread()
          Is this lock held by the current thread? (This is implemented by ReentrantLock but not specified in the Lock interface.)
 boolean isReadLock()
          Returns true if this lock is a read lock.
 boolean isWriteLock()
          Returns true if this lock is a write lock.
 void lock()
           
 void lockInterruptibly()
           
 Condition newCondition()
           
 boolean tryLock()
           
 boolean tryLock(long timeout, TimeUnit unit)
           
 void unlock()
           
 
Methods inherited from class org.entityfs.support.lang.ObjectProxySupport
equals, getProxied, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EntityLockReentrantLockAdapterImpl

public EntityLockReentrantLockAdapterImpl(boolean fair,
                                          Lockable locked,
                                          boolean readLock,
                                          boolean writeLock)
Constructor.

Parameters:
fair - Should fair queuing be used when acquiring locks?
locked - The locked object.
readLock - Is this a read lock for the entity?
writeLock - Is this a write lock for the entity?
Method Detail

getLocked

public Lockable getLocked()
Description copied from interface: EntityLock
Get the locked object. For locks that are not connected to any particular object (dummy locks, mostly), this method returns null.

Specified by:
getLocked in interface EntityLock
Returns:
The locked object or null if this lock is not connected to any particular object.

isReadLock

public boolean isReadLock()
Description copied from interface: EntityLock
Returns true if this lock is a read lock.

Specified by:
isReadLock in interface EntityLock
Returns:
true if this is a read lock, false if it is a write lock.

isWriteLock

public boolean isWriteLock()
Description copied from interface: EntityLock
Returns true if this lock is a write lock.

Specified by:
isWriteLock in interface EntityLock
Returns:
true if this is a write lock, false if this is a read lock.

lock

public void lock()
Specified by:
lock in interface Lock

newCondition

public Condition newCondition()
Specified by:
newCondition in interface Lock

unlock

public void unlock()
Specified by:
unlock in interface Lock

isHeldByCurrentThread

public boolean isHeldByCurrentThread()
Description copied from interface: EntityLock
Is this lock held by the current thread? (This is implemented by ReentrantLock but not specified in the Lock interface.)

Specified by:
isHeldByCurrentThread in interface EntityLock
Returns:
true if this lock is locked by the current thread.

tryLock

public boolean tryLock()
Specified by:
tryLock in interface Lock

tryLock

public boolean tryLock(long timeout,
                       TimeUnit unit)
                throws InterruptedException
Specified by:
tryLock in interface Lock
Throws:
InterruptedException

getHoldCount

public int getHoldCount()
Description copied from interface: EntityLock
Get the hold count of the lock. (How many Lock.lock() has been called minus the number of times Lock.unlock() has been called by the current thread.) If the hold count is 0, the lock is unlocked. The hold count can never be less than 0.

Specified by:
getHoldCount in interface EntityLock
Returns:
The hold count of the lock

lockInterruptibly

public void lockInterruptibly()
                       throws InterruptedException
Specified by:
lockInterruptibly in interface Lock
Throws:
InterruptedException

isDummy

public boolean isDummy()
Description copied from interface: EntityLock
Is this lock a dummy lock. A dummy lock does not actually do any locking.

Specified by:
isDummy in interface EntityLock
Returns:
false, always.