All Known Subinterfaces:
CalendarPanel.CalendarDate, CalendarPanel.CalendarDateTime, CalendarPanel.CalendarZonedDateTime, ComponentValue<C,T>, EntityConditions.ConditionValue, EntityConditions.Modified, EntityEditor.EditorEntity, EntityEditor.EditorValue<T>, EntityEditor.Exists, EntityEditor.Modified, EntityEditor.Present, EntityTableTreeModel.UnreachableItems, Event, FilterModel.ExcludedItems<T>, FilterModel.IncludedItems<T>, FilterModel.IncludePredicate<T>, FilterTableColumnModel.ColumnSelection.ColumnIndex, FilterTableColumnModel.HiddenColumns<C>, FilterTableColumnModel.VisibleColumns<C>, FilterTableSearchModel.Results, FilterTableSearchModel.Results.CurrentResult, FilterTreeModel.VisibleNodes<T>, ImagePane.ImageValue, MultiSelection.Indexes, MultiSelection.Items<R>, Observable<T>, ObservableState, ObservableValueCollection<T,C>, ObservableValueList<T>, ObservableValueSet<T>, Observer<T>, PersistenceEvents.Deleted, PersistenceEvents.Inserted, PersistenceEvents.Updated, Signal<T>, State, Value<T>, ValueCollection<T,C>, ValueList<T>, ValueSet<T>
All Known Implementing Classes:
AbstractComponentValue, AbstractObserver, AbstractSensor, AbstractTextComponentValue, AbstractValue, PropertyValue

public interface Sensor
Manages listeners, notified each time something happens, without data.

An Observer is a sensor as well, its listeners notified along with its consumers, so anything that only needs to know that something happened can listen to an event, a signal, a value or a state alike.

This interface provides default method implementations that delegate to sensor(). There are two ways to implement this interface:

  • Extend AbstractSensor - provides concrete implementations where sensor() returns this
  • Implement sensor() to return a delegate - useful for wrapper types

All implementations are thread-safe and support concurrent access.

See Also:
  • Method Details

    • addListener

      default boolean addListener(Runnable listener)
      Adds listener to this Sensor. Adding the same listener a second time has no effect.

      Note that if the listener is already registered (whether strongly or via addWeakListener(java.lang.Runnable)) this returns false and retains the existing registration kind; it does not upgrade a weak registration to strong.

      Parameters:
      listener - the listener to add
      Returns:
      true if this sensor did not already contain the specified listener
      Throws:
      NullPointerException - in case listener is null
    • removeListener

      default boolean removeListener(Runnable listener)
      Removes listener from this Sensor, whether it was added via addListener(Runnable) or addWeakListener(Runnable).
      Parameters:
      listener - the listener to remove
      Returns:
      true if this sensor contained the specified listener
    • addWeakListener

      default boolean addWeakListener(Runnable listener)
      Uses a WeakReference, adding listener does not prevent it from being garbage collected. Adding the same listener a second time has no effect.

      Note: Dead weak references accumulate until cleaned up, which happens automatically when listeners are added or removed. To trigger cleanup manually without modifying the listener set, call removeWeakListener(Runnable) with any non-existing listener:

      // Clean up dead weak references
      sensor.removeWeakListener(() -> {});
      Parameters:
      listener - the listener
      Returns:
      true if this sensor did not already contain the specified listener
    • removeWeakListener

      default boolean removeWeakListener(Runnable listener)
      Removes listener from this Sensor, whether it was added via addListener(Runnable) or addWeakListener(Runnable).
      Parameters:
      listener - the listener to remove
      Returns:
      true if this sensor contained the specified listener
    • sensor

      Sensor sensor()
      Returns the underlying Sensor to which listener operations are delegated.

      For AbstractSensor and AbstractObserver subclasses this method returns this. For wrapper types, this returns the delegate sensor, and for an Observer implemented via Observer.observer(), its observer.

      Returns:
      the Sensor handling listener management