Class AutoLock<T extends Lock>

java.lang.Object
org.somda.sdc.common.util.AutoLock<T>
Type Parameters:
T - the lock type to auto-close.
All Implemented Interfaces:
AutoCloseable, Lock

public class AutoLock<T extends Lock> extends Object implements Lock, AutoCloseable
Converts locks to auto-closables.
  • Method Details

    • lock

      public static <T extends Lock> AutoLock<T> lock(T lock)
      Locks the given lock and return auto-closable variant.
      Type Parameters:
      T - type of the lock (write/read/common).
      Parameters:
      lock - the lock to wrap.
      Returns:
      an auto-closable instance to be used with try (...) { ... }.
    • getLock

      public T getLock()
      Returns the wrapped lock instance.
      Returns:
      the wrapped lock.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • lock

      public void lock()
      Specified by:
      lock in interface Lock
    • lockInterruptibly

      public void lockInterruptibly() throws InterruptedException
      Specified by:
      lockInterruptibly in interface Lock
      Throws:
      InterruptedException
    • tryLock

      public boolean tryLock()
      Specified by:
      tryLock in interface Lock
    • tryLock

      public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
      Specified by:
      tryLock in interface Lock
      Throws:
      InterruptedException
    • unlock

      public void unlock()
      Specified by:
      unlock in interface Lock
    • newCondition

      public Condition newCondition()
      Specified by:
      newCondition in interface Lock