Class CloseableLock

java.lang.Object
xyz.ronella.trivial.decorator.CloseableLock
All Implemented Interfaces:
AutoCloseable

public class CloseableLock extends Object implements AutoCloseable
A class that decorates an implementation of Lock to become AutoCloseable.
Since:
2.9.0
  • Constructor Details

    • CloseableLock

      public CloseableLock(Lock lock)
      Creates an instance of CloseableLock. This constructor will call the lock method by default.
      Parameters:
      lock - An instance of Lock
    • CloseableLock

      public CloseableLock(Lock lock, BooleanSupplier lockOnlyWhen)
      Creates an instance of CloseableLock. This constructor will call the lock method by default.
      Parameters:
      lock - An instance of Lock
      lockOnlyWhen - The logic if lock will actually be needed.
    • CloseableLock

      public CloseableLock(Lock lock, boolean noLockCall)
      Creates an instance of CloseableLock.
      Parameters:
      lock - An instance of Lock
      noLockCall - When true the constructor will not call the lock method.
    • CloseableLock

      public CloseableLock(Lock lock, boolean noLockCall, BooleanSupplier lockOnlyWhen)
      Creates an instance of CloseableLock.
      Parameters:
      lock - An instance of Lock
      noLockCall - When true the constructor will not call the lock method.
      lockOnlyWhen - The logic if lock will actually be needed.
  • Method Details

    • lock

      public void lock()
      Calls the lock method if the lockOnlyWhen returns true.
    • unlock

      public void unlock()
      Calls the unlock method if the lockOnlyWhen returns true.
    • close

      public void close()
      Calls the unlock method.
      Specified by:
      close in interface AutoCloseable