Package org.reactfx

Class ObservableBase<O,​T>

  • Type Parameters:
    O - type of the observer
    T - 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:
    1. Observer management: adding and removing observers.
    2. 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.
    3. Observer notification.
    • Constructor Detail

      • 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 before newObserver(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()
      • 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. If action 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

        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.

      • addObserver

        public final void addObserver​(O observer)
        Specified by:
        addObserver in interface Observable<O>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object