|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 Thread |
activeWriter_
|
protected static Object |
dummy_
|
protected static org.apache.commons.logging.Log |
log_
|
protected ReadWriteLockWithUpgrade.ReaderLock |
readerLock_
|
protected static Map<ReadWriteLock,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 Lock |
changeLock()
|
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. |
Lock |
readLock()
|
protected boolean |
startRead()
|
protected boolean |
startReadFromNewReader()
|
protected boolean |
startReadFromWaitingReader()
|
protected boolean |
startWrite()
|
protected boolean |
startWriteFromNewWriter()
|
protected boolean |
startWriteFromWaitingWriter()
|
String |
toString()
|
Lock |
upgradeLockAttempt(long msecs)
Attempt to obtain an upgrade to writer lock. |
Lock |
writeLock()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Thread activeWriter_
protected static final Map<ReadWriteLock,Object> upgraderLocal_
protected static final 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 String toString()
toString
in class Object
public Lock writeLock()
writeLock
in interface ReadWriteLock
public Lock readLock()
readLock
in interface ReadWriteLock
public Lock upgradeLockAttempt(long msecs) throws UpgradeException
msecs
- Time to wait in millisecons.
UpgradeException
protected 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 |