Interface StreamMessage<T>

Type Parameters:
T - the type of element signaled
All Superinterfaces:
org.reactivestreams.Publisher<T>
All Known Subinterfaces:
HttpRequest, HttpRequestWriter, HttpResponse, HttpResponseWriter
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 pooled HttpData objects

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

For pooled HttpData, StreamMessage will convert them into its unpooled version that never leak, so that the Subscriber does not need to worry about leaks.

If a Subscriber does not want a StreamMessage to make a copy of a pooled HttpData, specify SubscriptionOption.WITH_POOLED_OBJECTS when you subscribe. Note that the Subscriber is responsible for releasing the objects given with Subscriber.onNext(Object).

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.