Package org.reactfx

Class ObservableBase<O,T>

java.lang.Object
org.reactfx.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 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.
  • Field Details

  • Constructor Details

    • ObservableBase

      protected ObservableBase(NotificationAccumulator<O,T,?> pendingNotificationsImpl)
    • ObservableBase

      protected ObservableBase()
  • Method Details

    • 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()
    • notifyObservers

      public final void notifyObservers(T event)
      Specified by:
      notifyObservers in interface ProperObservable<O,T>
    • enqueueNotifications

      protected final void enqueueNotifications(T event)
    • notifyObservers

      protected final void notifyObservers()
    • forEachObserver

      protected final void forEachObserver(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.

    • observe

      public final Subscription observe(O observer)
      Specified by:
      observe in interface Observable<O>
    • addObserver

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

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

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object