Class SequenceLock
java.lang.Object
com.conversantmedia.util.concurrent.SequenceLock
- All Implemented Interfaces:
OptimisticLock
http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf
Created by jcairns on 2/12/16.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongreadLock()Aquire a lock token for readingbooleanreadLockHeld(long lockToken) check if optimistic locking succeededlonglongtryWriteLock(long time, TimeUnit unit) longvoidunlock(long sequence) "commit" or unlock the sequence when the write lock is heldlongAcquire the lock for writing, waiting if needed
-
Field Details
-
sequence
-
-
Constructor Details
-
SequenceLock
public SequenceLock()
-
-
Method Details
-
readLock
public long readLock()Description copied from interface:OptimisticLockAquire a lock token for reading- Specified by:
readLockin interfaceOptimisticLock- Returns:
- long - the token indicating the lock state
-
readLockHeld
public boolean readLockHeld(long lockToken) Description copied from interface:OptimisticLockcheck if optimistic locking succeeded- Specified by:
readLockHeldin interfaceOptimisticLock- Parameters:
lockToken- - the value returned from tryLock- Returns:
- boolean - true if lock was held
-
writeLock
public long writeLock()Description copied from interface:OptimisticLockAcquire the lock for writing, waiting if needed- Specified by:
writeLockin interfaceOptimisticLock- Returns:
- long - the token indicating the lock state
-
unlock
public void unlock(long sequence) Description copied from interface:OptimisticLock"commit" or unlock the sequence when the write lock is held- Specified by:
unlockin interfaceOptimisticLock- Parameters:
sequence- - lock sequence to unlock
-
tryWriteLock
public long tryWriteLock()- Specified by:
tryWriteLockin interfaceOptimisticLock- Returns:
- long - the token indicating the lock state, or 0 if not available
-
tryWriteLock
- Specified by:
tryWriteLockin interfaceOptimisticLock- Parameters:
time- The time to wait to obtain the lockunit- The units of time parameter- Returns:
- long - the token indicating the lock state, or 0 if not available
- Throws:
InterruptedException- on interrupt
-
tryWriteLockInterruptibly
- Specified by:
tryWriteLockInterruptiblyin interfaceOptimisticLock- Returns:
- long - the token indicating the lock state
- Throws:
InterruptedException- - on interrupt
-