Interface OptimisticLock
-
- All Known Implementing Classes:
SequenceLock
public interface OptimisticLockCreated by jcairns on 2/12/16.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description longreadLock()Aquire a lock token for readingbooleanreadLockHeld(long lockToken)check if optimistic locking succeededlongtryWriteLock()longtryWriteLock(long time, TimeUnit unit)longtryWriteLockInterruptibly()voidunlock(long sequence)"commit" or unlock the sequence when the write lock is heldlongwriteLock()Acquire the lock for writing, waiting if needed
-
-
-
Method Detail
-
readLock
long readLock()
Aquire a lock token for reading- Returns:
- long - the token indicating the lock state
-
readLockHeld
boolean readLockHeld(long lockToken)
check if optimistic locking succeeded- Parameters:
lockToken- - the value returned from tryLock- Returns:
- boolean - true if lock was held
-
writeLock
long writeLock()
Acquire the lock for writing, waiting if needed- Returns:
- long - the token indicating the lock state
-
tryWriteLockInterruptibly
long tryWriteLockInterruptibly() throws InterruptedException- Returns:
- long - the token indicating the lock state
- Throws:
InterruptedException- - on interrupt
-
tryWriteLock
long tryWriteLock()
- Returns:
- long - the token indicating the lock state, or 0 if not available
-
tryWriteLock
long tryWriteLock(long time, TimeUnit unit) throws InterruptedException- 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
-
unlock
void unlock(long sequence)
"commit" or unlock the sequence when the write lock is held- Parameters:
sequence- - lock sequence to unlock
-
-