com.vaadin.signals.
Class ValueSignal<T>
Type Parameters:
T
- the signal value type
Direct Known Subclasses:
A signal containing a value. The value is updated as a single atomic change. It's recommended to use immutable values and this is partially enforced by the way a new instance is created from the underlying JSON data every time the value is read.
-
Field Summary
Fields inherited from class com.vaadin.signals.Signal
ANYTHING_GOES
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ValueSignal
(SignalTree tree, Id id, Predicate<SignalCommand> validator, Class<T> valueType) Creates a new value signal instance with the given id and validator for the given signal tree with the given value type.
ValueSignal
(Class<T> valueType) Creates a new value signal of the given type with no value.
ValueSignal
(T initialValue) Creates a new value signal with the given initial value.
-
Method Summary
Modifier and TypeMethodDescriptionasNode()
Converts this signal into a node signal.
Wraps this signal to not accept changes.
boolean
protected T
extractValue
(Node.Data data) Extracts the value for this signal from the given signal data node.
int
hashCode()
Sets the value of this signal if and only if the signal has the expected value at the time when the operation is confirmed.
toString()
update
(UnaryOperator<T> updater) Updates the signal value based on the given callback.
protected Object
usageChangeValue
(Node.Data data) Gets a reference value that will be used to determine whether a dependency based on previous usage should be invalidated.
Sets the value of this signal.
verifyValue
(T expectedValue) Checks that this signal has the expected value.
withValidator
(Predicate<SignalCommand> validator) Wraps this signal with a validator.
Methods inherited from class com.vaadin.signals.Signal
clear, computed, createUsage, data, data, effect, fromJson, id, map, mergeValidators, nodeValue, peek, peekConfirmed, remove, runInTransaction, runInTransaction, runWithoutTransaction, runWithoutTransaction, submit, submit, submit, submitInsert, submitVoidOperation, toJson, tree, untracked, validator, value
-
Constructor Details
-
ValueSignal
Creates a new value signal with the given initial value. The type of the signal will be based on the type (
Object.getClass()
) of the initial value instance. The signal does not support clustering.Parameters:
initialValue
- the initial value to use, notnull
-
ValueSignal
Creates a new value signal of the given type with no value. The signal does not support clustering.
Parameters:
valueType
- the value type, notnull
-
ValueSignal
protected ValueSignal(SignalTree tree, Id id, Predicate<SignalCommand> validator, Class<T> valueType) Creates a new value signal instance with the given id and validator for the given signal tree with the given value type.
Parameters:
tree
- the signal tree that contains the value for this signal, notnull
id
- the id of the signal node within the signal tree, notnull
validator
- the validator to check operations submitted to this singal, notnull
valueType
- the value type, notnull
-
-
Method Details
-
value
Sets the value of this signal. The result of the returned operation will be resolved with the previous value at the time when this operation was confirmed.
Parameters:
value
- the value to setReturns:
an operation containing the eventual result
-
extractValue
Description copied from class:
Signal
Extracts the value for this signal from the given signal data node.
Specified by:
extractValue
in classSignal<T>
Parameters:
data
- the data node to extract the value from, ornull
if the node doesn't exist in the treeReturns:
the signal value
-
usageChangeValue
Description copied from class:
Signal
Gets a reference value that will be used to determine whether a dependency based on previous usage should be invalidated. This is done by getting one reference value when the dependency occurs and then comparing that to the current value to determine if the value has changed.
The implementation should return an object that changes if and only if the
Signal.value()
of this signal changes.Specified by:
usageChangeValue
in classSignal<T>
Parameters:
data
- the data node to read from, notnull
Returns:
a reference value to use for validity checks, may be
null
-
replace
Sets the value of this signal if and only if the signal has the expected value at the time when the operation is confirmed. This is the signal counterpart to
AtomicReference.compareAndSet(Object, Object)
. The result of the returned operation will be resolved as successful if the expected value was present and resolved as unsuccessful if any other value was present when the operation is processed.Parameters:
expectedValue
- the expected valuenewValue
- the new valueReturns:
an operation containing the eventual result
-
update
Updates the signal value based on the given callback. The callback receives the current signal value and returns the new value to use. If the original value has changed by the time this change is confirmed, then the returned value is ignored and the callback is run again with the new value as input. This process is repeated until cancelled or until the update succeeds without conflicting changes.
The process can be cancelled through the returned operation instance. Note that canceling will only prevent further retries but the change will still be made if the currently running attempt succeeds.
The result of the returned operation will be resolved with the previous value at the time when a successful update operation was confirmed.
Update operations cannot participate in transactions since any retry would occur after the original transaction has already been committed. For this reason, the whole operation completely bypasses all transaction handling.
Parameters:
updater
- the value update callback, notnull
Returns:
an operation containing the eventual result
-
verifyValue
Checks that this signal has the expected value. This operation is only meaningful to use as a condition in a
transaction
. The result of the returned operation will be resolved as successful if the expected value was present and resolved as unsuccessful if any other value was present when the operation is processed.Parameters:
expectedValue
- the expected valueReturns:
an operation containing the eventual result
-
withValidator
Wraps this signal with a validator. The validator is used to check all value changing commands issued through the new signal instance. If this signal has a validator, then the new signal will use both validators. Note that due to the way validators are retained by
asNode()
, there's a possibility that the validator also receives commands that cannot be directly issued for a value signal.This signal will keep its current configuration and changes applied through this instance will be visible through the wrapped instance.
Parameters:
validator
- the validator to use, notnull
Returns:
a new value signal that uses the validator, not
null
-
asReadonly
Wraps this signal to not accept changes.
This signal will keep its current configuration and changes applied through this instance will be visible through the wrapped instance.
Returns:
the new readonly value signal, not
null
-
asNode
Description copied from class:
Signal
Converts this signal into a node signal. This allows further conversion into any specific signal type through the methods in
NodeSignal
. The converted signal is backed by the same underlying data and uses the same validator as this signal. -
equals
-
hashCode
public int hashCode() -
toString
-