Class DefaultUniEmitter<T>

  • Type Parameters:
    T - the type of item emitted by the emitter
    All Implemented Interfaces:
    Cancellable, ContextSupport, UniEmitter<T>, UniSubscription, org.reactivestreams.Subscription

    public class DefaultUniEmitter<T>
    extends java.lang.Object
    implements UniEmitter<T>, UniSubscription
    Implementation of the Uni Emitter. This implementation makes sure:
    • only the first event is propagated downstream
    • termination action is called only once and then drop

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      Requests the Uni to cancel and clean up resources.
      void complete​(T item)
      Emits the item event downstream with the given (potentially null) item.
      Context context()
      Provide a context.
      void fail​(java.lang.Throwable failure)
      Emits the failure event downstream with the given exception.
      boolean isTerminated()  
      UniEmitter<T> onTermination​(java.lang.Runnable onTermination)
      Attaches a @{code termination} event handler invoked when the downstream UniSubscription is cancelled, or when the emitter has emitted either an item or failure event.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • complete

        public void complete​(T item)
        Description copied from interface: UniEmitter
        Emits the item event downstream with the given (potentially null) item.

        Calling this method multiple times or after the UniEmitter.fail(Throwable) method has no effect.

        Specified by:
        complete in interface UniEmitter<T>
        Parameters:
        item - the item, may be null
      • fail

        public void fail​(java.lang.Throwable failure)
        Description copied from interface: UniEmitter
        Emits the failure event downstream with the given exception.

        Calling this method multiple times or after the UniEmitter.complete(Object) method has no effect.

        Specified by:
        fail in interface UniEmitter<T>
        Parameters:
        failure - the exception, must not be null
      • onTermination

        public UniEmitter<T> onTermination​(java.lang.Runnable onTermination)
        Description copied from interface: UniEmitter
        Attaches a @{code termination} event handler invoked when the downstream UniSubscription is cancelled, or when the emitter has emitted either an item or failure event.

        This method allows cleanup resources once the emitter can be disposed (has reached a terminal state).

        If the registration of the onTermination callback is done after the termination, it invokes the callback immediately.

        Specified by:
        onTermination in interface UniEmitter<T>
        Parameters:
        onTermination - the action to run on termination, must not be null
        Returns:
        this emitter
      • 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 org.reactivestreams.Subscription
        Specified by:
        cancel in interface UniSubscription
      • isTerminated

        public boolean isTerminated()
      • 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.