| java.lang.Object org.apache.commons.transaction.locking.GenericLock org.apache.commons.transaction.locking.ReadWriteUpgradeLock
ReadWriteUpgradeLock | public class ReadWriteUpgradeLock extends GenericLock (Code) | | Convenience implementation of a read/write lock with an option for upgrade
based on
ReadWriteUpgradeLock .
Reads are shared which means there can be any number of concurrent read
accesses allowed by this lock. Writes are exclusive. This means when there is
a write access no other access neither read nor write are allowed by this
lock.
The idea (as explained by Jim LoVerde) on an upgrade lock 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.
Calls to
ReadWriteUpgradeLock.acquireRead(Object,long) ,
ReadWriteUpgradeLock.acquireUpgrade(Object,long) and
ReadWriteUpgradeLock.acquireWrite(Object,long) are blocking and reentrant. Blocking
means they will wait if they can not acquire the descired access, reentrant
means that a lock request by a specific owner will always be compatible with
other accesses on this lock by the same owner. E.g. if you already have a
lock for writing and you try to acquire write access again you will not be
blocked by this first lock, while others of course will be. This is the
natural way you already know from Java monitors and synchronized blocks.
version: $Id: ReadWriteUpgradeLock.java 493628 2007-01-07 01:42:48Z joerg $ See Also: GenericLock See Also: org.apache.commons.transaction.locking.ReadWriteLock See Also: ReadWriteUpgradeLockManager since: 1.1 |
Method Summary | |
public synchronized boolean | acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, boolean preferred, long timeoutMSecs) | public boolean | acquireRead(Object ownerId, long timeoutMSecs) Tries to acquire a blocking, reentrant read lock. | public boolean | acquireUpgrade(Object ownerId, long timeoutMSecs) Tries to acquire a reentrant upgrade lock on a resource. | public boolean | acquireWrite(Object ownerId, long timeoutMSecs) Tries to acquire a blocking, reentrant write lock. |
NO_LOCK | final public static int NO_LOCK(Code) | | |
READ_LOCK | final public static int READ_LOCK(Code) | | |
UPGRADE_LOCK | final public static int UPGRADE_LOCK(Code) | | |
WRITE_LOCK | final public static int WRITE_LOCK(Code) | | |
ReadWriteUpgradeLock | public ReadWriteUpgradeLock(Object resourceId, LoggerFacade logger)(Code) | | Creates a new read/write/upgrade lock.
Parameters: resourceId - identifier for the resource associated to this lock Parameters: logger - generic logger used for all kind of debug logging |
acquireRead | public boolean acquireRead(Object ownerId, long timeoutMSecs) throws InterruptedException(Code) | | Tries to acquire a blocking, reentrant read lock. A read lock is
compatible with other read locks, but not with a write lock.
Parameters: ownerId - a unique id identifying the entity that wants to acquire acertain lock level on this lock Parameters: timeoutMSecs - if blocking is enabled by the wait parameterthis specifies the maximum wait time in milliseconds true if the lock actually was acquired throws: InterruptedException - when the thread waiting on this method is interrupted |
acquireUpgrade | public boolean acquireUpgrade(Object ownerId, long timeoutMSecs) throws InterruptedException(Code) | | Tries to acquire a reentrant upgrade lock on a resource.
Parameters: ownerId - a unique id identifying the entity that wants to acquire acertain lock level on this lock Parameters: timeoutMSecs - if blocking is enabled by the wait parameterthis specifies the maximum wait time in milliseconds true if the lock actually was acquired throws: InterruptedException - when the thread waiting on this method is interrupted |
acquireWrite | public boolean acquireWrite(Object ownerId, long timeoutMSecs) throws InterruptedException(Code) | | Tries to acquire a blocking, reentrant write lock. A write lock is
incompatible with any another read or write lock and is thus exclusive.
Parameters: ownerId - a unique id identifying the entity that wants to acquire acertain lock level on this lock Parameters: timeoutMSecs - if blocking is enabled by the wait parameterthis specifies the maximum wait time in milliseconds true if the lock actually was acquired throws: InterruptedException - when the thread waiting on this method is interrupted |
Methods inherited from org.apache.commons.transaction.locking.GenericLock | public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, boolean reentrant, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean preferred, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public synchronized boolean acquire(Object ownerId, int targetLockLevel, boolean wait, int compatibility, boolean preferred, long timeoutMSecs) throws InterruptedException(Code)(Java Doc) public boolean equals(Object o)(Code)(Java Doc) protected Set getConflictingOwners(Object ownerId, int targetLockLevel, int compatibility)(Code)(Java Doc) protected Set getConflictingOwners(LockOwner myOwner, Collection ownersToTest)(Code)(Java Doc) protected Collection getConflictingWaiters(Object ownerId)(Code)(Java Doc) public int getLevelMaxLock()(Code)(Java Doc) public int getLevelMinLock()(Code)(Java Doc) public int getLockLevel(Object ownerId)(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner()(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner(LockOwner reentrantOwner, boolean preferred)(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner(int supportLockLevel, boolean preferred)(Code)(Java Doc) protected synchronized LockOwner getMaxLevelOwner(LockOwner reentrantOwner, int supportLockLevel, boolean preferred)(Code)(Java Doc) public Object getOwner()(Code)(Java Doc) public Object getResourceId()(Code)(Java Doc) public boolean has(Object ownerId, int lockLevel)(Code)(Java Doc) public int hashCode()(Code)(Java Doc) protected boolean isCompatible(int targetLockLevel, int currentLockLevel)(Code)(Java Doc) protected void registerWaiter(LockOwner waitingOwner)(Code)(Java Doc) public synchronized boolean release(Object ownerId)(Code)(Java Doc) protected synchronized void setLockLevel(Object ownerId, LockOwner lock, int targetLockLevel, int compatibility, boolean intention)(Code)(Java Doc) public boolean test(Object ownerId, int targetLockLevel, int compatibility)(Code)(Java Doc) public synchronized String toString()(Code)(Java Doc) protected boolean tryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred)(Code)(Java Doc) protected synchronized boolean tryLock(Object ownerId, int targetLockLevel, int compatibility, boolean preferred, boolean tryOnly)(Code)(Java Doc) protected void unregisterWaiter(LockOwner waitingOwner)(Code)(Java Doc)
|
|
|