org.entityfs.lock.impl.rw
Class ReadWriteEntityLockAdapter

java.lang.Object
  extended by org.entityfs.lock.impl.ReentrantLockAdapter
      extended by org.entityfs.lock.impl.rw.ReadWriteEntityLockAdapter
All Implemented Interfaces:
EntityLockAdapter, LockAdapter

public class ReadWriteEntityLockAdapter
extends ReentrantLockAdapter
implements EntityLockAdapter

This EntityLockAdapter uses a ReadLockOwnerAwareReentrantReadWriteLock for the lockable object's read and write lock and an EntityLockFactory for creating other locks.

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

Method Summary
 void createEntityLockForIdentifier(Object identifier, boolean readLock, boolean writeLock)
          This must be called before using a lock to ensure that it exists in the lock adapter.
 EntityLock getEntityLock(Object identifier)
          Get the lock identified by the identifier.
 EntityLock getReadLock()
          Get the entity's read lock.
 EntityLock getWriteLock()
           
 boolean isReadLockedByCurrentThread()
           
 boolean isWriteLockedByCurrentThread()
           
 
Methods inherited from class org.entityfs.lock.impl.ReentrantLockAdapter
createLockForIdentifier, getLock, getLockFactory, registerLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.entityfs.lock.LockAdapter
createLockForIdentifier, getLock
 

Method Detail

getReadLock

public EntityLock getReadLock()
Description copied from interface: EntityLockAdapter
Get the entity's read lock. This may or may not be the same lock as the entity's write lock, depending on the EntityLockAdapterFactory used by the file system.

Specified by:
getReadLock in interface EntityLockAdapter
Returns:
The entity's read lock.

getWriteLock

public EntityLock getWriteLock()
Specified by:
getWriteLock in interface EntityLockAdapter

isReadLockedByCurrentThread

public boolean isReadLockedByCurrentThread()
Specified by:
isReadLockedByCurrentThread in interface EntityLockAdapter

isWriteLockedByCurrentThread

public boolean isWriteLockedByCurrentThread()
Specified by:
isWriteLockedByCurrentThread in interface EntityLockAdapter

createEntityLockForIdentifier

public void createEntityLockForIdentifier(Object identifier,
                                          boolean readLock,
                                          boolean writeLock)
Description copied from interface: EntityLockAdapter
This must be called before using a lock to ensure that it exists in the lock adapter. It typically called by the lock-using object's constructor.

Locks created by calling this method can later be retrieved by calling EntityLockAdapter.getEntityLock(Object).

Specified by:
createEntityLockForIdentifier in interface EntityLockAdapter
Parameters:
identifier - An identifier that is unique for the lock-using object. This may be any kind of object, a static Object constant, for instance.
readLock - Is the lock a read lock? I.e., should the lock's isReadLock() method return true?
writeLock - Is the lock a write lock? I.e., should the lock's isWriteLock() method return true ?

getEntityLock

public EntityLock getEntityLock(Object identifier)
Description copied from interface: EntityLockAdapter
Get the lock identified by the identifier. The lock must have been defined by calling EntityLockAdapter.createEntityLockForIdentifier(Object, boolean, boolean) before it can be retrieved by this method.

Specified by:
getEntityLock in interface EntityLockAdapter
Parameters:
identifier - The identifier for the lock. The identifier for each defined lock is unique in the lock using object.
Returns:
The lock, or null if no lock is defined for the identifier.