de.neteye.actioncache
Class ReaderWriterLock

java.lang.Object
  |
  +--de.neteye.actioncache.ReaderWriterLock

public class ReaderWriterLock
extends java.lang.Object

Class implementing a reader/writer lock with FIFO ordering.

Version:
$Revision: 1.2 $
Author:
Felix Gnass

Constructor Summary
ReaderWriterLock()
           
 
Method Summary
 void lockForReading()
          Aquire a read lock.
 void lockForWriting()
          Request the write lock.
 void releaseReaderLock()
          Release the read lock.
 void releaseWriterLock()
          Release the write lock.
 boolean tryLockForReading()
          Request a reader lock.
 boolean tryLockForWriting()
          Aquire a write lock (non-blocking).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReaderWriterLock

public ReaderWriterLock()
Method Detail

lockForReading

public void lockForReading()
Aquire a read lock. A call to this method will block until the current writer (if any) has finished.


tryLockForReading

public boolean tryLockForReading()
Request a reader lock.

Returns:
true if you can safely read from the source false otherwise

releaseReaderLock

public void releaseReaderLock()
Release the read lock.


lockForWriting

public void lockForWriting()
Request the write lock. The call blocks until a write operation can be performed safely. Write requests are guaranteed to be executed in the order received (FIFO). Pending read requests take precedence over all write requests.


tryLockForWriting

public boolean tryLockForWriting()
Aquire a write lock (non-blocking).


releaseWriterLock

public void releaseWriterLock()
Release the write lock.