Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.transaction.locking
Class ReadWriteUpgradeLockManager

    java.lang.Object
      org.apache.commons.transaction.locking.GenericLockManager
          org.apache.commons.transaction.locking.ReadWriteLockManager
              org.apache.commons.transaction.locking.ReadWriteUpgradeLockManager

All Implemented Interfaces:
  LockManager, LockManager2

public class ReadWriteUpgradeLockManager
extends ReadWriteLockManager

Manager for `ReadWriteUpgradeLock`s on resources.

The idea (as explained by Jim LoVerde) is that only one owner can hold an upgrade lock, but while that is held, it is possible for read locks to exist and/or be obtained, and when the request is made to upgrade to a write lock by the same owner, the lock manager prevents additional read locks until the write lock can be aquired.

In this sense the write lock becomes preferred over all other locks when it gets upgraded from a upgrate lock. Preferred means that if it has to wait and others wait as well it will be served before all other none preferred locking requests.

Since:
  1.1
Version:
  $Revision$
See Also:
  `ReadWriteUpgradeLock`

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
`ReadWriteUpgradeLockManager(LoggerFacade logger, long timeoutMSecs)` Creates a new read/write/upgrade lock manager.

Method Summary
`protected GenericLock` | `createLock(Object resourceId)`
`boolean` | `tryUpgradeLock(Object ownerId, Object resourceId)` Tries to acquire a reentrant upgrade lock on a resource.
`boolean` | `tryWriteLock(Object ownerId, Object resourceId)` Tries to acquire an exclusive, reentrant write lock on a resource.
`void` | `upgradeLock(Object ownerId, Object resourceId)` Tries to acquire a reentrant upgrade lock on a resource.
`void` | `writeLock(Object ownerId, Object resourceId)` Tries to acquire an exclusive, reentrant write lock on a resource.

Methods inherited from class org.apache.commons.transaction.locking.ReadWriteLockManager
`checkReadLock, checkWriteLock, hasReadLock, hasWriteLock, readLock, tryReadLock`

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

### ReadWriteUpgradeLockManager

    public ReadWriteUpgradeLockManager(LoggerFacade logger,
                                       long timeoutMSecs)

  Creates a new read/write/upgrade 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

Method Detail

### tryUpgradeLock

    public boolean tryUpgradeLock(Object ownerId,
                                  Object resourceId)

  Tries to acquire a reentrant upgrade 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(Object ownerId,
                                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.

  Overrides:
    `tryWriteLock` in class `ReadWriteLockManager`
  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

### upgradeLock

    public void upgradeLock(Object ownerId,
                            Object resourceId)
                     throws LockException

  Tries to acquire a reentrant upgrade 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 level for
  Throws:
    `LockException` - will be thrown when the lock can not be acquired

### writeLock

    public void writeLock(Object ownerId,
                          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.

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

### createLock

    protected GenericLock createLock(Object resourceId)

  Overrides:
    `createLock` in class `ReadWriteLockManager`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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