T
- The type of the value of this expressionpublic abstract class LockingExpression<T> extends DependentExpression<T> implements Expression<T>
After mutation the held write lock should be downgraded to a read lock, then observers should be notified, then the read lock should be released.
A mutating operation is considered to be any method or section of code which
can be considered to atomically result in a change in the value of this
Expression
.
Constructor and Description |
---|
LockingExpression() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
beginWrite() |
protected HotObservable<Expression<? extends T>> |
createObservable() |
protected boolean |
endWrite() |
protected void |
fireChange() |
java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
getReadLock() |
T |
getValue()
This should always return the correct current value for this Expression.
|
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
getWriteLock() |
protected <U> U |
read(java.util.function.Supplier<U> read) |
addDependency, evaluate, getValueImpl
cancelChange, invalidations, isChanging, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
anonymize, decoupleValue, immutable, invalidations, over, over
protected <U> U read(java.util.function.Supplier<U> read)
protected boolean beginWrite()
beginWrite
in class ActiveExpression<T>
protected boolean endWrite()
endWrite
in class ActiveExpression<T>
public final T getValue()
Expression
Expression
, i.e. it should be either an immutable class, a const
reference, or a copy of the underlying value. This is important, but
conversely it does not mean that the return value can necessarily be
relied upon not to not mutate when this expression is updated, unless a read
lock is held.
Once a value has been returned, it is up to the implementing Expression as to
whether the value will be reliable such that it will remain the same even if
the conceptual value of this expression subsequently changes, or whether it
will update automatically with the expression. Please only rely on either
behavior if it is explicitly documented, otherwise use
Expression.decoupleValue()
if you need a persistent reference which is safe
to mutate and/or safe from external mutation.
The observers should only ever be notified of an update from the thread which
has the write lock on an Expression
, and Expression
s should
be careful to only notify observers when they are in a state where their
value can be fetched. Immediate fetch is discouraged, though. Expressions
should generally update lazily, not eagerly.
getValue
in interface Expression<T>
getValue
in class ActiveExpression<T>
public java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock getReadLock()
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock getWriteLock()
protected HotObservable<Expression<? extends T>> createObservable()
createObservable
in class ActiveExpression<T>
protected void fireChange()
fireChange
in class ActiveExpression<T>