Class OnChangeRTIndicator

All Implemented Interfaces:
ClockAware, Resettable, RTIndicator
Direct Known Subclasses:
WindowTimeRTIndicator

public class OnChangeRTIndicator extends AbstractDecorableIncrementalRTIndicator
Incremental indicator that fires change notifications to registered listeners whenever its value changes. Its StateStore is pluggable — see setStateStoreSupplier(Supplier) — and is only materialized when a listener is actually there to receive it. Events can be disabled via setEnableEvents(boolean).
  • Constructor Details

    • OnChangeRTIndicator

      public OnChangeRTIndicator()
    • OnChangeRTIndicator

      public OnChangeRTIndicator(RTIndicator indicator)
  • Method Details

    • setEnableEvents

      public void setEnableEvents(boolean enableEvents)
    • isEnableEvents

      public boolean isEnableEvents()
    • addOnChangeListener

      public void addOnChangeListener(OnChangeRTIndicator.OnChangeListener listener)
    • removeOnChangeListener

      public void removeOnChangeListener(OnChangeRTIndicator.OnChangeListener listener)
    • clearOnChangeListeners

      public void clearOnChangeListeners()
    • hasListeners

      protected boolean hasListeners()
      Returns:
      whether any listener is registered — the gate that decides if a store is needed at all
    • setStateStoreSupplier

      public void setStateStoreSupplier(@NonNull @NonNull Supplier<StateStore> stateStoreSupplier)
      Routes this indicator's state at an externally owned store, typically the one shared by every indicator of an instrument. The supplier is consulted lazily, on the events that actually write , so wiring an indicator up costs nothing until it has something to persist — which matters once the store behind it is a persistent backend rather than a map.
      Parameters:
      stateStoreSupplier - supplies the store to use instead of this indicator's own
    • getStateStore

      public StateStore getStateStore()
      Resolves this indicator's state store: the externally supplied one if setStateStoreSupplier(Supplier) was called, otherwise a private in-memory store created on demand. Single accessor on purpose — listeners and callers must never see different stores.
      Returns:
      the state store this indicator writes through (never null)
    • nextValue

      protected double nextValue(double prevValue, double newValue)
      Fires change notifications (if events are enabled) before delegating to the parent's nextValue computation. Subclasses like WindowTimeRTIndicator override event enablement to control notification timing.
      Overrides:
      nextValue in class AbstractDecorableIncrementalRTIndicator
      Parameters:
      prevValue - the previous indicator value (or last update value, depending on override)
      newValue - the new input value
      Returns:
      the computed indicator value
    • notifyOnChange

      protected void notifyOnChange(double prevValue, double newValue)
      Broadcasts the value change to all registered listeners, resolving the state store exactly once per event and handing it to each listener directly, so a listener body is its logic — no factory unwrapping. With no listeners registered nothing is resolved: the store stays uncreated .
      Parameters:
      prevValue - the previous indicator value
      newValue - the new indicator value
    • notifyOnChange

      protected void notifyOnChange(@NonNull @NonNull StateStore store, double prevValue, double newValue)
      Broadcasts with a store the caller already resolved, so an event that had to write state itself does not resolve twice.
      Parameters:
      store - the store to hand to every listener
      prevValue - the previous indicator value
      newValue - the new indicator value
    • toString

      protected com.google.common.base.MoreObjects.ToStringHelper toString(com.google.common.base.MoreObjects.ToStringHelper ts)
      Overrides:
      toString in class AbstractRTIndicator