org.exist.storage.lock
Class MultiReadReentrantLock

java.lang.Object
  extended byorg.exist.storage.lock.MultiReadReentrantLock
All Implemented Interfaces:
Lock

public class MultiReadReentrantLock
extends java.lang.Object
implements Lock

A reentrant read/write lock, which allows multiple readers to acquire a lock. Waiting writers are preferred. This is an adapted and bug-fixed version of code taken from Apache's Turbine JCS.


Field Summary
 
Fields inherited from interface org.exist.storage.lock.Lock
NO_LOCK, READ_LOCK, WRITE_LOCK
 
Constructor Summary
MultiReadReentrantLock()
          Default constructor.
 
Method Summary
 boolean acquire()
          Acquire a lock for read.
 boolean acquire(int mode)
          Acquire a lock for read or write.
 boolean attempt(int mode)
          Attempt to acquire a lock for read or write.
 boolean isLockedForWrite()
          Returns true if there are active or pending write locks.
 void release()
          Release a lock.
 void release(int mode)
          Release a lock of the specified type.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiReadReentrantLock

public MultiReadReentrantLock()
Default constructor.

Method Detail

acquire

public boolean acquire()
                throws LockException
Description copied from interface: Lock
Acquire a lock for read.

Specified by:
acquire in interface Lock
Throws:
LockException

acquire

public boolean acquire(int mode)
                throws LockException
Description copied from interface: Lock
Acquire a lock for read or write. mode is one of Lock.READ_LOCK or Lock.WRITE_LOCK.

Specified by:
acquire in interface Lock
Parameters:
mode -
Throws:
LockException

attempt

public boolean attempt(int mode)
Description copied from interface: Lock
Attempt to acquire a lock for read or write. This method will fail immediately if the lock cannot be acquired.

Specified by:
attempt in interface Lock
Parameters:
mode -

release

public void release()
Description copied from interface: Lock
Release a lock. This method assumes that the lock is a read lock.

Specified by:
release in interface Lock

release

public void release(int mode)
Description copied from interface: Lock
Release a lock of the specified type.

Specified by:
release in interface Lock
Parameters:
mode -

isLockedForWrite

public boolean isLockedForWrite()
Description copied from interface: Lock
Returns true if there are active or pending write locks.

Specified by:
isLockedForWrite in interface Lock


Copyright (C) Wolfgang Meier. All rights reserved.