- Type Parameters:
T- the type of data propagated to consumers
- All Superinterfaces:
Sensor
- 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,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>,PersistenceEvents.Deleted,PersistenceEvents.Inserted,PersistenceEvents.Updated,Signal<T>,State,Value<T>,ValueCollection<T,,C> ValueList<T>,ValueSet<T>
- All Known Implementing Classes:
AbstractComponentValue,AbstractObserver,AbstractTextComponentValue,AbstractValue,PropertyValue
Sensor
it extends, all of them in the order they were added.
This interface provides default method implementations that delegate to observer().
There are two ways to implement this interface:
- Extend
AbstractObserver- provides concrete implementations whereobserver()returnsthis - Implement
observer()to return a delegate - useful for wrapper types (seeObservablefor an example)
All implementations are thread-safe and support concurrent access.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceObserver.Builder<T,B extends Observer.Builder<T, B>> A base builder for adding listeners and consumers, extended by the builders of observable types; there is no factory for a standaloneObserverbuilder. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanaddConsumer(Consumer<? super T> consumer) Addsconsumerto thisObserver.default booleanaddWeakConsumer(Consumer<? super T> consumer) Uses aWeakReference, addingconsumerdoes not prevent it from being garbage collected.observer()Returns the underlyingObserverto which listener and consumer operations are delegated.default booleanremoveConsumer(Consumer<? super T> consumer) Removesconsumerfrom thisObserver, whether it was added viaaddConsumer(Consumer)oraddWeakConsumer(Consumer).default booleanremoveWeakConsumer(Consumer<? super T> consumer) Removesconsumerfrom thisObserver, whether it was added viaaddConsumer(Consumer)oraddWeakConsumer(Consumer).default Sensorsensor()An observer is its own sensor, viaobserver().Returns a new conditionalObservernotified when this observer instance is triggered with the given valueReturns a new conditionalObservernotified when this observer instance is triggered with a value satisfying the given predicate.Methods inherited from interface is.codion.common.reactive.sensor.Sensor
addListener, addWeakListener, removeListener, removeWeakListener
-
Method Details
-
addConsumer
Addsconsumerto thisObserver. Adding the same consumer a second time has no effect.- Parameters:
consumer- the consumer to add- Returns:
- true if this observer did not already contain the specified consumer
- Throws:
NullPointerException- in case consumer is null
-
removeConsumer
Removesconsumerfrom thisObserver, whether it was added viaaddConsumer(Consumer)oraddWeakConsumer(Consumer).- Parameters:
consumer- the consumer to remove- Returns:
- true if this observer contained the specified consumer
-
addWeakConsumer
Uses aWeakReference, addingconsumerdoes not prevent it from being garbage collected. Adding the same consumer a second time has no effect.Note: Dead weak references accumulate until cleaned up, which happens automatically when listeners or consumers are added or removed. To trigger cleanup manually without modifying them, call
removeWeakConsumer(Consumer)with any non-existing consumer:// Clean up dead weak references observer.removeWeakConsumer(data -> {});- Parameters:
consumer- the consumer- Returns:
- true if this observer did not already contain the specified consumer
-
removeWeakConsumer
Removesconsumerfrom thisObserver, whether it was added viaaddConsumer(Consumer)oraddWeakConsumer(Consumer).- Parameters:
consumer- the consumer to remove- Returns:
- true if this observer contained the specified consumer
-
when
Returns a new conditionalObservernotified when this observer instance is triggered with the given valueThe conditional observer subscribes to this one only while it has listeners or consumers of its own, attaching on the first and detaching on the last, so one that is never listened to - or whose listeners and consumers are all removed again - leaves nothing behind on this observer. Removing the last of them is therefore how a conditional observer is disposed of; there is nothing else to release.
- Parameters:
value- the value on which to trigger the observer- Returns:
- a new conditional
Observer
-
when
Returns a new conditionalObservernotified when this observer instance is triggered with a value satisfying the given predicate.The predicate is tested with each triggering value, including null, and must tolerate null input.
Subscribes to this observer only while it has listeners or consumers of its own, see
when(Object).- Parameters:
predicate- the predicate on which to trigger the observer- Returns:
- a new conditional
Observer
-
observer
Returns the underlyingObserverto which listener and consumer operations are delegated.For
AbstractObserversubclasses this method returnsthis. For wrapper types, this returns the delegate observer.- Returns:
- the
Observerhandling listener and consumer management
-
sensor
An observer is its own sensor, viaobserver().- Specified by:
sensorin interfaceSensor- Returns:
- the
Sensorhandling listener management, this observer'sobserver()
-