Class ValueSignal<T>

java.lang.Object
com.vaadin.hilla.signals.Signal<T>
com.vaadin.hilla.signals.ValueSignal<T>
Direct Known Subclasses:
NumberSignal

public class ValueSignal<T> extends Signal<T>
  • Constructor Summary

    Constructors
    Constructor
    Description
    ValueSignal(Class<T> valueType)
    Creates a new ValueSignal with provided valueType and null as the default value.
    ValueSignal(T defaultValue, Class<T> valueType)
    Creates a new ValueSignal with the provided default value.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    compareAndSet(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.ObjectNode
    Creates a snapshot event reflecting the current state of the signal.
    Returns the signal's current value.
    protected boolean
    processEvent(com.fasterxml.jackson.databind.node.ObjectNode event)
    Processes the event and updates the signal value if needed.

    Methods inherited from class com.vaadin.hilla.signals.Signal

    equals, getId, getValueType, hashCode, submit, subscribe

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ValueSignal

      public ValueSignal(T defaultValue, Class<T> valueType)
      Creates a new ValueSignal with the provided default value.
      Parameters:
      defaultValue - the default value, not null
      valueType - the value type class, not null
      Throws:
      NullPointerException - if the default defaultValue or the valueType is null
    • ValueSignal

      public ValueSignal(Class<T> valueType)
      Creates a new ValueSignal with provided valueType and null as the default value.
      Parameters:
      valueType - the value type class, not null
      Throws:
      NullPointerException - if the default defaultValue or the valueType is null
  • Method Details

    • getValue

      @Nullable public T getValue()
      Returns the signal's current value.
      Returns:
      the value
    • createSnapshotEvent

      protected com.fasterxml.jackson.databind.node.ObjectNode createSnapshotEvent()
      Description copied from class: Signal
      Creates a snapshot event reflecting the current state of the signal.
      Specified by:
      createSnapshotEvent in class Signal<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:
      processEvent in class Signal<T>
      Parameters:
      event - the event to process
      Returns:
      true if the event was successfully processed and the signal value was updated, false otherwise.
    • compareAndSet

      protected boolean compareAndSet(T newValue, T expectedValue)
      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 set
      expectedValue - the expected value
      Returns:
      true if the value was successfully updated, false otherwise