O - the wrapped object type.L - the wrapped lock type.public static class LockingVisitors.LockVisitor<O,L>
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
void |
acceptReadLocked(FailableConsumer<O,?> consumer)
Provides read (shared, non-exclusive) access to the locked (hidden) object.
|
void |
acceptWriteLocked(FailableConsumer<O,?> consumer)
Provides write (exclusive) access to the locked (hidden) object.
|
<T> T |
applyReadLocked(FailableFunction<O,T,?> function)
Provides read (shared, non-exclusive) access to the locked (hidden) object for the purpose of computing a
result object.
|
<T> T |
applyWriteLocked(FailableFunction<O,T,?> function)
Provides write (exclusive) access to the locked (hidden) object for the purpose of computing a result object.
|
L |
getLock()
Gets the lock.
|
O |
getObject()
Gets the guarded object.
|
public void acceptReadLocked(FailableConsumer<O,?> consumer)
consumer, passing the locked object as the parameter.consumer - The consumer, which is being invoked to use the hidden object, which will be passed as the
consumers parameter.acceptWriteLocked(FailableConsumer),
applyReadLocked(FailableFunction)public void acceptWriteLocked(FailableConsumer<O,?> consumer)
consumer, passing the locked object as the parameter.consumer - The consumer, which is being invoked to use the hidden object, which will be passed as the
consumers parameter.acceptReadLocked(FailableConsumer),
applyWriteLocked(FailableFunction)public <T> T applyReadLocked(FailableFunction<O,T,?> function)
function, passing the locked object as the parameter,
receiving the functions result.Example: Consider that the hidden object is a list, and we wish to know the current size of the list. This might be achieved with the following:
private Lock<List<Object>> listLock;
public int getCurrentListSize() {
final Integer sizeInteger = listLock.applyReadLocked((list) -> Integer.valueOf(list.size));
return sizeInteger.intValue();
}
T - The result type (both the functions, and this method's.)function - The function, which is being invoked to compute the result. The function will receive the
hidden object.java.lang.IllegalStateException - The result object would be, in fact, the hidden object. This would extend
access to the hidden object beyond this methods lifetime and will therefore be prevented.acceptReadLocked(FailableConsumer),
applyWriteLocked(FailableFunction)public <T> T applyWriteLocked(FailableFunction<O,T,?> function)
function, passing the locked object as the parameter,
receiving the functions result.T - The result type (both the functions, and this method's.)function - The function, which is being invoked to compute the result. The function will receive the
hidden object.java.lang.IllegalStateException - The result object would be, in fact, the hidden object. This would extend
access to the hidden object beyond this methods lifetime and will therefore be prevented.acceptReadLocked(FailableConsumer),
applyWriteLocked(FailableFunction)public L getLock()
public O getObject()
Copyright © 2010 - 2023 Adobe. All Rights Reserved