Class SequenceLock
- java.lang.Object
-
- com.conversantmedia.util.concurrent.SequenceLock
-
- All Implemented Interfaces:
OptimisticLock
public class SequenceLock extends java.lang.Object implements OptimisticLock
http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf Created by jcairns on 2/12/16.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ContendedAtomicLong
sequence
-
Constructor Summary
Constructors Constructor Description SequenceLock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
readLock()
Aquire a lock token for readingboolean
readLockHeld(long lockToken)
check if optimistic locking succeededlong
tryWriteLock()
long
tryWriteLock(long time, java.util.concurrent.TimeUnit unit)
long
tryWriteLockInterruptibly()
void
unlock(long sequence)
"commit" or unlock the sequence when the write lock is heldlong
writeLock()
Acquire the lock for writing, waiting if needed
-
-
-
Field Detail
-
sequence
final ContendedAtomicLong sequence
-
-
Method Detail
-
readLock
public long readLock()
Description copied from interface:OptimisticLock
Aquire a lock token for reading- Specified by:
readLock
in interfaceOptimisticLock
- Returns:
- long - the token indicating the lock state
-
readLockHeld
public boolean readLockHeld(long lockToken)
Description copied from interface:OptimisticLock
check if optimistic locking succeeded- Specified by:
readLockHeld
in interfaceOptimisticLock
- Parameters:
lockToken
- - the value returned from tryLock- Returns:
- boolean - true if lock was held
-
writeLock
public long writeLock()
Description copied from interface:OptimisticLock
Acquire the lock for writing, waiting if needed- Specified by:
writeLock
in 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:
unlock
in interfaceOptimisticLock
- Parameters:
sequence
- - lock sequence to unlock
-
tryWriteLock
public long tryWriteLock()
- Specified by:
tryWriteLock
in interfaceOptimisticLock
- Returns:
- long - the token indicating the lock state, or 0 if not available
-
tryWriteLock
public long tryWriteLock(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
tryWriteLock
in 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:
java.lang.InterruptedException
- on interrupt
-
tryWriteLockInterruptibly
public long tryWriteLockInterruptibly() throws java.lang.InterruptedException
- Specified by:
tryWriteLockInterruptibly
in interfaceOptimisticLock
- Returns:
- long - the token indicating the lock state
- Throws:
java.lang.InterruptedException
- - on interrupt
-
-