Class Operators.MonoSubscriber<I,O>

java.lang.Object
reactor.core.publisher.Operators.MonoSubscriber<I,O>
Type Parameters:
I - The upstream sequence type
O - The downstream sequence type
All Implemented Interfaces:
Iterable<O>, Collection<O>, Queue<O>, Subscriber<I>, Subscription, CoreSubscriber<I>, Fuseable, Fuseable.QueueSubscription<O>, Scannable
Enclosing class:
Operators

public static class Operators.MonoSubscriber<I,O> extends Object implements Fuseable, Fuseable.QueueSubscription<O>
A Subscriber/Subscription barrier that holds a single value at most and properly gates asynchronous behaviors resulting from concurrent request or cancel and onXXX signals.
  • Field Details

    • actual

      protected final CoreSubscriber<? super O> actual
    • value

      protected @Nullable O value
      The value stored by this Mono operator. Strongly prefer using setValue(Object) rather than direct writes to this field, when possible.
  • Constructor Details

  • Method Details

    • cancel

      public void cancel()
      Specified by:
      cancel in interface Subscription
    • scanUnsafe

      public @Nullable Object scanUnsafe(Scannable.Attr key)
      Description copied from interface: Scannable
      This method is used internally by components to define their key-value mappings in a single place. Although it is ignoring the generic type of the Scannable.Attr key, implementors should take care to return values of the correct type, and return null if no specific value is available.

      For public consumption of attributes, prefer using Scannable.scan(Attr), which will return a typed value and fall back to the key's default if the component didn't define any mapping.

      Specified by:
      scanUnsafe in interface Scannable
      Parameters:
      key - a Scannable.Attr to resolve for the component.
      Returns:
      the value associated to the key for that specific component, or null if none.
    • clear

      public final void clear()
      Specified by:
      clear in interface Collection<I>
    • complete

      public final void complete(@Nullable O v)
      Tries to emit the value and complete the underlying subscriber or stores the value away until there is a request for it.

      Make sure this method is called at most once

      Parameters:
      v - the value to emit
    • discard

      protected void discard(@Nullable O v)
      Discard the given value, generally this.value field. Lets derived subscriber with further knowledge about the possible types of the value discard such values in a specific way. Note that fields should generally be nulled out along the discard call.
      Parameters:
      v - the value to discard
    • actual

      public final CoreSubscriber<? super O> actual()
    • isCancelled

      public final boolean isCancelled()
      Returns true if this Subscription has been cancelled.
      Returns:
      true if this Subscription has been cancelled
    • isEmpty

      public final boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<I>
    • onComplete

      public void onComplete()
      Specified by:
      onComplete in interface Subscriber<I>
    • onError

      public void onError(Throwable t)
      Specified by:
      onError in interface Subscriber<I>
    • onNext

      public void onNext(I t)
      Specified by:
      onNext in interface Subscriber<I>
    • onSubscribe

      public void onSubscribe(Subscription s)
      Description copied from interface: CoreSubscriber
      Implementors should initialize any state used by Subscriber.onNext(Object) before calling Subscription.request(long). Should further onNext related state modification occur, thread-safety will be required.

      Note that an invalid request <= 0 will not produce an onError and will simply be ignored or reported through a debug-enabled Logger.

      Specified by:
      onSubscribe in interface CoreSubscriber<I>
      Specified by:
      onSubscribe in interface Subscriber<I>
    • poll

      public final @Nullable O poll()
      Specified by:
      poll in interface Queue<I>
    • request

      public void request(long n)
      Specified by:
      request in interface Subscription
    • requestFusion

      public int requestFusion(int mode)
      Description copied from interface: Fuseable.QueueSubscription
      Request a specific fusion mode from this QueueSubscription.

      One should request either SYNC, ASYNC or ANY modes (never NONE) and the implementor should return NONE, SYNC or ASYNC (never ANY).

      For example, if a source supports only ASYNC fusion but the intermediate operator supports only SYNC fuseable sources, the operator may request SYNC fusion and the source can reject it via NONE, thus the operator can return NONE as well to downstream and the fusion doesn't happen.

      Specified by:
      requestFusion in interface Fuseable.QueueSubscription<I>
      Parameters:
      mode - the mode requested by the intermediate operator
      Returns:
      the actual fusion mode activated
    • setValue

      public void setValue(@Nullable O value)
      Set the value internally, without impacting request tracking state. This however discards the provided value when detecting a cancellation.
      Parameters:
      value - the new value.
      See Also:
    • size

      public int size()
      Specified by:
      size in interface Collection<I>
    • currentContext

      default Context currentContext()
      Description copied from interface: CoreSubscriber
      Request a Context from dependent components which can include downstream operators during subscribing or a terminal Subscriber.
      Specified by:
      currentContext in interface CoreSubscriber<I>
      Returns:
      a resolved context or Context.empty()