Class UsageTracker

java.lang.Object
com.vaadin.flow.signals.impl.UsageTracker

public class UsageTracker extends Object
Tracks signal value read operations while a task is run.
  • Field Details

    • NO_USAGE

      public static final UsageTracker.Usage NO_USAGE
      A usage that doesn't have any changes and never fires any events.
  • Method Details

    • track

      public static UsageTracker.Usage track(SerializableRunnable task)
      Runs the given task while collecting all cases where a managed value is used.
      Parameters:
      task - the task to run, not null
      Returns:
      a usage instance that combines all used managed values, not null
    • track

      public static void track(SerializableRunnable task, UsageTracker.UsageRegistrar tracker)
      Runs the given task while reacting to all cases where a managed value is used.
      Parameters:
      task - the task to run, not null
      tracker - a consumer that receives all usages as they happen, not null
    • track

      public static <T> T track(Supplier<T> task, UsageTracker.UsageRegistrar tracker)
      Runs the given task with return value while reacting to all cases where a managed value is used.
      Type Parameters:
      T - the task return type
      Parameters:
      task - the task to run, not null
      tracker - a consumer that receives all usages as they happen, not null
      Returns:
      the value returned from the task
    • untracked

      public static <T extends @Nullable Object> T untracked(ValueSupplier<T> task)
      Runs the given supplier without tracking usage even if a usage tracker is active.
      Type Parameters:
      T - the supplier type
      Parameters:
      task - the supplier task to run, not null
      Returns:
      the value returned from the supplier
    • registerUsage

      public static void registerUsage(UsageTracker.Usage usage)
      Registers a usage with the current usage tracker. This method should be run only if usage tracking is active.
      Parameters:
      usage - the usage instance to register, not null
    • isGetAllowed

      public static boolean isGetAllowed()
      Checks whether calling Signal.get() is allowed in the current context. Returns true when a real usage tracker is active or when inside a deliberately untracked context (e.g. via Signal.untracked() or Signal.peek()).
      Returns:
      true if calling get() is allowed
    • isActive

      public static boolean isActive()
      Checks whether a usage tracker is currently active. Returns true only for real trackers, not the deliberately untracked sentinel.
      Returns:
      true if a usage tracker is active