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
public static class LockingVisitors.LockVisitor<O,L> extends java.lang.ObjectWraps a domain object and a lock for access by lambdas.- See Also:
LockingVisitors
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLockingVisitors.LockVisitor.LVBuilder<O,L,B extends LockingVisitors.LockVisitor.LVBuilder<O,L,B>>BuildsLockingVisitors.LockVisitorinstances.
-
Constructor Summary
Constructors Modifier Constructor Description protectedLockVisitor(O object, L lock, java.util.function.Supplier<java.util.concurrent.locks.Lock> readLockSupplier, java.util.function.Supplier<java.util.concurrent.locks.Lock> writeLockSupplier)Constructs an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacceptReadLocked(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.LgetLock()Gets the lock.OgetObject()Gets the guarded object.protected voidlockAcceptUnlock(java.util.function.Supplier<java.util.concurrent.locks.Lock> lockSupplier, FailableConsumer<O,?> consumer)protected <T> TlockApplyUnlock(java.util.function.Supplier<java.util.concurrent.locks.Lock> lockSupplier, FailableFunction<O,T,?> function)ImplementsapplyReadLocked(FailableFunction)andapplyWriteLocked(FailableFunction).
-
-
-
Constructor Detail
-
LockVisitor
protected LockVisitor(O object, L lock, java.util.function.Supplier<java.util.concurrent.locks.Lock> readLockSupplier, java.util.function.Supplier<java.util.concurrent.locks.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 Detail
-
acceptReadLocked
public void acceptReadLocked(FailableConsumer<O,?> consumer)
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(FailableConsumer),applyReadLocked(FailableFunction)
-
acceptWriteLocked
public void acceptWriteLocked(FailableConsumer<O,?> consumer)
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:
acceptReadLocked(FailableConsumer),applyWriteLocked(FailableFunction)
-
applyReadLocked
public <T> T applyReadLocked(FailableFunction<O,T,?> function)
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:
java.lang.NullPointerException- Thrown if the lock supplier is null or returns null.- See Also:
acceptReadLocked(FailableConsumer),applyWriteLocked(FailableFunction)
-
applyWriteLocked
public <T> T applyWriteLocked(FailableFunction<O,T,?> function)
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:
java.lang.NullPointerException- Thrown if the lock supplier is null or returns null.- See Also:
acceptWriteLocked(FailableConsumer),applyReadLocked(FailableFunction)
-
getLock
public L getLock()
Gets the lock.- Returns:
- The lock.
-
getObject
public O getObject()
Gets the guarded object.- Returns:
- The object.
-
lockAcceptUnlock
protected void lockAcceptUnlock(java.util.function.Supplier<java.util.concurrent.locks.Lock> lockSupplier, FailableConsumer<O,?> consumer)- Parameters:
lockSupplier- Supplies theLockto acquire and release, including aStampedLockview.consumer- The consumer of the guarded object.- See Also:
acceptReadLocked(FailableConsumer),acceptWriteLocked(FailableConsumer)
-
lockApplyUnlock
protected <T> T lockApplyUnlock(java.util.function.Supplier<java.util.concurrent.locks.Lock> lockSupplier, FailableFunction<O,T,?> function)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:
java.lang.NullPointerException- Thrown if the lock supplier is null or returns null.- See Also:
applyReadLocked(FailableFunction),applyWriteLocked(FailableFunction)
-
-