java.lang.Object
xyz.ronella.trivial.decorator.CloseableLock
- All Implemented Interfaces:
AutoCloseable
A class that decorates an implementation of Lock to become AutoCloseable.
- Since:
- 2.9.0
-
Constructor Summary
ConstructorsConstructorDescriptionCloseableLock(Lock lock) Creates an instance of CloseableLock.CloseableLock(Lock lock, boolean noLockCall) Creates an instance of CloseableLock.CloseableLock(Lock lock, boolean noLockCall, BooleanSupplier lockOnlyWhen) Creates an instance of CloseableLock.CloseableLock(Lock lock, BooleanSupplier lockOnlyWhen) Creates an instance of CloseableLock. -
Method Summary
-
Constructor Details
-
CloseableLock
Creates an instance of CloseableLock. This constructor will call the lock method by default.- Parameters:
lock- An instance of Lock
-
CloseableLock
Creates an instance of CloseableLock. This constructor will call the lock method by default.- Parameters:
lock- An instance of LocklockOnlyWhen- The logic if lock will actually be needed.
-
CloseableLock
Creates an instance of CloseableLock.- Parameters:
lock- An instance of LocknoLockCall- When true the constructor will not call the lock method.
-
CloseableLock
Creates an instance of CloseableLock.- Parameters:
lock- An instance of LocknoLockCall- 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:
closein interfaceAutoCloseable
-