T - the type of element signaledpublic interface StreamMessage<T>
extends org.reactivestreams.Publisher<T>
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:
StreamMessage fully consumed?A StreamMessage is complete (or 'fully consumed') when:
Subscriber consumes all elements and Subscriber.onComplete() is invoked,Subscriber.onError(Throwable) is invoked,Subscription has been cancelled orabort() has been requested.When fully consumed, the CompletableFuture returned by completionFuture()
will complete, which you may find useful because Subscriber does not notify you when a stream is
cancelled.
ReferenceCounted objectsStreamMessage 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.
If a Subscriber does not want a StreamMessage to make a copy of a ByteBufHolder,
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.
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Closes this stream with
AbortedStreamException and prevents further subscription. |
void |
abort(Throwable cause)
Closes this stream with the specified
Throwable and prevents further subscription. |
default CompletableFuture<Void> |
closeFuture()
Deprecated.
Use
completionFuture() instead. |
CompletableFuture<Void> |
completionFuture()
Returns a
CompletableFuture that completes when this stream is complete,
either successfully or exceptionally, including cancellation and abortion. |
CompletableFuture<List<T>> |
drainAll()
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<T>> |
drainAll(boolean withPooledObjects)
Deprecated.
|
CompletableFuture<List<T>> |
drainAll(io.netty.util.concurrent.EventExecutor executor)
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<T>> |
drainAll(io.netty.util.concurrent.EventExecutor executor,
boolean withPooledObjects)
Deprecated.
|
CompletableFuture<List<T>> |
drainAll(io.netty.util.concurrent.EventExecutor executor,
SubscriptionOption... options)
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<T>> |
drainAll(SubscriptionOption... options)
Subscribes to this
StreamMessage and retrieves all elements from it. |
default boolean |
isComplete()
Returns
true if this stream is complete, either successfully or exceptionally,
including cancellation and abortion. |
boolean |
isEmpty()
Returns
true if this stream has been closed and did not publish any elements. |
boolean |
isOpen()
Returns
true if this stream is not closed yet. |
static <T> StreamMessage<T> |
of()
Creates a new
StreamMessage that will publish no objects, just a close event. |
static <T> StreamMessage<T> |
of(T... objs)
Creates a new
StreamMessage that will publish the given objs. |
static <T> StreamMessage<T> |
of(T obj)
Creates a new
StreamMessage that will publish the single obj. |
static <T> StreamMessage<T> |
of(T obj1,
T obj2)
|
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber,
boolean withPooledObjects)
Deprecated.
|
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber,
io.netty.util.concurrent.EventExecutor executor)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber,
io.netty.util.concurrent.EventExecutor executor,
boolean withPooledObjects)
Deprecated.
|
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber,
io.netty.util.concurrent.EventExecutor executor,
SubscriptionOption... options)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super T> subscriber,
SubscriptionOption... options)
Requests to start streaming data to the specified
Subscriber. |
static <T> StreamMessage<T> of()
StreamMessage that will publish no objects, just a close event.static <T> StreamMessage<T> of(T obj)
StreamMessage that will publish the single obj.static <T> StreamMessage<T> of(T obj1, T obj2)
@SafeVarargs static <T> StreamMessage<T> of(T... objs)
StreamMessage that will publish the given objs.boolean isOpen()
true if this stream is not closed yet. Note that a stream may not be
complete even if it's closed; a stream is complete when it's fully
consumed by a Subscriber.boolean isEmpty()
true if this stream has been closed and did not publish any elements.
Note that this method will not return true when the stream is open even if it has not
published anything so far, because it may publish something later.default boolean isComplete()
true if this stream is complete, either successfully or exceptionally,
including cancellation and abortion.
A StreamMessage is complete (or 'fully consumed') when:
Subscriber consumes all elements and Subscriber.onComplete() is invoked,Subscriber.onError(Throwable) is invoked,Subscription has been cancelled orabort() has been requested.CompletableFuture<Void> completionFuture()
CompletableFuture that completes when this stream is complete,
either successfully or exceptionally, including cancellation and abortion.
A StreamMessage is complete
(or 'fully consumed') when:
Subscriber consumes all elements and Subscriber.onComplete() is invoked,Subscriber.onError(Throwable) is invoked,Subscription has been cancelled orabort() has been requested.@Deprecated default CompletableFuture<Void> closeFuture()
completionFuture() instead.CompletableFuture that completes when this stream is complete,
either successfully or exceptionally, including cancellation and abortion.void subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
Subscriber. If there is a problem subscribing,
Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CancelledSubscriptionException if this stream has been
cancelled and SubscriptionOption.NOTIFY_CANCELLATION is
specified when subscribed.subscribe in interface org.reactivestreams.Publisher<T>void subscribe(org.reactivestreams.Subscriber<? super T> subscriber, SubscriptionOption... options)
Subscriber. If there is a problem subscribing,
Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CancelledSubscriptionException if this stream has been
cancelled and SubscriptionOption.NOTIFY_CANCELLATION is
specified when subscribed.options - SubscriptionOptions to subscribe withvoid subscribe(org.reactivestreams.Subscriber<? super T> subscriber, io.netty.util.concurrent.EventExecutor executor)
Subscriber. If there is a problem subscribing,
Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CancelledSubscriptionException if this stream has been
cancelled and SubscriptionOption.NOTIFY_CANCELLATION is
specified when subscribed.executor - the executor to subscribevoid subscribe(org.reactivestreams.Subscriber<? super T> subscriber, io.netty.util.concurrent.EventExecutor executor, SubscriptionOption... options)
Subscriber. If there is a problem subscribing,
Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CancelledSubscriptionException if this stream has been
cancelled and SubscriptionOption.NOTIFY_CANCELLATION is
specified when subscribed.executor - the executor to subscribeoptions - SubscriptionOptions to subscribe with@Deprecated void subscribe(org.reactivestreams.Subscriber<? super T> subscriber, boolean withPooledObjects)
subscribe(Subscriber, SubscriptionOption...).Subscriber. If there is a problem subscribing,
Subscriber.onError(Throwable) will be invoked with one of the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CancelledSubscriptionException if this stream has been
cancelled and SubscriptionOption.NOTIFY_CANCELLATION is
specified when subscribed.@Deprecated void subscribe(org.reactivestreams.Subscriber<? super T> subscriber, io.netty.util.concurrent.EventExecutor executor, boolean withPooledObjects)
subscribe(Subscriber, EventExecutor, SubscriptionOption...).Subscriber from the specified
Executor. If there is a problem subscribing, Subscriber.onError(Throwable) will be
invoked with one of the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CancelledSubscriptionException if this stream has been
cancelled and SubscriptionOption.NOTIFY_CANCELLATION is
specified when subscribed.executor - the executor to subscribeCompletableFuture<List<T>> drainAll()
StreamMessage and retrieves all elements from it.
The returned CompletableFuture may be completed exceptionally with the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CompletableFuture which will be completed with the list of the elements retrieved.@Deprecated CompletableFuture<List<T>> drainAll(boolean withPooledObjects)
drainAll(SubscriptionOption...).StreamMessage and retrieves all elements from it.
The returned CompletableFuture may be completed exceptionally with the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.CompletableFuture which will be completed with the list of the elements retrieved.@Deprecated CompletableFuture<List<T>> drainAll(io.netty.util.concurrent.EventExecutor executor, boolean withPooledObjects)
drainAll(EventExecutor, SubscriptionOption...).StreamMessage and retrieves all elements from it.
The returned CompletableFuture may be completed exceptionally with the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.executor - the executor to retrieve all elementsCompletableFuture which will be completed with the list of the elements retrieved.CompletableFuture<List<T>> drainAll(SubscriptionOption... options)
StreamMessage and retrieves all elements from it.
The returned CompletableFuture may be completed exceptionally with the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.options - SubscriptionOptions to subscribe with. Note that
SubscriptionOption.NOTIFY_CANCELLATION is ineffective because there's no
cancelling while draining all elements.CompletableFuture which will be completed with the list of the elements retrieved.CompletableFuture<List<T>> drainAll(io.netty.util.concurrent.EventExecutor executor)
StreamMessage and retrieves all elements from it.
The returned CompletableFuture may be completed exceptionally with the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.executor - the executor to retrieve all elementsCompletableFuture which will be completed with the list of the elements retrieved.CompletableFuture<List<T>> drainAll(io.netty.util.concurrent.EventExecutor executor, SubscriptionOption... options)
StreamMessage and retrieves all elements from it.
The returned CompletableFuture may be completed exceptionally with the following exceptions:
IllegalStateException if other Subscriber subscribed to this stream already.AbortedStreamException if this stream has been aborted.executor - the executor to retrieve all elementsoptions - SubscriptionOptions to subscribe with. Note that
SubscriptionOption.NOTIFY_CANCELLATION is ineffective because there's no
cancelling while draining all elements.CompletableFuture which will be completed with the list of the elements retrieved.void abort()
AbortedStreamException and prevents further subscription.
A Subscriber that attempts to subscribe to an aborted stream will be notified with
an AbortedStreamException via Subscriber.onError(Throwable). Calling this method
on a closed or aborted stream has no effect.void abort(Throwable cause)
Copyright © 2020 LeanCloud. All rights reserved.