Class AbstractLocalSignal<T extends @Nullable Object>

java.lang.Object
com.vaadin.flow.signals.local.AbstractLocalSignal<T>
Type Parameters:
T - the signal value type
All Implemented Interfaces:
Signal<T>, Serializable
Direct Known Subclasses:
ListSignal, ValueSignal

public abstract class AbstractLocalSignal<T extends @Nullable Object> extends Object implements Signal<T>
Base class for local signals providing shared listener notification, usage tracking, and value access logic.
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractLocalSignal(T initialValue)
    Creates a new signal with the given initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Asserts that the current thread holds the lock.
    protected void
    Hook for subclasses to perform precondition checks before accessing the value.
    get()
    Gets the current value of this signal.
    protected T
    Gets the current signal value.
    protected T
    Gets the current signal value without checking that the lock is held.
    protected void
    Acquires the lock.
    Reads the value without setting up any dependencies.
    protected void
    Sets the signal value and notifies all registered listeners.
    protected boolean
    Attempts to acquire the lock without blocking.
    protected void
    Releases the lock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.signals.Signal

    map
  • Constructor Details

    • AbstractLocalSignal

      protected AbstractLocalSignal(T initialValue)
      Creates a new signal with the given initial value.
      Parameters:
      initialValue - the initial value
  • Method Details

    • checkPreconditions

      protected void checkPreconditions()
      Hook for subclasses to perform precondition checks before accessing the value. Called while holding the lock. The base implementation verifies that the signal is not accessed from a different session than the one that first used it.
    • get

      public T get()
      Description copied from interface: Signal
      Gets the current value of this signal. The value is read in a way that takes the current transaction into account and in the case of clustering also changes that have been submitted to the cluster but not yet confirmed.

      If the signal implementation supports transactions, then reading the value in a regular (i.e. Transaction.Type.STAGED) transaction makes the transaction depend on the value so that the transaction fails in case the signal value is changed concurrently.

      Reading the value inside an Signal.unboundEffect(EffectAction) or Signal.computed(SignalComputation) callback sets up that effect or computed signal to depend on the signal.

      This method must only be called within a reactive context such as an effect, a computed signal, an explicit Signal.untracked(ValueSupplier) block, or a transaction. Calling it outside such a context throws an IllegalStateException. Use Signal.peek() for one-time reads that do not need dependency tracking.

      Specified by:
      get in interface Signal<T extends @Nullable Object>
      Returns:
      the signal value
    • peek

      public T peek()
      Description copied from interface: Signal
      Reads the value without setting up any dependencies. This method returns the same value as Signal.get() but without creating a dependency when used inside a transaction, effect or computed signal.

      Unlike Signal.get(), this method can be called outside a reactive context and is the recommended way to read a signal value for one-time use, such as logging, assertions, or initializing non-reactive UI.

      Specified by:
      peek in interface Signal<T extends @Nullable Object>
      Returns:
      the signal value
    • lock

      protected void lock()
      Acquires the lock. Must be followed by unlock() in a finally block.
    • unlock

      protected void unlock()
      Releases the lock.
    • tryLock

      protected boolean tryLock()
      Attempts to acquire the lock without blocking.
      Returns:
      true if the lock was acquired, false otherwise
    • assertLockHeld

      protected void assertLockHeld()
      Asserts that the current thread holds the lock.
    • getSignalValue

      protected T getSignalValue()
      Gets the current signal value. Must be called while holding the lock.
      Returns:
      the current value
    • getSignalValueUnsafe

      protected T getSignalValueUnsafe()
      Gets the current signal value without checking that the lock is held. Only use when the caller ensures thread-safety through other means.
      Returns:
      the current value
    • setSignalValue

      protected void setSignalValue(T value)
      Sets the signal value and notifies all registered listeners. Must be called while holding the lock.
      Parameters:
      value - the new value