Package com.illumon.util.locks
Interface FunctionalLock
- All Superinterfaces:
Lock
- All Known Subinterfaces:
AwareFunctionalLock
- All Known Implementing Classes:
FunctionalReentrantLock
Extension to the
Lock
interface to enable locking for the duration of a lambda or other
FunctionalInterface
invocation.-
Method Summary
Modifier and TypeMethodDescriptiondefault <RESULT_TYPE,
EXCEPTION_TYPE extends Exception>
RESULT_TYPEcomputeLocked
(FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) Acquire the lock, invokeFunctionalInterfaces.ThrowingSupplier.get()
while holding the lock, and release the lock before returning the result.default <RESULT_TYPE,
EXCEPTION_TYPE extends Exception>
RESULT_TYPEcomputeLockedInterruptibly
(FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) Acquire the lock interruptibly, invokeFunctionalInterfaces.ThrowingSupplier.get()
while holding the lock, and release the lock before returning the result.default <EXCEPTION_TYPE extends Exception>
voiddoLocked
(FunctionalInterfaces.ThrowingRunnable<EXCEPTION_TYPE> runnable) Acquire the lock, invokeFunctionalInterfaces.ThrowingRunnable.run()
while holding the lock, and release the lock before returning.default <EXCEPTION_TYPE extends Exception>
voiddoLockedInterruptibly
(FunctionalInterfaces.ThrowingRunnable<EXCEPTION_TYPE> runnable) Acquire the lock interruptibly, invokeFunctionalInterfaces.ThrowingRunnable.run()
while holding the lock, and release the lock before returning.default SafeCloseable
Acquire the lock viaLock.lock()
and return aSafeCloseable
that callsLock.unlock()
onSafeCloseable.close()
.default <EXCEPTION_TYPE extends Exception>
booleantestLocked
(FunctionalInterfaces.ThrowingBooleanSupplier<EXCEPTION_TYPE> supplier) Acquire the lock, invokeFunctionalInterfaces.ThrowingBooleanSupplier.get()
while holding the lock, and release the lock before returning the result.Methods inherited from interface java.util.concurrent.locks.Lock
lock, lockInterruptibly, newCondition, tryLock, tryLock, unlock
-
Method Details
-
doLocked
default <EXCEPTION_TYPE extends Exception> void doLocked(@NotNull FunctionalInterfaces.ThrowingRunnable<EXCEPTION_TYPE> runnable) throws EXCEPTION_TYPE Acquire the lock, invokeFunctionalInterfaces.ThrowingRunnable.run()
while holding the lock, and release the lock before returning.- Parameters:
runnable
- TheFunctionalInterfaces.ThrowingRunnable
to run- Throws:
EXCEPTION_TYPE
- Ifrunnable
throws its declared exception
-
doLockedInterruptibly
default <EXCEPTION_TYPE extends Exception> void doLockedInterruptibly(@NotNull FunctionalInterfaces.ThrowingRunnable<EXCEPTION_TYPE> runnable) throws InterruptedException, EXCEPTION_TYPE Acquire the lock interruptibly, invokeFunctionalInterfaces.ThrowingRunnable.run()
while holding the lock, and release the lock before returning.- Parameters:
runnable
- TheFunctionalInterfaces.ThrowingRunnable.run()
to run- Throws:
InterruptedException
- If the current thread was interrupted while waiting to acquire the lockEXCEPTION_TYPE
- Ifrunnable
throws its declared exception
-
computeLocked
default <RESULT_TYPE,EXCEPTION_TYPE extends Exception> RESULT_TYPE computeLocked(@NotNull FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPEAcquire the lock, invokeFunctionalInterfaces.ThrowingSupplier.get()
while holding the lock, and release the lock before returning the result.- Parameters:
supplier
- TheFunctionalInterfaces.ThrowingSupplier
to get- Returns:
- The result of invoking
supplier
- Throws:
EXCEPTION_TYPE
- Ifsupplier
throws its declared exception
-
testLocked
default <EXCEPTION_TYPE extends Exception> boolean testLocked(@NotNull FunctionalInterfaces.ThrowingBooleanSupplier<EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPE Acquire the lock, invokeFunctionalInterfaces.ThrowingBooleanSupplier.get()
while holding the lock, and release the lock before returning the result.- Parameters:
supplier
- TheFunctionalInterfaces.ThrowingBooleanSupplier
to get- Returns:
- The result of invoking
supplier
- Throws:
EXCEPTION_TYPE
- Ifsupplier
throws its declared exception
-
computeLockedInterruptibly
default <RESULT_TYPE,EXCEPTION_TYPE extends Exception> RESULT_TYPE computeLockedInterruptibly(@NotNull FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) throws InterruptedException, EXCEPTION_TYPEAcquire the lock interruptibly, invokeFunctionalInterfaces.ThrowingSupplier.get()
while holding the lock, and release the lock before returning the result.- Parameters:
supplier
- TheFunctionalInterfaces.ThrowingSupplier
to get- Returns:
- The result of invoking
supplier
- Throws:
InterruptedException
- If the current thread was interrupted while waiting to acquire the lockEXCEPTION_TYPE
- Ifsupplier
throws its declared exception
-
lockCloseable
Acquire the lock viaLock.lock()
and return aSafeCloseable
that callsLock.unlock()
onSafeCloseable.close()
.- Returns:
- the safe closeable
-