|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.cache.lock.ReadWriteLockWithUpgrade
public class ReadWriteLockWithUpgrade
This class is similar to PreferredWriterReadWriteLock except that the read lock is upgradable to write lock. I.e., when a user calls upgradeLock(), it will release the read lock, wait for all the read locks to clear and obtain a write lock afterwards. In particular, the write lock is obtained with priority to prevent deadlock situation. The current design is based in part from Doug Lea's PreferredWriterReadWriteLock.
Note that the pre-requisite to use upgrade lock is the pre-existing of a read lock. Otherwise, a RuntimeException will be thrown.
Also note that currently lock can only be obtained through attempt
api with specified timeout instead acquire
is not supported.
Nested Class Summary | |
---|---|
protected class |
ReadWriteLockWithUpgrade.ReaderLock
|
protected class |
ReadWriteLockWithUpgrade.WriterLock
|
Field Summary | |
---|---|
protected java.lang.Thread |
activeWriter_
|
protected static java.lang.Object |
dummy_
|
protected static org.apache.commons.logging.Log |
log_
|
protected ReadWriteLockWithUpgrade.ReaderLock |
readerLock_
|
protected static java.util.Map<java.util.concurrent.locks.ReadWriteLock,java.lang.Object> |
upgraderLocal_
|
protected ReadWriteLockWithUpgrade.WriterLock |
writerLock_
|
Constructor Summary | |
---|---|
ReadWriteLockWithUpgrade()
|
Method Summary | |
---|---|
protected boolean |
allowReader()
Override this method to change to reader preference * |
protected void |
cancelledWaitingReader()
|
protected void |
cancelledWaitingWriter()
|
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller |
endRead()
Called upon termination of a read. |
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller |
endWrite()
Called upon termination of a write. |
protected java.util.concurrent.locks.Lock |
changeLock()
|
java.util.concurrent.locks.Lock |
readLock()
|
protected boolean |
startRead()
|
protected boolean |
startReadFromNewReader()
|
protected boolean |
startReadFromWaitingReader()
|
protected boolean |
startWrite()
|
protected boolean |
startWriteFromNewWriter()
|
protected boolean |
startWriteFromWaitingWriter()
|
java.lang.String |
toString()
|
java.util.concurrent.locks.Lock |
upgradeLockAttempt(long msecs)
Attempt to obtain an upgrade to writer lock. |
java.util.concurrent.locks.Lock |
writeLock()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.lang.Thread activeWriter_
protected static final java.util.Map<java.util.concurrent.locks.ReadWriteLock,java.lang.Object> upgraderLocal_
protected static final java.lang.Object dummy_
protected final ReadWriteLockWithUpgrade.ReaderLock readerLock_
protected final ReadWriteLockWithUpgrade.WriterLock writerLock_
protected static final org.apache.commons.logging.Log log_
Constructor Detail |
---|
public ReadWriteLockWithUpgrade()
Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.concurrent.locks.Lock writeLock()
writeLock
in interface java.util.concurrent.locks.ReadWriteLock
public java.util.concurrent.locks.Lock readLock()
readLock
in interface java.util.concurrent.locks.ReadWriteLock
public java.util.concurrent.locks.Lock upgradeLockAttempt(long msecs) throws UpgradeException
msecs
- Time to wait in millisecons.
UpgradeException
protected java.util.concurrent.locks.Lock changeLock()
protected void cancelledWaitingReader()
protected void cancelledWaitingWriter()
protected boolean allowReader()
protected boolean startRead()
protected boolean startWrite()
protected boolean startReadFromNewReader()
protected boolean startWriteFromNewWriter()
protected boolean startReadFromWaitingReader()
protected boolean startWriteFromWaitingWriter()
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller endRead()
protected org.jboss.cache.lock.ReadWriteLockWithUpgrade.Signaller endWrite()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |