Class LockingVisitors.LockVisitor<O,L>
java.lang.Object
org.apache.commons.lang3.concurrent.locks.LockingVisitors.LockVisitor<O,L>
- Type Parameters:
O- The wrapped object type.L- The wrapped lock type.
- Direct Known Subclasses:
LockingVisitors.ReadWriteLockVisitor, LockingVisitors.ReentrantLockVisitor, LockingVisitors.StampedLockVisitor
- Enclosing class:
LockingVisitors
Wraps a domain object and a lock for access by lambdas.
- Since:
- 3.11
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptReadLocked(FailableConsumer<O, ?> consumer) Invokes the consumer while holding the lock supplied for read operations.voidacceptWriteLocked(FailableConsumer<O, ?> consumer) Invokes the consumer while holding the lock supplied for write operations.<T> TapplyReadLocked(FailableFunction<O, T, ?> function) Applies the function while holding the lock supplied for read operations.<T> TapplyWriteLocked(FailableFunction<O, T, ?> function) Applies the function while holding the lock supplied for write operations.getLock()Gets the lock.Gets the guarded object.protected voidlockAcceptUnlock(Supplier<Lock> lockSupplier, FailableConsumer<O, ?> consumer) protected <T> TlockApplyUnlock(Supplier<Lock> lockSupplier, FailableFunction<O, T, ?> function) ImplementsapplyReadLocked(FailableFunction)andapplyWriteLocked(FailableFunction).
-
Constructor Details
-
LockVisitor
protected LockVisitor(O object, L lock, Supplier<Lock> readLockSupplier, Supplier<Lock> writeLockSupplier) Constructs an instance.- Parameters:
object- The object to guard.lock- The locking object.readLockSupplier- Supplies the lock used by read methods.writeLockSupplier- Supplies the lock used by write methods.
-
-
Method Details
-
acceptReadLocked
Invokes the consumer while holding the lock supplied for read operations. The lock is released in afinallyblock after the consumer returns or throws. Whether other readers can proceed concurrently depends on the supplied lock.- Parameters:
consumer- The consumer of the guarded object.- See Also:
-
acceptWriteLocked
Invokes the consumer while holding the lock supplied for write operations. The lock is released in afinallyblock after the consumer returns or throws.- Parameters:
consumer- The consumer of the guarded object.- See Also:
-
applyReadLocked
Applies the function while holding the lock supplied for read operations. The lock is released in afinallyblock after the function returns or throws. Whether other readers can proceed concurrently depends on the supplied lock.- Type Parameters:
T- The result type.- Parameters:
function- The function applied to the guarded object.- Returns:
- The function result.
- Throws:
NullPointerException- Thrown if the lock supplier is null or returns null.- See Also:
-
applyWriteLocked
Applies the function while holding the lock supplied for write operations. The lock is released in afinallyblock after the function returns or throws.- Type Parameters:
T- The result type.- Parameters:
function- The function applied to the guarded object.- Returns:
- The function result.
- Throws:
NullPointerException- Thrown if the lock supplier is null or returns null.- See Also:
-
getLock
-
getObject
-
lockAcceptUnlock
- Parameters:
lockSupplier- Supplies theLockto acquire and release, including aStampedLockview.consumer- The consumer of the guarded object.- See Also:
-
lockApplyUnlock
ImplementsapplyReadLocked(FailableFunction)andapplyWriteLocked(FailableFunction).- Type Parameters:
T- The result type.- Parameters:
lockSupplier- Supplies theLockto acquire and release, including aStampedLockview.function- The function applied to the guarded object.- Returns:
- The function result.
- Throws:
NullPointerException- Thrown if the lock supplier is null or returns null.- See Also:
-