Class ObservableBase<O,T>
java.lang.Object
org.reactfx.ObservableBase<O,T>
- Type Parameters:
O- type of the observerT- type of produced values
- All Implemented Interfaces:
Observable<O>, ProperObservable<O,T>
- Direct Known Subclasses:
EventStreamBase, LiveListBase, SuspendableBase, SuspenderBase, ValBase
Base class for observable objects. This abstract class implements:
- Observer management: adding and removing observers.
- Lazy binding to inputs. An observable has 0 or more inputs, most commonly, but not necessarily, other observables. Lazy binding to inputs means that the observable observes its inputs only when it is itself being observed.
- Observer notification.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Subscriptionprivate ListHelper<O> private final NotificationAccumulator<O, T, ?> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedObservableBase(NotificationAccumulator<O, T, ?> pendingNotificationsImpl) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddObserver(O observer) protected final voidenqueueNotifications(T event) booleanprotected final voidforEachObserver(Consumer<O> action) Executes action for each observer, regardless of recursion state.protected final intinthashCode()final booleanprotected voidnewObserver(O observer) Called for each new observer.protected final voidfinal voidnotifyObservers(T event) final Subscriptionprotected abstract SubscriptionStarts observing this observable's input(s), if any.final voidremoveObserver(O observer) toString()Methods inherited from interface ProperObservable
defaultEquals, defaultHashCode, defaultNotificationAccumulator, defaultToString
-
Field Details
-
observers
-
inputSubscription
-
pendingNotifications
-
-
Constructor Details
-
ObservableBase
-
ObservableBase
protected ObservableBase()
-
-
Method Details
-
observeInputs
Starts observing this observable's input(s), if any. This method is called when the number of observers goes from 0 to 1. This method is called beforenewObserver(Object)is called for the first observer.- Returns:
- subscription used to stop observing inputs. The subscription is unsubscribed (i.e. input observation stops) when the number of observers goes down to 0.
-
isObservingInputs
public final boolean isObservingInputs() -
getObserverCount
protected final int getObserverCount() -
notifyObservers
- Specified by:
notifyObserversin interfaceProperObservable<O,T>
-
enqueueNotifications
-
notifyObservers
protected final void notifyObservers() -
forEachObserver
Executes action for each observer, regardless of recursion state. Ifactionthrows an exception for one observer, it will not be called for any subsequent observers and the exception will be propagated by this method.- Parameters:
action- action to execute for each observer.
-
newObserver
Called for each new observer. Overriding this method is a convenient way for subclasses to handle this event, for example to publish some initial events.This method is called after the
observeInputs()method. -
observe
- Specified by:
observein interfaceObservable<O>
-
addObserver
- Specified by:
addObserverin interfaceObservable<O>
-
removeObserver
- Specified by:
removeObserverin interfaceObservable<O>
-
hashCode
-
equals
-
toString
-