Interface StreamWriter<T>
- Type Parameters:
T
- the type of the stream element
- All Known Subinterfaces:
HttpRequestWriter
,HttpResponseWriter
- All Known Implementing Classes:
DefaultStreamMessage
public interface StreamWriter<T>
Produces the objects to be published by a
StreamMessage
.
Life cycle of reference-counted objects
When the following methods are given with a ReferenceCounted
object, such as ByteBuf
and
ByteBufHttpData
, or the Supplier
that provides such an object:
tryWrite(Object)
tryWrite(Supplier)
write(Object)
write(Supplier)
#close(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 Type Method Description void
close()
Closes theStreamMessage
successfully.void
close(Throwable cause)
Closes theStreamMessage
exceptionally.boolean
isOpen()
Returnstrue
if theStreamMessage
is open.default boolean
tryWrite(Supplier<? extends T> o)
Writes the specified objectSupplier
to theStreamMessage
.boolean
tryWrite(T o)
Writes the specified object to theStreamMessage
.CompletableFuture<Void>
whenConsumed()
Returns aCompletableFuture
which is completed when all elements written so far have been consumed by theSubscriber
.default void
write(Supplier<? extends T> o)
Writes the specified objectSupplier
to theStreamMessage
.default void
write(T o)
Writes the specified object to theStreamMessage
.
-
Method Details
-
isOpen
boolean isOpen()Returnstrue
if theStreamMessage
is open. -
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:
- Life cycle of reference-counted objects
-
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:
- Life cycle of reference-counted objects
-
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:
- Life cycle of reference-counted objects
-
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:
- Life cycle of reference-counted objects
-
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.
-