Class SignalEnvironment

java.lang.Object
com.vaadin.signals.SignalEnvironment

public abstract class SignalEnvironment extends Object
The context in which signal operations are processed. Gives frameworks control over how application code is executed to allow acquiring relevant locks while running callbacks or to run potentially slow operations asynchronously without holding irrelevant locks. It is assumed that the environment is based on a ThreadLocal with regards to how results can be cached between invocations.
  • Constructor Details

    • SignalEnvironment

      public SignalEnvironment()
  • Method Details

    • isActive

      protected abstract boolean isActive()
      Checks whether this environment is active on the current thread. No other instance methods will be run while the environment is not active.
      Returns:
      true if this environment is active, false if it's inactive
    • getResultNotifier

      protected abstract Executor getResultNotifier()
      Gets an executor to use for asynchronously notifying about operation results. This method is run when an operation is submitted and the returned executor is used to notify of the results when the operation has been fully processed. The executor can thus be used to make sure the notification is delivered in the same context as where the operation was initiated. The notification is delivered immediately if no notifier is provided. It is recommended that the executor preserves ordering of submitted tasks within the same context so that notifications are delivered in the order that operations have been applied.
      Returns:
      an executor to use for notifying about operation results, or null to notify about results immediately
    • getEffectDispatcher

      protected abstract Executor getEffectDispatcher()
      Gets an executor to use for running the callback of an effect. This method is run when an effect is created and the returned executor is used for running the effect callback after any change has been detected. The executor can thus be used to make sure the effect callback is invoked in the same context as where the effect was created. It is recommended that the executor is asynchronous so that the thread that submitted the change can proceed without waiting for all affected effects to be dispatched. If no dispatcher is provided when an effect is created, then the effect callback will be run according to the getFallbackEffectDispatcher() of the environment that is active when a change is applied. This executor does not need to preserve ordering since the effect callback always uses the latest signal values without concern for in which order values have been changed.
      Returns:
      an executor to use for invoking effect callbacks, or null to use the fallback dispatcher
    • getFallbackEffectDispatcher

      protected abstract Executor getFallbackEffectDispatcher()
      Gets an executor to use for running the callback of an effect that doesn't have its own dispatcher. This method is run when applying any change to an effect that has no own dispatcher. The executor can thus be used to make effect callback invocations asynchronous rather than blocking the thread that applied the change until all affected effects have been processed. This executor does not need to preserve ordering since the effect callback always uses the latest signal values without concern for in which order values have been changed.
      Returns:
      the executor to use for invoking affected effects that don't have their own dispatcher, or null to invoke the callbacks immediately
    • register

      public static Runnable register(SignalEnvironment environment)
      Registers a signal environment to consider when processing signal operations. The environment should be unregistered using the returned callback when it's no longer needed.
      Parameters:
      environment - the environment to register, not null
      Returns:
      callback for unregistering the environment, not null
    • getCurrentResultNotifier

      public static Executor getCurrentResultNotifier()
      Queries currently active environments for an executor to use for notifying the results of an operation that is currently submitted. An immediate executor is returned if no executor is provided by registered environments.
      Returns:
      the executor to use, not null
      See Also:
    • getCurrentEffectDispatcher

      public static Executor getCurrentEffectDispatcher()
      Queries currently active environments for an executor to use for running the callbacks of an effect that is currently being created. If no registered environment provides an executor, then this method returns an executor that will delegate to the environment that is active when a change is applied and otherwise run the callback immediately.
      Returns:
      the executor to use, not null
      See Also: