Class SimplePublisher<T>
- java.lang.Object
-
- software.amazon.awssdk.utils.async.SimplePublisher<T>
-
- All Implemented Interfaces:
org.reactivestreams.Publisher<T>
public final class SimplePublisher<T> extends Object implements org.reactivestreams.Publisher<T>
APublisher
to which callers cansend(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 singlecomplete()
orerror(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 Constructor Description SimplePublisher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Void>
complete()
Indicate that no moresend(Object)
calls will be made, and that stream of messages is completed successfully.CompletableFuture<Void>
error(Throwable error)
Indicate that no moresend(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.
-
-
-
Method Detail
-
send
public CompletableFuture<Void> send(T value)
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
public CompletableFuture<Void> 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
public CompletableFuture<Void> error(Throwable 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.
-
-