public final class SimplePublisher<T> extends Object implements org.reactivestreams.Publisher<T>
Publisher
to which callers can send(Object)
messages, simplifying the process of implementing a publisher.
Operations
The SimplePublisher
supports three simplified operations:
send(Object)
for sending messagescomplete()
for indicating the successful end of messageserror(Throwable)
for indicating the unsuccessful end of messagesCompletableFuture
for indicating when the message has been successfully sent.
Callers are expected to invoke a series of send(Object)
s followed by a single complete()
or
error(Throwable)
. See the documentation on each operation for more details.
This publisher will store an unbounded number of messages. It is recommended that callers limit the number of in-flight
send(Object)
operations in order to bound the amount of memory used by this publisher.
Constructor and Description |
---|
SimplePublisher() |
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
complete()
Indicate that no more
send(Object) calls will be made, and that stream of messages is completed successfully. |
CompletableFuture<Void> |
error(Throwable error)
Indicate that no more
send(Object) calls will be made, and that streaming of messages has failed. |
CompletableFuture<Void> |
send(T value)
Send a message using this publisher.
|
void |
subscribe(org.reactivestreams.Subscriber<? super T> s)
A method called by the downstream subscriber in order to subscribe to the publisher.
|
public CompletableFuture<Void> send(T value)
Messages sent using this publisher will eventually be sent to a downstream subscriber, in the order they were written. When the message is sent to the subscriber, the returned future will be completed successfully.
This method may be invoked concurrently when the order of messages is not important.
In the time between when this method is invoked and the returned future is not completed, this publisher stores the request message in memory. Callers are recommended to limit the number of sends in progress at a time to bound the amount of memory used by this publisher.
The returned future will be completed exceptionally if the downstream subscriber cancels the subscription, or
if the send
call was performed after a complete()
or error(Throwable)
call.
value
- The message to send. Must not be null.public CompletableFuture<Void> complete()
send(Object)
calls will be made, and that stream of messages is completed successfully.
This can be called before any in-flight send
calls are complete. Such messages will be processed before the
stream is treated as complete. The returned future will be completed successfully when the complete
is sent to
the downstream subscriber.
After this method is invoked, any future send(Object)
, complete()
or error(Throwable)
calls will be completed exceptionally and not be processed.
The returned future will be completed exceptionally if the downstream subscriber cancels the subscription, or
if the complete
call was performed after a complete
or error(Throwable)
call.
public CompletableFuture<Void> error(Throwable error)
send(Object)
calls will be made, and that streaming of messages has failed.
This can be called before any in-flight send
calls are complete. Such messages will be processed before the
stream is treated as being in-error. The returned future will be completed successfully when the error
is
sent to the downstream subscriber.
After this method is invoked, any future send(Object)
, complete()
or #error(Throwable)
calls will be completed exceptionally and not be processed.
The returned future will be completed exceptionally if the downstream subscriber cancels the subscription, or
if the complete
call was performed after a complete()
or error
call.
error
- The error to send.Copyright © 2023. All rights reserved.