Class DeferredStreamMessage<T>
java.lang.Object
com.linecorp.armeria.common.stream.AggregationSupport
com.linecorp.armeria.common.stream.DeferredStreamMessage<T>
- Type Parameters:
T
- the type of element signaled
- All Implemented Interfaces:
StreamMessage<T>
,org.reactivestreams.Publisher<T>
A
StreamMessage
whose stream is published later by another StreamMessage
. It is useful when
your StreamMessage
will not be instantiated early.-
Constructor Summary
-
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.final void
close()
Closes the deferred stream without setting a delegate.final void
Closes the deferred stream without setting a delegate.collect
(EventExecutor executor, SubscriptionOption... options) Collects the elements published by thisStreamMessage
with the specifiedEventExecutor
andSubscriptionOption
s.protected final void
delegate
(StreamMessage<T> upstream) Sets the upstreamStreamMessage
which will actually publish the stream.final long
demand()
Returns the current demand of this stream.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
Invoked after an element is removed from theStreamMessage
and beforeSubscriber.onNext(Object)
is invoked.final void
subscribe
(org.reactivestreams.Subscriber<? super T> subscriber, EventExecutor executor) Requests to start streaming data to the specifiedSubscriber
.final void
subscribe
(org.reactivestreams.Subscriber<? super T> 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 com.linecorp.armeria.common.stream.AggregationSupport
aggregate
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, defaultSubscriberExecutor, filter, isComplete, map, mapAsync, mapError, mapParallel, mapParallel, peek, peek, peekError, recoverAndResume, recoverAndResume, subscribe, subscribe, subscribe, toDuplicator, toDuplicator, toInputStream, toInputStream, writeTo
-
Constructor Details
-
DeferredStreamMessage
public DeferredStreamMessage()
-
-
Method Details
-
delegate
Sets the upstreamStreamMessage
which will actually publish the stream.- Throws:
IllegalStateException
- if the upstream has been set already or ifclose()
orclose(Throwable)
was called already.
-
close
public final void close()Closes the deferred stream without setting a delegate.- Throws:
IllegalStateException
- if the upstream has been set already or ifclose()
orclose(Throwable)
was called already.
-
close
Closes the deferred stream without setting a delegate.- Throws:
IllegalStateException
- if the delegate has been set already or ifclose()
orclose(Throwable)
was called already.
-
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
. -
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. -
demand
public final long demand()Description copied from interface:StreamMessage
Returns the current demand of this stream. -
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. -
abort
Description copied from interface:StreamMessage
-
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
. -
subscribe
public final void subscribe(org.reactivestreams.Subscriber<? super T> 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>
- Parameters:
executor
- the executor to subscribe
-
subscribe
public final 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>
- Parameters:
executor
- the executor to subscribeoptions
-SubscriptionOption
s to subscribe with
-
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
-
onRemoval
Invoked after an element is removed from theStreamMessage
and beforeSubscriber.onNext(Object)
is invoked.- Parameters:
obj
- the removed element
-