Interface StreamWriter<T>
-
- Type Parameters:
T
- the type of the stream element
- All Known Subinterfaces:
HttpRequestWriter
,HttpResponseWriter
- All Known Implementing Classes:
DefaultHttpRequest
,DefaultHttpResponse
,DefaultStreamMessage
,EventLoopStreamMessage
public interface StreamWriter<T>
Produces the objects to be published by aStreamMessage
.Life cycle of reference-counted objects
When the following methods are given with a
the object will be released automatically by the stream when it's no longer in use, such as when:ReferenceCounted
object, such asByteBuf
andByteBufHttpData
, or theSupplier
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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
Closes theStreamMessage
successfully.void
close(Throwable cause)
Closes theStreamMessage
exceptionally.default void
close(T obj)
Writes the given object and closes the stream successfully.boolean
isOpen()
Returnstrue
if theStreamMessage
is open.CompletableFuture<Void>
onDemand(Runnable task)
Performs the specifiedtask
when there are enough demands from theSubscriber
.default boolean
tryWrite(Supplier<? extends T> o)
Writes the specified objectSupplier
to theStreamMessage
.boolean
tryWrite(T o)
Writes the specified object to theStreamMessage
.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 Detail
-
isOpen
boolean isOpen()
Returnstrue
if theStreamMessage
is open.
-
write
default void write(T o)
Writes the specified object to theStreamMessage
. The written object will be transferred to theSubscriber
.- Throws:
ClosedPublisherException
- 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
default void write(Supplier<? extends T> o)
Writes the specified objectSupplier
to theStreamMessage
. The object provided by theSupplier
will be transferred to theSubscriber
.- Throws:
ClosedPublisherException
- if the stream was already closed.- See Also:
- Life cycle of reference-counted objects
-
tryWrite
@CheckReturnValue boolean tryWrite(T o)
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
@CheckReturnValue default boolean tryWrite(Supplier<? extends T> o)
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
-
onDemand
CompletableFuture<Void> onDemand(Runnable task)
Performs the specifiedtask
when there are enough demands from theSubscriber
.- Returns:
- the future that completes successfully when the
task
finishes or exceptionally when theStreamMessage
is closed unexpectedly.
-
close
void close()
Closes theStreamMessage
successfully.Subscriber.onComplete()
will be invoked to signal that theSubscriber
has consumed the stream completely.
-
close
void close(Throwable cause)
Closes theStreamMessage
exceptionally.Subscriber.onError(Throwable)
will be invoked to signal that theSubscriber
did not consume the stream completely.
-
close
default void close(T obj)
Writes the given object and closes the stream successfully.
-
-