Interface StreamWriter<T>
- Type Parameters:
T
- the type of the stream element
- All Superinterfaces:
org.reactivestreams.Publisher<T>
,StreamMessage<T>
- All Known Subinterfaces:
HttpRequestWriter
,HttpResponseWriter
,WebSocketWriter
- All Known Implementing Classes:
DefaultStreamMessage
Produces the objects to be published by a
StreamMessage
.
Life cycle of reference-counted objects
When the following methods are given with a pooled HttpData
or the Supplier
that
provides such an object:
- The method returns
false
or raises an exception. - The
Subscriber
of the stream consumes it. - The stream is cancelled, aborted or failed.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes theStreamMessage
successfully.void
Closes theStreamMessage
exceptionally.boolean
isOpen()
Returnstrue
if theStreamMessage
is open.default boolean
Writes the specified objectSupplier
to theStreamMessage
.boolean
Writes the specified object to theStreamMessage
.Returns aCompletableFuture
which is completed when all elements written so far have been consumed by theSubscriber
.default void
Writes the specified objectSupplier
to theStreamMessage
.default void
Writes the specified object to theStreamMessage
.Methods inherited from interface com.linecorp.armeria.common.stream.StreamMessage
abort, abort, collect, collect, collect, decode, decode, defaultSubscriberExecutor, demand, endWith, filter, isComplete, isEmpty, map, mapAsync, mapError, mapParallel, mapParallel, peek, peek, peekError, recoverAndResume, recoverAndResume, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, subscribeOn, toDuplicator, toDuplicator, toInputStream, toInputStream, whenComplete, writeTo
-
Method Details
-
isOpen
boolean isOpen()Returnstrue
if theStreamMessage
is open.- Specified by:
isOpen
in interfaceStreamMessage<T>
-
write
Writes the specified object to theStreamMessage
. The written object will be transferred to theSubscriber
.- Throws:
ClosedStreamException
- if the stream was already closedIllegalArgumentException
- if the publication of the specified object has been rejected- See Also:
-
write
Writes the specified objectSupplier
to theStreamMessage
. The object provided by theSupplier
will be transferred to theSubscriber
.- Throws:
ClosedStreamException
- if the stream was already closed.- See Also:
-
tryWrite
Writes the specified object to theStreamMessage
. The written object will be transferred to theSubscriber
.- Returns:
true
if the specified object has been scheduled for publication.false
if the stream has been closed already.- Throws:
IllegalArgumentException
- if the publication of the specified object has been rejected- See Also:
-
tryWrite
Writes the specified objectSupplier
to theStreamMessage
. The object provided by theSupplier
will be transferred to theSubscriber
.- Returns:
true
if the specified object has been scheduled for publication.false
if the stream has been closed already.- See Also:
-
whenConsumed
CompletableFuture<Void> whenConsumed()Returns aCompletableFuture
which is completed when all elements written so far have been consumed by theSubscriber
.- Returns:
- the future which completes successfully when all elements written so far have been consumed,
or exceptionally when the
StreamMessage
has been closed unexpectedly.
-
close
void close()Closes theStreamMessage
successfully.Subscriber.onComplete()
will be invoked to signal that theSubscriber
has consumed the stream completely. -
close
Closes theStreamMessage
exceptionally.Subscriber.onError(Throwable)
will be invoked to signal that theSubscriber
did not consume the stream completely.
-