Package com.illumon.util.locks
Interface FunctionalLock
- All Superinterfaces:
Lock
- All Known Subinterfaces:
AwareFunctionalLock
- All Known Implementing Classes:
FunctionalReentrantLock
public interface FunctionalLock extends Lock
Extension to the
Lock
interface to enable locking for the duration of a lambda or other
FunctionalInterface
invocation.-
Method Summary
Modifier and Type Method Description default <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 <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 extends ExceptionAcquire 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 exceptionEXCEPTION_TYPE extends Exception
-
doLockedInterruptibly
default <EXCEPTION_TYPE extends Exception> void doLockedInterruptibly(@NotNull FunctionalInterfaces.ThrowingRunnable<EXCEPTION_TYPE> runnable) throws InterruptedException, EXCEPTION_TYPE extends ExceptionAcquire 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 exceptionEXCEPTION_TYPE extends Exception
-
computeLocked
default <RESULT_TYPE, EXCEPTION_TYPE extends Exception> RESULT_TYPE computeLocked(@NotNull FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE,EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPE extends ExceptionAcquire 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 exceptionEXCEPTION_TYPE extends Exception
-
testLocked
default <EXCEPTION_TYPE extends Exception> boolean testLocked(@NotNull FunctionalInterfaces.ThrowingBooleanSupplier<EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPE extends ExceptionAcquire 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 exceptionEXCEPTION_TYPE extends Exception
-
computeLockedInterruptibly
default <RESULT_TYPE, EXCEPTION_TYPE extends Exception> RESULT_TYPE computeLockedInterruptibly(@NotNull FunctionalInterfaces.ThrowingSupplier<RESULT_TYPE,EXCEPTION_TYPE> supplier) throws InterruptedException, EXCEPTION_TYPE extends ExceptionAcquire 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 exceptionEXCEPTION_TYPE extends Exception
-