Package org.reactfx
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
public abstract class ObservableBase<O,T> extends java.lang.Object implements ProperObservable<O,T>
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
Fields Modifier and Type Field Description private SubscriptioninputSubscriptionprivate ListHelper<O>observersprivate NotificationAccumulator<O,T,?>pendingNotifications
-
Constructor Summary
Constructors Modifier Constructor Description protectedObservableBase()protectedObservableBase(NotificationAccumulator<O,T,?> pendingNotificationsImpl)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddObserver(O observer)protected voidenqueueNotifications(T event)booleanequals(java.lang.Object o)protected voidforEachObserver(java.util.function.Consumer<O> action)Executes action for each observer, regardless of recursion state.protected intgetObserverCount()inthashCode()booleanisObservingInputs()protected voidnewObserver(O observer)Called for each new observer.protected voidnotifyObservers()voidnotifyObservers(T event)Subscriptionobserve(O observer)protected abstract SubscriptionobserveInputs()Starts observing this observable's input(s), if any.voidremoveObserver(O observer)java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.reactfx.ProperObservable
defaultEquals, defaultHashCode, defaultNotificationAccumulator, defaultToString
-
-
-
-
Field Detail
-
observers
private ListHelper<O> observers
-
inputSubscription
private Subscription inputSubscription
-
pendingNotifications
private final NotificationAccumulator<O,T,?> pendingNotifications
-
-
Constructor Detail
-
ObservableBase
protected ObservableBase(NotificationAccumulator<O,T,?> pendingNotificationsImpl)
-
ObservableBase
protected ObservableBase()
-
-
Method Detail
-
observeInputs
protected abstract Subscription 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
public final void notifyObservers(T event)
- Specified by:
notifyObserversin interfaceProperObservable<O,T>
-
enqueueNotifications
protected final void enqueueNotifications(T event)
-
notifyObservers
protected final void notifyObservers()
-
forEachObserver
protected final void forEachObserver(java.util.function.Consumer<O> action)
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
protected void newObserver(O observer)
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
public final Subscription observe(O observer)
- Specified by:
observein interfaceObservable<O>
-
addObserver
public final void addObserver(O observer)
- Specified by:
addObserverin interfaceObservable<O>
-
removeObserver
public final void removeObserver(O observer)
- Specified by:
removeObserverin interfaceObservable<O>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-