Interface StreamMessage<T>

Type Parameters:
T - the type of element signaled
All Superinterfaces:
org.reactivestreams.Publisher<T>
All Known Subinterfaces:
HttpRequest, HttpRequestWriter, HttpResponse, HttpResponseWriter, PooledHttpRequest, PooledHttpResponse, PooledStreamMessage<T>
All Known Implementing Classes:
DefaultStreamMessage, DeferredStreamMessage, EmptyFixedStreamMessage, FilteredHttpRequest, FilteredHttpResponse, FilteredStreamMessage, OneElementFixedStreamMessage, PublisherBasedStreamMessage, RegularFixedStreamMessage, StreamMessageWrapper, TwoElementFixedStreamMessage

public interface StreamMessage<T>
extends org.reactivestreams.Publisher<T>
A variant of Reactive Streams Publisher, which allows only one Subscriber. Unlike a usual Publisher, a StreamMessage can stream itself only once. It has the following additional operations on top of what the Reactive Streams API provides:

When is a StreamMessage fully consumed?

A StreamMessage is complete (or 'fully consumed') when:

  • the Subscriber consumes all elements and Subscriber.onComplete() is invoked,
  • an error occurred and Subscriber.onError(Throwable) is invoked,
  • the Subscription has been cancelled or
  • abort() has been requested.

When fully consumed, the CompletableFuture returned by whenComplete() will complete, which you may find useful because Subscriber does not notify you when a stream is cancelled.

Publication and Consumption of ReferenceCounted objects

StreamMessage will reject the publication request of a ReferenceCounted object except ByteBuf and ByteBufHolder.

StreamMessage will discard the publication request of a ByteBuf or a ByteBufHolder silently and release it automatically when the publication is attempted after the stream is closed.

For ByteBuf and ByteBufHolder, StreamMessage will convert them into their respective unpooled versions that never leak, so that the Subscriber does not need to worry about leaks.

Subscriber.onError(Throwable) is invoked when any exception is raised except the CancelledSubscriptionException which is caused by Subscription.cancel(). If you want your Subscriber get notified by Subscriber.onError(Throwable) when Subscription.cancel() is called, specify SubscriptionOption.NOTIFY_CANCELLATION when you subscribe.