Package com.vaadin.hilla.signals
Class ValueSignal<T>
java.lang.Object
com.vaadin.hilla.signals.Signal<T>
com.vaadin.hilla.signals.ValueSignal<T>
- Direct Known Subclasses:
NumberSignal
-
Constructor Summary
ConstructorsConstructorDescriptionValueSignal(Class<T> valueType) Creates a new ValueSignal with provided valueType andnullas the default value.ValueSignal(T defaultValue, Class<T> valueType) Creates a new ValueSignal with the provided default value. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancompareAndSet(T newValue, T expectedValue) Compares the current value with the expected value and updates the signal value if they match.protected com.fasterxml.jackson.databind.node.ObjectNodeCreates a snapshot event reflecting the current state of the signal.getValue()Returns the signal's current value.protected booleanprocessEvent(com.fasterxml.jackson.databind.node.ObjectNode event) Processes the event and updates the signal value if needed.
-
Constructor Details
-
ValueSignal
Creates a new ValueSignal with the provided default value.- Parameters:
defaultValue- the default value, notnullvalueType- the value type class, notnull- Throws:
NullPointerException- if the default defaultValue or the valueType isnull
-
ValueSignal
Creates a new ValueSignal with provided valueType andnullas the default value.- Parameters:
valueType- the value type class, notnull- Throws:
NullPointerException- if the default defaultValue or the valueType isnull
-
-
Method Details
-
getValue
Returns the signal's current value.- Returns:
- the value
-
createSnapshotEvent
protected com.fasterxml.jackson.databind.node.ObjectNode createSnapshotEvent()Description copied from class:SignalCreates a snapshot event reflecting the current state of the signal.- Specified by:
createSnapshotEventin classSignal<T>- Returns:
- the snapshot event
-
processEvent
protected boolean processEvent(com.fasterxml.jackson.databind.node.ObjectNode event) Processes the event and updates the signal value if needed. Note that this method is not thread-safe and should be called from a synchronized context.- Specified by:
processEventin classSignal<T>- Parameters:
event- the event to process- Returns:
trueif the event was successfully processed and the signal value was updated,falseotherwise.
-
compareAndSet
Compares the current value with the expected value and updates the signal value if they match. Note that this method is not thread-safe and should be called from a synchronized context.- Parameters:
newValue- the new value to setexpectedValue- the expected value- Returns:
trueif the value was successfully updated,falseotherwise
-