T
- The type of the value of this expressionpublic abstract class ActiveExpression<T> extends java.lang.Object implements Expression<T>
This implementation is appropriate for expressions which store their own
mutable state which can be changed independently of dependent expressions.
For expressions which do not store such state it should be more efficient to
extend PassiveExpression
.
Constructor and Description |
---|
ActiveExpression() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
beginWrite() |
protected void |
cancelChange() |
protected HotObservable<Expression<? extends T>> |
createObservable() |
protected boolean |
endWrite() |
protected void |
fireChange() |
T |
getValue()
This should always return the correct current value for this Expression.
|
protected abstract T |
getValueImpl(boolean dirty)
Implementing classes should compute the value of the
Expression here. |
Observable<Expression<? extends T>> |
invalidations() |
protected boolean |
isChanging() |
protected void |
write(java.lang.Runnable runnable) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
anonymize, decoupleValue, immutable, over, over
public Observable<Expression<? extends T>> invalidations()
invalidations
in interface Expression<T>
protected HotObservable<Expression<? extends T>> createObservable()
protected void cancelChange()
protected boolean isChanging()
protected void write(java.lang.Runnable runnable)
protected boolean beginWrite()
protected boolean endWrite()
protected void fireChange()
public 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>
protected abstract T getValueImpl(boolean dirty)
Expression
here.
Read lock is guaranteed to be obtained. This method should never be invoked
manually.dirty
- Whether the expression has been mutated since this method was last
invoked.Expression
.