Class FilteredStreamMessage<T,U>
java.lang.Object
com.linecorp.armeria.common.stream.FilteredStreamMessage<T,U>
- All Implemented Interfaces:
StreamMessage<U>
,org.reactivestreams.Publisher<U>
- Direct Known Subclasses:
FilteredHttpRequest
,FilteredHttpResponse
A
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.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
FilteredStreamMessage
(StreamMessage<T> upstream) Creates a newFilteredStreamMessage
that filters objects published byupstream
before passing to a subscriber.protected
FilteredStreamMessage
(StreamMessage<T> upstream, boolean withPooledObjects) (Advanced users only) Creates a newFilteredStreamMessage
that filters objects published byupstream
before passing to a subscriber. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
abort()
Closes this stream withAbortedStreamException
and prevents further subscription.final void
Closes this stream with the specifiedThrowable
and prevents further subscription.protected void
beforeComplete
(org.reactivestreams.Subscriber<? super U> subscriber) A callback executed just before callingSubscriber.onComplete()
onsubscriber
.beforeError
(org.reactivestreams.Subscriber<? super U> subscriber, Throwable cause) A callback executed just before callingSubscriber.onError(Throwable)
onsubscriber
.protected void
beforeSubscribe
(org.reactivestreams.Subscriber<? super U> subscriber, org.reactivestreams.Subscription subscription) A callback executed just before callingSubscriber.onSubscribe(Subscription)
onsubscriber
.collect
(EventExecutor executor, SubscriptionOption... options) Collects the elements published by thisStreamMessage
with the specifiedEventExecutor
andSubscriptionOption
s.final EventExecutor
Returns the defaultEventExecutor
which will be used when a user subscribes usingStreamMessage.subscribe(Subscriber)
,StreamMessage.subscribe(Subscriber, SubscriptionOption...)
.final long
demand()
Returns the current demand of this stream.protected abstract U
The filter to apply to published objects.final boolean
isEmpty()
Returnstrue
if this stream has been closed and did not publish any elements.final boolean
isOpen()
Returnstrue
if this stream is not closed yet.protected void
onCancellation
(org.reactivestreams.Subscriber<? super U> subscriber) A callback executed when thisStreamMessage
is canceled by theSubscriber
.final void
subscribe
(org.reactivestreams.Subscriber<? super U> subscriber, EventExecutor executor) Requests to start streaming data to the specifiedSubscriber
.final void
subscribe
(org.reactivestreams.Subscriber<? super U> subscriber, EventExecutor executor, SubscriptionOption... options) Requests to start streaming data to the specifiedSubscriber
.final CompletableFuture<Void>
Returns aCompletableFuture
that completes when this stream is complete, either successfully or exceptionally, including cancellation and abortion.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessage
collect, collect, decode, decode, filter, isComplete, map, mapAsync, mapError, mapParallel, mapParallel, peek, peek, peekError, recoverAndResume, recoverAndResume, subscribe, subscribe, subscribe, toDuplicator, toDuplicator, toInputStream, toInputStream, writeTo
-
Constructor Details
-
FilteredStreamMessage
Creates a newFilteredStreamMessage
that filters objects published byupstream
before passing to a subscriber. -
FilteredStreamMessage
(Advanced users only) Creates a newFilteredStreamMessage
that filters objects published byupstream
before passing to a subscriber.- Parameters:
withPooledObjects
- iftrue
,filter(Object)
receives the pooledHttpData
as is, without making a copy. If you don't know what this means, useFilteredStreamMessage(StreamMessage)
.- See Also:
-
-
Method Details
-
filter
The filter to apply to published objects. The result of the filter is passed on to the delegate subscriber. -
beforeSubscribe
protected void beforeSubscribe(org.reactivestreams.Subscriber<? super U> subscriber, org.reactivestreams.Subscription subscription) A callback executed just before callingSubscriber.onSubscribe(Subscription)
onsubscriber
. Override this method to execute any initialization logic that may be needed. -
beforeComplete
A callback executed just before callingSubscriber.onComplete()
onsubscriber
. Override this method to execute any cleanup logic that may be needed before completing the subscription. -
beforeError
@Nullable protected @Nullable Throwable beforeError(org.reactivestreams.Subscriber<? super U> subscriber, Throwable cause) A callback executed just before callingSubscriber.onError(Throwable)
onsubscriber
. Override this method to execute any cleanup logic that may be needed before failing the subscription. This method may rewrite thecause
and then return a new one so that the newThrowable
would be passed toSubscriber.onError(Throwable)
. -
onCancellation
A callback executed when thisStreamMessage
is canceled by theSubscriber
. -
isOpen
public final boolean isOpen()Description copied from interface:StreamMessage
Returnstrue
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 aSubscriber
.- Specified by:
isOpen
in interfaceStreamMessage<T>
-
isEmpty
public final boolean isEmpty()Description copied from interface:StreamMessage
Returnstrue
if this stream has been closed and did not publish any elements. Note that this method will not returntrue
when the stream is open even if it has not published anything so far, because it may publish something later.- Specified by:
isEmpty
in interfaceStreamMessage<T>
-
demand
public final long demand()Description copied from interface:StreamMessage
Returns the current demand of this stream.- Specified by:
demand
in interfaceStreamMessage<T>
-
whenComplete
Description copied from interface:StreamMessage
Returns aCompletableFuture
that completes when this stream is complete, either successfully or exceptionally, including cancellation and abortion.A
StreamMessage
is complete (or 'fully consumed') when:- the
Subscriber
consumes all elements andSubscriber.onComplete()
is invoked, - an error occurred and
Subscriber.onError(Throwable)
is invoked, - the
Subscription
has been cancelled or StreamMessage.abort()
has been requested.
- Specified by:
whenComplete
in interfaceStreamMessage<T>
- the
-
collect
Description copied from interface:StreamMessage
Collects the elements published by thisStreamMessage
with the specifiedEventExecutor
andSubscriptionOption
s. The returnedCompletableFuture
will be notified when the elements are fully consumed.Note that if this
StreamMessage
was subscribed by otherSubscriber
already, the returnedCompletableFuture
will be completed with anIllegalStateException
.- Specified by:
collect
in interfaceStreamMessage<T>
-
subscribe
public final void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, EventExecutor executor) Description copied from interface:StreamMessage
Requests to start streaming data to the specifiedSubscriber
. If there is a problem subscribing,Subscriber.onError(Throwable)
will be invoked with one of the following exceptions:IllegalStateException
if otherSubscriber
subscribed to this stream already.AbortedStreamException
if this stream has been aborted.CancelledSubscriptionException
if this stream has been cancelled andSubscriptionOption.NOTIFY_CANCELLATION
is specified when subscribed.- Other exceptions that occurred due to an error while retrieving the elements.
- Specified by:
subscribe
in interfaceStreamMessage<T>
executor
- the executor to subscribe
-
subscribe
public final void subscribe(org.reactivestreams.Subscriber<? super U> subscriber, EventExecutor executor, SubscriptionOption... options) Description copied from interface:StreamMessage
Requests to start streaming data to the specifiedSubscriber
. If there is a problem subscribing,Subscriber.onError(Throwable)
will be invoked with one of the following exceptions:IllegalStateException
if otherSubscriber
subscribed to this stream already.AbortedStreamException
if this stream has been aborted.CancelledSubscriptionException
if this stream has been cancelled andSubscriptionOption.NOTIFY_CANCELLATION
is specified when subscribed.- Other exceptions that occurred due to an error while retrieving the elements.
- Specified by:
subscribe
in interfaceStreamMessage<T>
executor
- the executor to subscribeoptions
-SubscriptionOption
s to subscribe with
-
defaultSubscriberExecutor
Description copied from interface:StreamMessage
Returns the defaultEventExecutor
which will be used when a user subscribes usingStreamMessage.subscribe(Subscriber)
,StreamMessage.subscribe(Subscriber, SubscriptionOption...)
.Please note that if this method is called multiple times, the returned
EventExecutor
s can be different depending on thisStreamMessage
implementation.- Specified by:
defaultSubscriberExecutor
in interfaceStreamMessage<T>
-
abort
public final void abort()Description copied from interface:StreamMessage
Closes this stream withAbortedStreamException
and prevents further subscription. ASubscriber
that attempts to subscribe to an aborted stream will be notified with anAbortedStreamException
viaSubscriber.onError(Throwable)
. Calling this method on a closed or aborted stream has no effect.- Specified by:
abort
in interfaceStreamMessage<T>
-
abort
Description copied from interface:StreamMessage
Closes this stream with the specifiedThrowable
and prevents further subscription. ASubscriber
that attempts to subscribe to an aborted stream will be notified with the specifiedThrowable
viaSubscriber.onError(Throwable)
. Calling this method on a closed or aborted stream has no effect.- Specified by:
abort
in interfaceStreamMessage<T>
-