Interface OptimisticLock

All Known Implementing Classes:
SequenceLock

public interface OptimisticLock
Created by jcairns on 2/12/16.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Aquire a lock token for reading
    boolean
    readLockHeld(long lockToken)
    check if optimistic locking succeeded
    long
     
    long
    tryWriteLock(long time, TimeUnit unit)
     
    long
     
    void
    unlock(long sequence)
    "commit" or unlock the sequence when the write lock is held
    long
    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

      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 lock
      unit - 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