Interface OptimisticLock

  • All Known Implementing Classes:
    SequenceLock

    public interface OptimisticLock
    Created by jcairns on 2/12/16.
    • 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
      • 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