Class SerializedSubject<T>

java.lang.Object
io.reactivex.rxjava3.core.Observable<T>
io.reactivex.rxjava3.subjects.Subject<T>
io.reactivex.rxjava3.subjects.SerializedSubject<T>
Type Parameters:
T - the item value type
All Implemented Interfaces:
ObservableSource<T>, Observer<T>, Predicate<Object>, AppendOnlyLinkedArrayList.NonThrowingPredicate<Object>

final class SerializedSubject<T> extends Subject<T> implements AppendOnlyLinkedArrayList.NonThrowingPredicate<Object>
Serializes calls to the Observer methods.

All other Observable and Subject methods are thread-safe by design.

  • Field Details

    • actual

      final Subject<T> actual
      The actual subscriber to serialize Subscriber calls to.
    • emitting

      boolean emitting
      Indicates an emission is going on, guarded by this.
    • queue

      If not null, it holds the missed NotificationLite events.
    • done

      volatile boolean done
      Indicates a terminal event has been received and all further events will be dropped.
  • Constructor Details

    • SerializedSubject

      SerializedSubject(Subject<T> actual)
      Constructor that wraps an actual subject.
      Parameters:
      actual - the subject wrapped
  • Method Details

    • subscribeActual

      protected void subscribeActual(Observer<? super T> observer)
      Description copied from class: Observable
      Operator implementations (both source and intermediate) should implement this method that performs the necessary business logic and handles the incoming Observers.

      There is no need to call any of the plugin hooks on the current Observable instance or the Observer; all hooks and basic safeguards have been applied by Observable.subscribe(Observer) before this method gets called.

      Specified by:
      subscribeActual in class Observable<T>
      Parameters:
      observer - the incoming Observer, never null
    • onSubscribe

      public void onSubscribe(Disposable d)
      Description copied from interface: Observer
      Provides the Observer with the means of cancelling (disposing) the connection (channel) with the Observable in both synchronous (from within Observer.onNext(Object)) and asynchronous manner.
      Specified by:
      onSubscribe in interface Observer<T>
      Parameters:
      d - the Disposable instance whose Disposable.dispose() can be called anytime to cancel the connection
    • onNext

      public void onNext(T t)
      Description copied from interface: Observer
      Provides the Observer with a new item to observe.

      The Observable may call this method 0 or more times.

      The Observable will not call this method again after it calls either Observer.onComplete() or Observer.onError(java.lang.Throwable).

      Specified by:
      onNext in interface Observer<T>
      Parameters:
      t - the item emitted by the Observable
    • onError

      public void onError(Throwable t)
      Description copied from interface: Observer
      Notifies the Observer that the Observable has experienced an error condition.

      If the Observable calls this method, it will not thereafter call Observer.onNext(T) or Observer.onComplete().

      Specified by:
      onError in interface Observer<T>
      Parameters:
      t - the exception encountered by the Observable
    • onComplete

      public void onComplete()
      Description copied from interface: Observer
      Notifies the Observer that the Observable has finished sending push-based notifications.

      The Observable will not call this method if it calls Observer.onError(java.lang.Throwable).

      Specified by:
      onComplete in interface Observer<T>
    • emitLoop

      void emitLoop()
      Loops until all notifications in the queue has been processed.
    • test

      public boolean test(Object o)
      Description copied from interface: Predicate
      Test the given input value and return a boolean.
      Specified by:
      test in interface AppendOnlyLinkedArrayList.NonThrowingPredicate<T>
      Specified by:
      test in interface Predicate<T>
      Parameters:
      o - the value
      Returns:
      the boolean result
    • hasObservers

      public boolean hasObservers()
      Description copied from class: Subject
      Returns true if the subject has any Observers.

      The method is thread-safe.

      Specified by:
      hasObservers in class Subject<T>
      Returns:
      true if the subject has any Observers
    • hasThrowable

      public boolean hasThrowable()
      Description copied from class: Subject
      Returns true if the subject has reached a terminal state through an error event.

      The method is thread-safe.

      Specified by:
      hasThrowable in class Subject<T>
      Returns:
      true if the subject has reached a terminal state through an error event
      See Also:
    • getThrowable

      @Nullable public @Nullable Throwable getThrowable()
      Description copied from class: Subject
      Returns the error that caused the Subject to terminate or null if the Subject hasn't terminated yet.

      The method is thread-safe.

      Specified by:
      getThrowable in class Subject<T>
      Returns:
      the error that caused the Subject to terminate or null if the Subject hasn't terminated yet
    • hasComplete

      public boolean hasComplete()
      Description copied from class: Subject
      Returns true if the subject has reached a terminal state through a complete event.

      The method is thread-safe.

      Specified by:
      hasComplete in class Subject<T>
      Returns:
      true if the subject has reached a terminal state through a complete event
      See Also: