public class ReadWriteUpgradeLockManager extends ReadWriteLockManager
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.
ReadWriteUpgradeLock
checkThreshhold, DEFAULT_CHECK_THRESHHOLD, DEFAULT_TIMEOUT, effectiveGlobalTimeouts, globalLocks, globalOwners, globalTimeoutMSecs, logger, maxLockLevel, timedOutOwners
Constructor and Description |
---|
ReadWriteUpgradeLockManager(LoggerFacade logger,
long timeoutMSecs)
Creates a new read/write/upgrade lock manager.
|
Modifier and Type | Method and Description |
---|---|
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.
|
checkReadLock, checkWriteLock, hasReadLock, hasWriteLock, readLock, tryReadLock
addOwner, atomicGetOrCreateLock, checkLock, doLock, getAll, getLevel, getLock, getLocks, getNextGlobalConflictTimeout, hasLock, lock, lock, lock, release, releaseAll, releaseAllNoTimeOutReset, releaseTimedOutOwners, removeLock, removeOwner, removeOwnerWithoutLocks, startGlobalTimeout, timeOut, timeoutCheck, toString, tryLock, wouldDeadlock
public ReadWriteUpgradeLockManager(LoggerFacade logger, long timeoutMSecs)
logger
- generic logger used for all kind of debug loggingtimeoutMSecs
- specifies the maximum time to wait for a lock in millisecondspublic boolean tryUpgradeLock(Object ownerId, Object resourceId)
false
will be returned.ownerId
- a unique id identifying the entity that wants to acquire this
lockresourceId
- the resource to get the lock fortrue
if the lock has been acquired, false
otherwisepublic boolean tryWriteLock(Object ownerId, Object resourceId)
false
will be returned.tryWriteLock
in class ReadWriteLockManager
ownerId
- a unique id identifying the entity that wants to acquire this
lockresourceId
- the resource to get the lock fortrue
if the lock has been acquired, false
otherwisepublic void upgradeLock(Object ownerId, Object resourceId) throws LockException
ownerId
- a unique id identifying the entity that wants to acquire this
lockresourceId
- the resource to get the level forLockException
- will be thrown when the lock can not be acquiredpublic void writeLock(Object ownerId, Object resourceId) throws LockException
writeLock
in class ReadWriteLockManager
ownerId
- a unique id identifying the entity that wants to acquire this
lockresourceId
- the resource to get the level forLockException
- will be thrown when the lock can not be acquiredprotected GenericLock createLock(Object resourceId)
createLock
in class ReadWriteLockManager
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.