org.entityfs.lock
Class AbstractReadWriteLockableProxy<T extends ReadWriteLockable>

java.lang.Object
  extended by org.entityfs.support.lang.ObjectProxySupport<T>
      extended by org.entityfs.lock.AbstractReadWriteLockableProxy<T>
All Implemented Interfaces:
Lockable, ReadLockable, ReadWriteLockable, WriteLockable

public abstract class AbstractReadWriteLockableProxy<T extends ReadWriteLockable>
extends ObjectProxySupport<T>
implements ReadWriteLockable

This abstract class can be used as a starting point for implementing a proxy for a ReadWriteLockable class. It implements all methods in the ReadWriteLockable interface.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
protected AbstractReadWriteLockableProxy(T proxied)
           
 
Method Summary
 EntityLock getReadLock()
          Get the read lock without locking it.
 EntityLock getWriteLock()
          Get the write lock without locking it.
 boolean isReadLockedByCurrentThread()
          Does the calling thread hold a read lock for this object? A write lock also qualifies as a read lock.
 boolean isWriteLockedByCurrentThread()
          Does the calling thread hold a write lock for the lockable object (this)?
 EntityLock lockForReading()
          Lock object for reading and return the lock.
 EntityLock lockForWriting()
          Lock the object for writing and return the lock.
 
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

AbstractReadWriteLockableProxy

protected AbstractReadWriteLockableProxy(T proxied)
Method Detail

getReadLock

public EntityLock getReadLock()
Description copied from interface: ReadLockable
Get the read lock without locking it.

This method always returns a lock, even if the object's file system is not locking or if the object is read only.

Specified by:
getReadLock in interface ReadLockable
Returns:
The lockable's read lock. This might be unlocked or locked by someone else.

getWriteLock

public EntityLock getWriteLock()
Description copied from interface: WriteLockable
Get the write lock without locking it.

This method always returns a lock, even if the object's file system is not locking or if the object is read only.

Specified by:
getWriteLock in interface WriteLockable
Returns:
The lockable's write lock. This might be unlocked or locked by someone else.

isReadLockedByCurrentThread

public boolean isReadLockedByCurrentThread()
Description copied from interface: ReadLockable
Does the calling thread hold a read lock for this object? A write lock also qualifies as a read lock.

Specified by:
isReadLockedByCurrentThread in interface ReadLockable
Returns:
true if the lockable object is read or write locked by the current thread.

isWriteLockedByCurrentThread

public boolean isWriteLockedByCurrentThread()
Description copied from interface: WriteLockable
Does the calling thread hold a write lock for the lockable object (this)?

Specified by:
isWriteLockedByCurrentThread in interface WriteLockable
Returns:
true if the lockable object is write locked by the current thread.

lockForReading

public EntityLock lockForReading()
Description copied from interface: ReadLockable
Lock object for reading and return the lock. How the lock is acquired is determined by the EntityLockAdapterFactory and LockAcquiringStrategy used. If this is called on an object that somehow is connected to an entity object, that entity's file system's entity lock adapter factory and lock acquiring strategy is used.

A read lock cannot be upgraded to a write lock (just like how Java's ReadWriteLock works).

For more discussions on locks and locking, see Entity and FileSystem.

This method always returns a lock, even if the object's file system is not locking or if the object is read only.

Specified by:
lockForReading in interface ReadLockable
Returns:
A locked read lock.

lockForWriting

public EntityLock lockForWriting()
Description copied from interface: WriteLockable
Lock the object for writing and return the lock. How the lock is acquired is determined by the EntityLockAdapterFactory and LockAcquiringStrategy used. If this is called on an object that is somehow connected to an Entity object, that entity's file systems' lock adapter factory and lock acquiring strategy is used. A write lock can be downgraded to a read lock (by calling ReadLockable.lockForReading() and then releasing the write lock).

An entity in a locking read only file system may still be locked for writing.

For more discussions on locks and locking, see Entity and FileSystem.

This method always returns a lock, even if the file system is not locking.

Specified by:
lockForWriting in interface WriteLockable
Returns:
A locked write lock.