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
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 Subscription
private ListHelper
<O> private final NotificationAccumulator
<O, T, ?> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
ObservableBase
(NotificationAccumulator<O, T, ?> pendingNotificationsImpl) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addObserver
(O observer) protected final void
enqueueNotifications
(T event) boolean
protected final void
forEachObserver
(Consumer<O> action) Executes action for each observer, regardless of recursion state.protected final int
int
hashCode()
final boolean
protected void
newObserver
(O observer) Called for each new observer.protected final void
final void
notifyObservers
(T event) final Subscription
protected abstract Subscription
Starts observing this observable's input(s), if any.final void
removeObserver
(O observer) toString()
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 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:
notifyObservers
in interfaceProperObservable<O,
T>
-
enqueueNotifications
-
notifyObservers
protected final void notifyObservers() -
forEachObserver
Executes action for each observer, regardless of recursion state. Ifaction
throws 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:
observe
in interfaceObservable<O>
-
addObserver
- Specified by:
addObserver
in interfaceObservable<O>
-
removeObserver
- Specified by:
removeObserver
in interfaceObservable<O>
-
hashCode
public int hashCode() -
equals
-
toString
-