Package com.vaadin.flow.signals.impl
Class UsageTracker
java.lang.Object
com.vaadin.flow.signals.impl.UsageTracker
Tracks signal value read operations while a task is run.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTracks the state of some used value.static interfaceReceives notifications about signal usage events. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UsageTracker.UsageA usage that doesn't have any changes and never fires any events. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisActive()Checks whether a usage tracker is currently active.static booleanChecks whether callingSignal.get()is allowed in the current context.static voidregisterUsage(UsageTracker.Usage usage) Registers a usage with the current usage tracker.static UsageTracker.Usagetrack(SerializableRunnable task) Runs the given task while collecting all cases where a managed value is used.static voidtrack(SerializableRunnable task, UsageTracker.UsageRegistrar tracker) Runs the given task while reacting to all cases where a managed value is used.static <T> Ttrack(Supplier<T> task, UsageTracker.UsageRegistrar tracker) Runs the given task with return value while reacting to all cases where a managed value is used.static <T extends @Nullable Object>
Tuntracked(ValueSupplier<T> task) Runs the given supplier without tracking usage even if a usage tracker is active.
-
Field Details
-
NO_USAGE
A usage that doesn't have any changes and never fires any events.
-
-
Method Details
-
track
Runs the given task while collecting all cases where a managed value is used.- Parameters:
task- the task to run, notnull- Returns:
- a usage instance that combines all used managed values, not
null
-
track
Runs the given task while reacting to all cases where a managed value is used.- Parameters:
task- the task to run, notnulltracker- a consumer that receives all usages as they happen, notnull
-
track
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, notnulltracker- a consumer that receives all usages as they happen, notnull- Returns:
- the value returned from the task
-
untracked
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, notnull- Returns:
- the value returned from the supplier
-
registerUsage
Registers a usage with the current usage tracker. This method should be run only if usage tracking isactive.- Parameters:
usage- the usage instance to register, notnull
-
isGetAllowed
public static boolean isGetAllowed()Checks whether callingSignal.get()is allowed in the current context. Returnstruewhen a real usage tracker is active or when inside a deliberately untracked context (e.g. viaSignal.untracked()orSignal.peek()).- Returns:
trueif callingget()is allowed
-
isActive
public static boolean isActive()Checks whether a usage tracker is currently active. Returnstrueonly for real trackers, not the deliberately untracked sentinel.- Returns:
trueif a usage tracker is active
-