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 SafeCloseable
Acquire the lock viaLock.lock()
and return aSafeCloseable
that callsLock.unlock()
onSafeCloseable.close()
.default SafeCloseable
Acquire the lock viaLock.lockInterruptibly()
and return aSafeCloseable
that 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
- TheThrowingRunnable
to run- Throws:
EXCEPTION_TYPE
- Ifrunnable
throws 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
- Ifrunnable
throws 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
- TheThrowingSupplier
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 @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
- TheThrowingBooleanSupplier
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 @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
- TheThrowingSupplier
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
-
lockInterruptiblyCloseable
Acquire the lock viaLock.lockInterruptibly()
and return aSafeCloseable
that callsLock.unlock()
onSafeCloseable.close()
.- Returns:
- the safe closeable
- Throws:
InterruptedException
-