Class UniSerializedSubscriber<T>

java.lang.Object
io.smallrye.mutiny.subscription.UniSerializedSubscriber<T>
All Implemented Interfaces:
Cancellable, ContextSupport, UniSubscriber<T>, UniSubscription, Flow.Subscription

public class UniSerializedSubscriber<T> extends Object implements UniSubscriber<T>, UniSubscription
An implementation of UniSubscriber and UniSubscription making sure event handlers are only called once.
  • Constructor Details

  • Method Details

    • subscribe

      public static <T> void subscribe(AbstractUni<T> source, UniSubscriber<? super T> subscriber)
    • context

      public Context context()
      Description copied from interface: ContextSupport
      Provide a context.

      Since calls to this method shall only be triggered when a Mutiny pipeline uses a withContext operator, there is no need in general for caching the context value in a field of the implementing class. Exceptions include operators that have cross-subscriber semantics such as memoizers or broadcasters.

      This method is expected to be called once per withContext operator.

      Specified by:
      context in interface ContextSupport
      Returns:
      the context, must not be null.
    • onSubscribe

      public void onSubscribe(UniSubscription subscription)
      Description copied from interface: UniSubscriber
      Event handler called once the subscribed Uni has taken into account the subscription. The Uni have triggered the computation of the item.

      IMPORTANT: UniSubscriber.onItem(Object) and UniSubscriber.onFailure(Throwable) would not be called before the invocation of this method.

      Specified by:
      onSubscribe in interface UniSubscriber<T>
      Parameters:
      subscription - the subscription allowing to cancel the computation.
    • onItem

      public void onItem(T item)
      Description copied from interface: UniSubscriber
      Event handler called once the item has been computed by the subscribed Uni.

      IMPORTANT: this method will be only called once per subscription. If UniSubscriber.onFailure(Throwable) is called, this method won't be called.

      Specified by:
      onItem in interface UniSubscriber<T>
      Parameters:
      item - the item, may be null.
    • onFailure

      public void onFailure(Throwable throwable)
      Description copied from interface: UniSubscriber
      Called if the computation of the item by the subscriber Uni failed.

      IMPORTANT: this method will be only called once per subscription. If UniSubscriber.onItem(Object) is called, this method won't be called.

      Specified by:
      onFailure in interface UniSubscriber<T>
      Parameters:
      throwable - the failure, cannot be null.
    • cancel

      public void cancel()
      Description copied from interface: UniSubscription
      Requests the Uni to cancel and clean up resources. If the item is retrieved after cancellation, it is not forwarded to the subscriber. If the cancellation happens after the delivery of the item, this call is ignored.

      Calling this method, emits the cancellation event upstream.

      Specified by:
      cancel in interface Cancellable
      Specified by:
      cancel in interface Flow.Subscription
      Specified by:
      cancel in interface UniSubscription