com.vaadin.hilla.signals.

Class Signal<T>

java.lang.Object
com.vaadin.hilla.signals.Signal<T>

Direct Known Subclasses:

ListSignal, ValueSignal

public abstract class Signal<T> extends Object
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Signal(Signal<T> delegate)
     
    Signal(Class<T> valueType)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Signal<T>

    Returns a read-only instance of the signal that rejects any attempt to modify the signal value.

    protected abstract com.fasterxml.jackson.databind.node.ObjectNode

    Creates a snapshot event reflecting the current state of the signal.

    boolean
     
    protected Signal<T>
     

    Returns the signal UUID.

    Returns the signal value type.

    int
     
    protected abstract com.fasterxml.jackson.databind.node.ObjectNode
    processEvent(com.fasterxml.jackson.databind.node.ObjectNode event)

    Processes the event and updates the signal value if needed.

    static void
    setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)

    Sets the object mapper to be used for JSON serialization in Signals.

    void
    submit(com.fasterxml.jackson.databind.node.ObjectNode event)

    Submits an event to the signal and notifies subscribers about the change of the signal value.

    reactor.core.publisher.Flux<com.fasterxml.jackson.databind.node.ObjectNode>

    Subscribes to the signal.

    reactor.core.publisher.Flux<com.fasterxml.jackson.databind.node.ObjectNode>
    subscribe(String signalId)

    Subscribes to an internal child signal with a specific signal id.

    Methods inherited from class java.lang.Object

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

    • Signal

      public Signal(Class<T> valueType)
    • Signal

      protected Signal(Signal<T> delegate)
  • Method Details

    • getDelegate

      protected Signal<T> getDelegate()
    • getId

      public UUID getId()

      Returns the signal UUID.

      Returns:

      the id

    • getValueType

      public Class<T> getValueType()

      Returns the signal value type.

      Returns:

      the value type

    • subscribe

      public reactor.core.publisher.Flux<com.fasterxml.jackson.databind.node.ObjectNode> subscribe()

      Subscribes to the signal.

      Returns:

      a Flux of JSON events

    • subscribe

      public reactor.core.publisher.Flux<com.fasterxml.jackson.databind.node.ObjectNode> subscribe(String signalId)

      Subscribes to an internal child signal with a specific signal id.

      Parameters:

      signalId - the internal signal id

      Returns:

      a Flux of JSON events

    • submit

      public void submit(com.fasterxml.jackson.databind.node.ObjectNode event)

      Submits an event to the signal and notifies subscribers about the change of the signal value.

      Parameters:

      event - the event to submit

    • createSnapshotEvent

      protected abstract com.fasterxml.jackson.databind.node.ObjectNode createSnapshotEvent()

      Creates a snapshot event reflecting the current state of the signal.

      Returns:

      the snapshot event

    • processEvent

      protected abstract com.fasterxml.jackson.databind.node.ObjectNode 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.

      Parameters:

      event - the event to process

      Returns:

      true if the event was successfully processed and the signal value was updated, false otherwise.

    • asReadonly

      public abstract Signal<T> asReadonly()

      Returns a read-only instance of the signal that rejects any attempt to modify the signal value. The read-only signal, however, receives the same updates as the original signal does.

      Returns:

      the read-only signal

    • equals

      public boolean equals(Object o)

      Overrides:

      equals in class Object

    • hashCode

      public int hashCode()

      Overrides:

      hashCode in class Object

    • setMapper

      public static void setMapper(com.fasterxml.jackson.databind.ObjectMapper mapper)

      Sets the object mapper to be used for JSON serialization in Signals. This is helpful for testing purposes. If not set, the default Hilla endpoint object mapper is used.

      Note: If a custom endpointMapperFactory bean defined using the EndpointController.ENDPOINT_MAPPER_FACTORY_BEAN_QUALIFIER qualifier, the mapper from that factory is used also in Signals, and there is no need to set it manually here.

      Parameters:

      mapper - the object mapper to be used in Signals