Class SimplePublisher<T>
- All Implemented Interfaces:
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 messages
CompletableFuture
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomplete()
Indicate that no moresend(Object)
calls will be made, and that stream of messages is completed successfully.Indicate that no moresend(Object)
calls will be made, and that streaming of messages has failed.Send a message using this publisher.void
A method called by the downstream subscriber in order to subscribe to the publisher.
-
Constructor Details
-
SimplePublisher
public SimplePublisher()
-
-
Method Details
-
send
Send a message using this publisher.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 acomplete()
orerror(Throwable)
call.- Parameters:
value
- The message to send. Must not be null.- Returns:
- A future that is completed when the message is sent to the subscriber.
-
complete
Indicate that no moresend(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 thecomplete
is sent to the downstream subscriber.After this method is invoked, any future
send(Object)
,complete()
orerror(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 acomplete
orerror(Throwable)
call.- Returns:
- A future that is completed when the complete has been sent to the downstream subscriber.
-
error
Indicate that no moresend(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 theerror
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 acomplete()
orerror
call.- Parameters:
error
- The error to send.- Returns:
- A future that is completed when the exception has been sent to the downstream subscriber.
-
subscribe
-