Interface OptimisticLock
- All Known Implementing Classes:
SequenceLock
public interface OptimisticLock
Created by jcairns on 2/12/16.
-
Method Summary
Modifier and TypeMethodDescriptionlong
readLock()
Aquire a lock token for readingboolean
readLockHeld
(long lockToken) check if optimistic locking succeededlong
long
tryWriteLock
(long time, TimeUnit unit) long
void
unlock
(long sequence) "commit" or unlock the sequence when the write lock is heldlong
Acquire the lock for writing, waiting if needed
-
Method Details
-
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
- 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
- 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
-