Package io.deephaven.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(@NotNull ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) Acquire the lock, invokeThrowingSupplier.get()while holding the lock, and release the lock before returning the result.default <RESULT_TYPE,EXCEPTION_TYPE extends Exception>
RESULT_TYPEcomputeLockedInterruptibly(@NotNull ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) Acquire the lock interruptibly, invokeThrowingSupplier.get()while holding the lock, and release the lock before returning the result.default <EXCEPTION_TYPE extends Exception>
voiddoLocked(@NotNull ThrowingRunnable<EXCEPTION_TYPE> runnable) Acquire the lock, invokeThrowingRunnable.run()while holding the lock, and release the lock before returning.default <EXCEPTION_TYPE extends Exception>
voiddoLockedInterruptibly(@NotNull ThrowingRunnable<EXCEPTION_TYPE> runnable) Acquire the lock interruptibly, invokeThrowingRunnable.run()while holding the lock, and release the lock before returning.default SafeCloseableAcquire the lock viaLock.lock()and return aSafeCloseablethat callsLock.unlock()onSafeCloseable.close().default SafeCloseableAcquire the lock viaLock.lockInterruptibly()and return aSafeCloseablethat callsLock.unlock()onSafeCloseable.close().default <EXCEPTION_TYPE extends Exception>
booleantestLocked(@NotNull ThrowingBooleanSupplier<EXCEPTION_TYPE> supplier) Acquire the lock, invokeThrowingBooleanSupplier.getAsBoolean()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 @NotNull ThrowingRunnable<EXCEPTION_TYPE> runnable) throws EXCEPTION_TYPE Acquire the lock, invokeThrowingRunnable.run()while holding the lock, and release the lock before returning.- Parameters:
runnable- TheThrowingRunnableto run- Throws:
EXCEPTION_TYPE- Ifrunnablethrows its declared exception
-
doLockedInterruptibly
default <EXCEPTION_TYPE extends Exception> void doLockedInterruptibly(@NotNull @NotNull ThrowingRunnable<EXCEPTION_TYPE> runnable) throws InterruptedException, EXCEPTION_TYPE Acquire the lock interruptibly, invokeThrowingRunnable.run()while holding the lock, and release the lock before returning.- Parameters:
runnable- TheThrowingRunnable.run()to run- Throws:
InterruptedException- If the current thread was interrupted while waiting to acquire the lockEXCEPTION_TYPE- Ifrunnablethrows its declared exception
-
computeLocked
default <RESULT_TYPE,EXCEPTION_TYPE extends Exception> RESULT_TYPE computeLocked(@NotNull @NotNull ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPEAcquire the lock, invokeThrowingSupplier.get()while holding the lock, and release the lock before returning the result.- Parameters:
supplier- TheThrowingSupplierto get- Returns:
- The result of invoking
supplier - Throws:
EXCEPTION_TYPE- Ifsupplierthrows its declared exception
-
testLocked
default <EXCEPTION_TYPE extends Exception> boolean testLocked(@NotNull @NotNull ThrowingBooleanSupplier<EXCEPTION_TYPE> supplier) throws EXCEPTION_TYPE Acquire the lock, invokeThrowingBooleanSupplier.getAsBoolean()while holding the lock, and release the lock before returning the result.- Parameters:
supplier- TheThrowingBooleanSupplierto get- Returns:
- The result of invoking
supplier - Throws:
EXCEPTION_TYPE- Ifsupplierthrows its declared exception
-
computeLockedInterruptibly
default <RESULT_TYPE,EXCEPTION_TYPE extends Exception> RESULT_TYPE computeLockedInterruptibly(@NotNull @NotNull ThrowingSupplier<RESULT_TYPE, EXCEPTION_TYPE> supplier) throws InterruptedException, EXCEPTION_TYPEAcquire the lock interruptibly, invokeThrowingSupplier.get()while holding the lock, and release the lock before returning the result.- Parameters:
supplier- TheThrowingSupplierto get- Returns:
- The result of invoking
supplier - Throws:
InterruptedException- If the current thread was interrupted while waiting to acquire the lockEXCEPTION_TYPE- Ifsupplierthrows its declared exception
-
lockCloseable
Acquire the lock viaLock.lock()and return aSafeCloseablethat callsLock.unlock()onSafeCloseable.close().- Returns:
- the safe closeable
-
lockInterruptiblyCloseable
Acquire the lock viaLock.lockInterruptibly()and return aSafeCloseablethat callsLock.unlock()onSafeCloseable.close().- Returns:
- the safe closeable
- Throws:
InterruptedException
-