public abstract class FilteredStreamMessage<T,U> extends Object implements StreamMessage<U>
StreamMessage that filters objects as they are published. The filtering
will happen from an I/O thread, meaning the order of the filtering will match the
order that the delegate processes the objects in.| Modifier | Constructor and Description |
|---|---|
protected |
FilteredStreamMessage(StreamMessage<T> delegate)
Creates a new
FilteredStreamMessage that filters objects published by delegate
before passing to a subscriber. |
protected |
FilteredStreamMessage(StreamMessage<T> delegate,
boolean withPooledObjects)
Creates a new
FilteredStreamMessage that filters objects published by delegate
before passing to a subscriber. |
| 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. |
protected void |
beforeComplete(org.reactivestreams.Subscriber<? super U> subscriber)
A callback executed just before calling
Subscriber.onComplete() on subscriber. |
protected Throwable |
beforeError(org.reactivestreams.Subscriber<? super U> subscriber,
Throwable cause)
A callback executed just before calling
Subscriber.onError(Throwable) on subscriber. |
protected void |
beforeSubscribe(org.reactivestreams.Subscriber<? super U> subscriber,
org.reactivestreams.Subscription subscription)
A callback executed just before calling
Subscriber.onSubscribe(Subscription) on
subscriber. |
CompletableFuture<Void> |
completionFuture()
Returns a
CompletableFuture that completes when this stream is complete,
either successfully or exceptionally, including cancellation and abortion. |
CompletableFuture<List<U>> |
drainAll()
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<U>> |
drainAll(boolean withPooledObjects)
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<U>> |
drainAll(io.netty.util.concurrent.EventExecutor executor)
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<U>> |
drainAll(io.netty.util.concurrent.EventExecutor executor,
boolean withPooledObjects)
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<U>> |
drainAll(io.netty.util.concurrent.EventExecutor executor,
SubscriptionOption... options)
Subscribes to this
StreamMessage and retrieves all elements from it. |
CompletableFuture<List<U>> |
drainAll(SubscriptionOption... options)
Subscribes to this
StreamMessage and retrieves all elements from it. |
protected abstract U |
filter(T obj)
The filter to apply to published objects.
|
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. |
void |
subscribe(org.reactivestreams.Subscriber<? super U> subscriber)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super U> subscriber,
boolean withPooledObjects)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super U> subscriber,
io.netty.util.concurrent.EventExecutor executor)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super U> subscriber,
io.netty.util.concurrent.EventExecutor executor,
boolean withPooledObjects)
Requests to start streaming data, invoking the specified
Subscriber from the specified
Executor. |
void |
subscribe(org.reactivestreams.Subscriber<? super U> subscriber,
io.netty.util.concurrent.EventExecutor executor,
SubscriptionOption... options)
Requests to start streaming data to the specified
Subscriber. |
void |
subscribe(org.reactivestreams.Subscriber<? super U> subscriber,
SubscriptionOption... options)
Requests to start streaming data to the specified
Subscriber. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcloseFuture, isComplete, of, of, of, ofprotected FilteredStreamMessage(StreamMessage<T> delegate)
FilteredStreamMessage that filters objects published by delegate
before passing to a subscriber.protected FilteredStreamMessage(StreamMessage<T> delegate, boolean withPooledObjects)
FilteredStreamMessage that filters objects published by delegate
before passing to a subscriber.withPooledObjects - if true, filter(Object) receives the pooled ByteBuf
and ByteBufHolder as is, without making a copy. If you don't know what
this means, use FilteredStreamMessage(StreamMessage).protected abstract U filter(T obj)
protected void beforeSubscribe(org.reactivestreams.Subscriber<? super U> subscriber, org.reactivestreams.Subscription subscription)
Subscriber.onSubscribe(Subscription) on
subscriber. Override this method to execute any initialization logic that may be needed.protected void beforeComplete(org.reactivestreams.Subscriber<? super U> subscriber)
Subscriber.onComplete() on subscriber.
Override this method to execute any cleanup logic that may be needed before completing the
subscription.@Nullable protected Throwable beforeError(org.reactivestreams.Subscriber<? super U> subscriber, Throwable cause)
Subscriber.onError(Throwable) on subscriber.
Override this method to execute any cleanup logic that may be needed before failing the
subscription. This method may rewrite the cause and then return a new one so that the new
Throwable would be passed to Subscriber.onError(Throwable).public boolean isOpen()
StreamMessagetrue 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.isOpen in interface StreamMessage<U>public boolean isEmpty()
StreamMessagetrue 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.isEmpty in interface StreamMessage<U>public CompletableFuture<Void> completionFuture()
StreamMessageCompletableFuture 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 orStreamMessage.abort() has been requested.completionFuture in interface StreamMessage<U>public void subscribe(org.reactivestreams.Subscriber<? super U> subscriber)
StreamMessageSubscriber. 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 StreamMessage<U>subscribe in interface org.reactivestreams.Publisher<U>public void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, boolean withPooledObjects)
StreamMessageSubscriber. 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 StreamMessage<U>public void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, SubscriptionOption... options)
StreamMessageSubscriber. 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 StreamMessage<U>options - SubscriptionOptions to subscribe withpublic void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, io.netty.util.concurrent.EventExecutor executor, boolean withPooledObjects)
StreamMessageSubscriber 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.subscribe in interface StreamMessage<U>executor - the executor to subscribepublic void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, io.netty.util.concurrent.EventExecutor executor)
StreamMessageSubscriber. 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 StreamMessage<U>executor - the executor to subscribepublic void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, io.netty.util.concurrent.EventExecutor executor, SubscriptionOption... options)
StreamMessageSubscriber. 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 StreamMessage<U>executor - the executor to subscribeoptions - SubscriptionOptions to subscribe withpublic CompletableFuture<List<U>> drainAll()
StreamMessageStreamMessage 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.drainAll in interface StreamMessage<U>CompletableFuture which will be completed with the list of the elements retrieved.public CompletableFuture<List<U>> drainAll(boolean withPooledObjects)
StreamMessageStreamMessage 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.drainAll in interface StreamMessage<U>CompletableFuture which will be completed with the list of the elements retrieved.public CompletableFuture<List<U>> drainAll(SubscriptionOption... options)
StreamMessageStreamMessage 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.drainAll in interface StreamMessage<U>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.public CompletableFuture<List<U>> drainAll(io.netty.util.concurrent.EventExecutor executor, boolean withPooledObjects)
StreamMessageStreamMessage 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.drainAll in interface StreamMessage<U>executor - the executor to retrieve all elementsCompletableFuture which will be completed with the list of the elements retrieved.public CompletableFuture<List<U>> drainAll(io.netty.util.concurrent.EventExecutor executor)
StreamMessageStreamMessage 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.drainAll in interface StreamMessage<U>executor - the executor to retrieve all elementsCompletableFuture which will be completed with the list of the elements retrieved.public CompletableFuture<List<U>> drainAll(io.netty.util.concurrent.EventExecutor executor, SubscriptionOption... options)
StreamMessageStreamMessage 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.drainAll in interface StreamMessage<U>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.public void abort()
StreamMessageAbortedStreamException 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.abort in interface StreamMessage<U>public void abort(Throwable cause)
StreamMessageThrowable and prevents further subscription.
A Subscriber that attempts to subscribe to an aborted stream will be notified with
the specified Throwable via Subscriber.onError(Throwable). Calling this method
on a closed or aborted stream has no effect.abort in interface StreamMessage<U>Copyright © 2020 LeanCloud. All rights reserved.