Class StreamMessageWrapper<T>
java.lang.Object
com.linecorp.armeria.common.stream.StreamMessageWrapper<T>
- Type Parameters:
T
- the type of elements
- All Implemented Interfaces:
StreamMessage<T>
,org.reactivestreams.Publisher<T>
Wraps a
StreamMessage
and forwards its method invocations to delegate
.-
Constructor Summary
ModifierConstructorDescriptionprotected
StreamMessageWrapper
(StreamMessage<? extends T> delegate) Creates a new instance that wraps adelegate
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Closes this stream withAbortedStreamException
and prevents further subscription.void
Closes this stream with the specifiedThrowable
and prevents further subscription.collect
(EventExecutor executor, SubscriptionOption... options) Collects the elements published by thisStreamMessage
with the specifiedEventExecutor
andSubscriptionOption
s.Returns the defaultEventExecutor
which will be used when a user subscribes usingStreamMessage.subscribe(Subscriber)
,StreamMessage.subscribe(Subscriber, SubscriptionOption...)
.protected final StreamMessage<? extends T>
delegate()
Returns theStreamMessage
being decorated.long
demand()
Returns the current demand of this stream.boolean
isEmpty()
Returnstrue
if this stream has been closed and did not publish any elements.boolean
isOpen()
Returnstrue
if this stream is not closed yet.void
subscribe
(org.reactivestreams.Subscriber<? super T> subscriber, EventExecutor executor, SubscriptionOption... options) Requests to start streaming data to the specifiedSubscriber
.Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements.toDuplicator
(EventExecutor executor) Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements.toString()
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, 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, subscribe, subscribe, subscribe, subscribe, toInputStream, toInputStream, writeTo
-
Constructor Details
-
StreamMessageWrapper
Creates a new instance that wraps adelegate
.
-
-
Method Details
-
delegate
Returns theStreamMessage
being decorated. -
isOpen
public 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 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 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
-
subscribe
public void subscribe(org.reactivestreams.Subscriber<? super T> 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 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>
-
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>
-
toDuplicator
Description copied from interface:StreamMessage
Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements. Note that you cannot subscribe to thisStreamMessage
anymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()
from the returnedStreamMessageDuplicator
.- Specified by:
toDuplicator
in interfaceStreamMessage<T>
-
toDuplicator
Description copied from interface:StreamMessage
Returns a newStreamMessageDuplicator
that duplicates thisStreamMessage
into one or moreStreamMessage
s, which publish the same elements. Note that you cannot subscribe to thisStreamMessage
anymore after you call this method. To subscribe, callStreamMessageDuplicator.duplicate()
from the returnedStreamMessageDuplicator
.- Specified by:
toDuplicator
in interfaceStreamMessage<T>
- Parameters:
executor
- the executor to duplicate
-
toString
-