Interface OptimisticLock
-
- All Known Implementing Classes:
SequenceLock
public interface OptimisticLock
Created by jcairns on 2/12/16.
-
-
Method Summary
All Methods Instance Methods Abstract 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
-
-
-
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 java.lang.InterruptedException
- Returns:
- long - the token indicating the lock state
- Throws:
java.lang.InterruptedException
- - on interrupt
-
tryWriteLock
long tryWriteLock()
- Returns:
- long - the token indicating the lock state, or 0 if not available
-
tryWriteLock
long tryWriteLock(long time, java.util.concurrent.TimeUnit unit) throws java.lang.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:
java.lang.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
-
-