Class BasicFuseableObserver<T,R>

java.lang.Object
io.reactivex.rxjava3.internal.observers.BasicFuseableObserver<T,R>
Type Parameters:
T - the upstream value type
R - the downstream value type
All Implemented Interfaces:
Observer<T>, Disposable, QueueDisposable<R>, QueueFuseable<R>, SimpleQueue<R>
Direct Known Subclasses:
ObservableDistinct.DistinctObserver, ObservableDistinctUntilChanged.DistinctUntilChangedObserver, ObservableDoAfterNext.DoAfterObserver, ObservableFilter.FilterObserver, ObservableMap.MapObserver, ObservableMapOptional.MapOptionalObserver

public abstract class BasicFuseableObserver<T,R> extends Object implements Observer<T>, QueueDisposable<R>
Base class for a fuseable intermediate observer.
  • Field Details

    • downstream

      protected final Observer<? super R> downstream
      The downstream subscriber.
    • upstream

      protected Disposable upstream
      The upstream subscription.
    • qd

      protected QueueDisposable<T> qd
      The upstream's QueueDisposable if not null.
    • done

      protected boolean done
      Flag indicating no further onXXX event should be accepted.
    • sourceMode

      protected int sourceMode
      Holds the established fusion mode of the upstream.
  • Constructor Details

    • BasicFuseableObserver

      public BasicFuseableObserver(Observer<? super R> downstream)
      Construct a BasicFuseableObserver by wrapping the given subscriber.
      Parameters:
      downstream - the subscriber, not null (not verified)
  • Method Details

    • onSubscribe

      public final 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
    • beforeDownstream

      protected boolean beforeDownstream()
      Override this to perform actions before the call actual.onSubscribe(this) happens.
      Returns:
      true if onSubscribe should continue with the call
    • afterDownstream

      protected void afterDownstream()
      Override this to perform actions after the call to actual.onSubscribe(this) happened.
    • 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
    • fail

      protected final void fail(Throwable t)
      Rethrows the throwable if it is a fatal exception or calls onError(Throwable).
      Parameters:
      t - the throwable to rethrow or signal to the actual subscriber
    • 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>
    • transitiveBoundaryFusion

      protected final int transitiveBoundaryFusion(int mode)
      Calls the upstream's QueueDisposable.requestFusion with the mode and saves the established mode in sourceMode if that mode doesn't have the QueueFuseable.BOUNDARY flag set.

      If the upstream doesn't support fusion (qd is null), the method returns QueueFuseable.NONE.

      Parameters:
      mode - the fusion mode requested
      Returns:
      the established fusion mode
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Dispose the resource, the operation should be idempotent.
      Specified by:
      dispose in interface Disposable
    • isDisposed

      public boolean isDisposed()
      Description copied from interface: Disposable
      Returns true if this resource has been disposed.
      Specified by:
      isDisposed in interface Disposable
      Returns:
      true if this resource has been disposed
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: SimpleQueue
      Returns true if the queue is empty.

      Note however that due to potential fused functions in SimpleQueue.poll() it is possible this method returns false but then poll() returns null because the fused function swallowed the available item(s).

      Specified by:
      isEmpty in interface SimpleQueue<T>
      Returns:
      true if the queue is empty
    • clear

      public void clear()
      Description copied from interface: SimpleQueue
      Removes all enqueued items from this queue.
      Specified by:
      clear in interface SimpleQueue<T>
    • offer

      public final boolean offer(R e)
      Description copied from interface: SimpleQueue
      Atomically enqueue a single value.
      Specified by:
      offer in interface SimpleQueue<T>
      Parameters:
      e - the value to enqueue, not null
      Returns:
      true if successful, false if the value was not enqueued likely due to reaching the queue capacity)
    • offer

      public final boolean offer(R v1, R v2)
      Description copied from interface: SimpleQueue
      Atomically enqueue two values.
      Specified by:
      offer in interface SimpleQueue<T>
      Parameters:
      v1 - the first value to enqueue, not null
      v2 - the second value to enqueue, not null
      Returns:
      true if successful, false if the value was not enqueued likely due to reaching the queue capacity)