Interface MultiEmitter<T>

Type Parameters:
T - the expected type of items.
All Superinterfaces:
ContextSupport

public interface MultiEmitter<T> extends ContextSupport
An object allowing to send signals to the downstream Multi. Multi propagates several item event, once a failure or completion event is fired, the other events have no effects.

Emitting a null item is invalid and will cause a failure.

  • Method Details

    • emit

      MultiEmitter<T> emit(T item)
      Emits an item event downstream.

      Calling this method after a failure or a completion events has no effect.

      Parameters:
      item - the item, must not be null
      Returns:
      this emitter, so firing item events can be chained.
    • fail

      void fail(Throwable failure)
      Emits a failure event downstream with the given exception.

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

      Parameters:
      failure - the exception, must not be null
    • complete

      void complete()
      Emits a completion event downstream indicating that no more item will be sent.

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

    • onTermination

      MultiEmitter<T> onTermination(Runnable onTermination)
      Attaches a @{code termination} event handler invoked when the downstream Flow.Subscription is cancelled, or when the emitter has emitted either a completion 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.

      Parameters:
      onTermination - the action to run on termination, must not be null
      Returns:
      this emitter
    • isCancelled

      boolean isCancelled()
      Returns:
      true if the downstream cancelled the stream or the emitter was terminated (with a completion or failure events).
    • requested

      long requested()
      Returns:
      the current outstanding request amount.
    • onRequest

      default MultiEmitter<T> onRequest(LongConsumer consumer)
      Defines a callback for Flow.Subscription.request(long) signals.

      This is useful to facilitate the implementation of back-pressured emissions.

      Parameters:
      consumer - the callback
      Returns:
      this emitter
    • onCancellation

      default MultiEmitter<T> onCancellation(Runnable onCancellation)
      Defines a callback for Flow.Subscription.cancel() signals.

      This is useful to facilitate the implementation of cancellation logic.

      Parameters:
      onCancellation - the callback
      Returns:
      this emitter