org.apache.commons.transaction.locking
Class ReadWriteLockManager

java.lang.Object
  extended by org.apache.commons.transaction.locking.GenericLockManager
      extended by org.apache.commons.transaction.locking.ReadWriteLockManager
All Implemented Interfaces:
LockManager, LockManager2
Direct Known Subclasses:
ReadWriteUpgradeLockManager

public class ReadWriteLockManager
extends GenericLockManager

Manager for ReadWriteLocks on resources.

Since:
1.1
Version:
$Revision$

Field Summary
 
Fields inherited from class org.apache.commons.transaction.locking.GenericLockManager
checkThreshhold, DEFAULT_CHECK_THRESHHOLD, DEFAULT_TIMEOUT, effectiveGlobalTimeouts, globalLocks, globalOwners, globalTimeoutMSecs, logger, maxLockLevel, timedOutOwners
 
Constructor Summary
protected ReadWriteLockManager(int maxLockLevel, LoggerFacade logger, long timeoutMSecs)
           
  ReadWriteLockManager(LoggerFacade logger, long timeoutMSecs)
          Creates a new read/write lock manager.
 
Method Summary
 boolean checkReadLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Determines if a shared, reentrant read lock on a resource could be acquired without actually acquiring it.
 boolean checkWriteLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Determines if an exclusive, reentrant write lock on a resource could be acquired without actually acquiring it.
protected  GenericLock createLock(java.lang.Object resourceId)
           
 boolean hasReadLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Determines if a shared, reentrant read lock on a resource is held by an owner.
 boolean hasWriteLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Determines if an exclusive, reentrant write lock on a resource is held by an owner.
 void readLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Tries to acquire a shared, reentrant read lock on a resource.
 boolean tryReadLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Tries to acquire a shared, reentrant read lock on a resource.
 boolean tryWriteLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Tries to acquire an exclusive, reentrant write lock on a resource.
 void writeLock(java.lang.Object ownerId, java.lang.Object resourceId)
          Tries to acquire an exclusive, reentrant write lock on a resource.
 
Methods inherited from class org.apache.commons.transaction.locking.GenericLockManager
addOwner, atomicGetOrCreateLock, checkLock, doLock, getAll, getLevel, getLock, getLocks, getNextGlobalConflictTimeout, hasLock, lock, lock, lock, release, releaseAll, releaseAllNoTimeOutReset, releaseTimedOutOwners, removeLock, removeOwner, startGlobalTimeout, timeOut, timeoutCheck, toString, tryLock, wouldDeadlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReadWriteLockManager

public ReadWriteLockManager(LoggerFacade logger,
                            long timeoutMSecs)
Creates a new read/write lock manager.

Parameters:
logger - generic logger used for all kind of debug logging
timeoutMSecs - specifies the maximum time to wait for a lock in milliseconds

ReadWriteLockManager

protected ReadWriteLockManager(int maxLockLevel,
                               LoggerFacade logger,
                               long timeoutMSecs)
                        throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException
Method Detail

tryReadLock

public boolean tryReadLock(java.lang.Object ownerId,
                           java.lang.Object resourceId)
Tries to acquire a shared, reentrant read lock on a resource.

This method does not block, but immediatly returns. If a lock is not available false will be returned.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the lock for
Returns:
true if the lock has been acquired, false otherwise

tryWriteLock

public boolean tryWriteLock(java.lang.Object ownerId,
                            java.lang.Object resourceId)
Tries to acquire an exclusive, reentrant write lock on a resource.

This method does not block, but immediatly returns. If a lock is not available false will be returned.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the lock for
Returns:
true if the lock has been acquired, false otherwise

checkReadLock

public boolean checkReadLock(java.lang.Object ownerId,
                             java.lang.Object resourceId)
Determines if a shared, reentrant read lock on a resource could be acquired without actually acquiring it.

This method does not block, but immediatly returns. If a lock is not available false will be returned.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the lock for
Returns:
true if the lock could be acquired, false otherwise

hasWriteLock

public boolean hasWriteLock(java.lang.Object ownerId,
                            java.lang.Object resourceId)
Determines if an exclusive, reentrant write lock on a resource is held by an owner.

Parameters:
ownerId - a unique id identifying the entity that wants to check this lock
resourceId - the resource to get the lock for
Returns:
true if the lock is held by the owner, false otherwise

hasReadLock

public boolean hasReadLock(java.lang.Object ownerId,
                           java.lang.Object resourceId)
Determines if a shared, reentrant read lock on a resource is held by an owner.

Parameters:
ownerId - a unique id identifying the entity that wants to check this lock
resourceId - the resource to get the lock for
Returns:
true if the lock is held by the owner, false otherwise

checkWriteLock

public boolean checkWriteLock(java.lang.Object ownerId,
                              java.lang.Object resourceId)
Determines if an exclusive, reentrant write lock on a resource could be acquired without actually acquiring it.

This method does not block, but immediatly returns. If a lock is not available false will be returned.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the lock for
Returns:
true if the lock could be acquired, false otherwise

readLock

public void readLock(java.lang.Object ownerId,
                     java.lang.Object resourceId)
              throws LockException
Tries to acquire a shared, reentrant read lock on a resource.

This method blocks and waits for the lock in case it is not avaiable. If there is a timeout or a deadlock or the thread is interrupted a LockException is thrown.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the lock for
Throws:
LockException - will be thrown when the lock can not be acquired

writeLock

public void writeLock(java.lang.Object ownerId,
                      java.lang.Object resourceId)
               throws LockException
Tries to acquire an exclusive, reentrant write lock on a resource.

This method blocks and waits for the lock in case it is not avaiable. If there is a timeout or a deadlock or the thread is interrupted a LockException is thrown.

Parameters:
ownerId - a unique id identifying the entity that wants to acquire this lock
resourceId - the resource to get the lock for
Throws:
LockException - will be thrown when the lock can not be acquired

createLock

protected GenericLock createLock(java.lang.Object resourceId)
Overrides:
createLock in class GenericLockManager


Copyright ? 2004 The Apache Software Foundation. All Rights Reserved.