Interface SdkPublisher<T>
-
- All Superinterfaces:
org.reactivestreams.Publisher<T>
- All Known Subinterfaces:
AsyncRequestBody
- All Known Implementing Classes:
AsyncRequestBodyListener.NotifyingAsyncRequestBody
,BlockingInputStreamAsyncRequestBody
,BlockingOutputStreamAsyncRequestBody
,ByteBuffersAsyncRequestBody
,ChecksumCalculatingAsyncRequestBody
,ChecksumValidatingPublisher
,CompressionAsyncRequestBody
,EnvelopeWrappedSdkPublisher
,FileAsyncRequestBody
,InputStreamWithExecutorAsyncRequestBody
,PaginatedItemsPublisher
,PublisherListener.NotifyingPublisher
,ResponsePublisher
,SplittingPublisher
public interface SdkPublisher<T> extends org.reactivestreams.Publisher<T>
Interface that is implemented by the Async auto-paginated responses.
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <T> SdkPublisher<T>
adapt(org.reactivestreams.Publisher<T> toAdapt)
Adapts aPublisher
toSdkPublisher
.default SdkPublisher<T>
addTrailingData(Supplier<Iterable<T>> trailingDataSupplier)
Creates a new publisher that emits trailing events provided bytrailingDataSupplier
in addition to the published events.default SdkPublisher<List<T>>
buffer(int bufferSize)
Buffers the events into lists of the given buffer size.default SdkPublisher<T>
doAfterOnCancel(Runnable afterOnCancel)
Add a callback that will be invoked after this publisher invokesSubscription.cancel()
.default SdkPublisher<T>
doAfterOnComplete(Runnable afterOnComplete)
Add a callback that will be invoked after this publisher invokesSubscriber.onComplete()
.default SdkPublisher<T>
doAfterOnError(Consumer<Throwable> afterOnError)
Add a callback that will be invoked after this publisher invokesSubscriber.onError(Throwable)
.default <U extends T>
SdkPublisher<U>filter(Class<U> clzz)
Filters published events to just those that are instances of the given class.default SdkPublisher<T>
filter(Predicate<T> predicate)
Filters published events to just those that match the given predicate.default <U> SdkPublisher<U>
flatMapIterable(Function<T,Iterable<U>> mapper)
Performs a mapping on the published events and creates a new publisher that emits the mapped events one by one.default SdkPublisher<T>
limit(int limit)
Limit the number of published events and cancel the subscription after that limit has been reached.default <U> SdkPublisher<U>
map(Function<T,U> mapper)
Perform a mapping on the published events.default CompletableFuture<Void>
subscribe(Consumer<T> consumer)
Subscribes to the publisher with the givenConsumer
.
-
-
-
Method Detail
-
adapt
static <T> SdkPublisher<T> adapt(org.reactivestreams.Publisher<T> toAdapt)
Adapts aPublisher
toSdkPublisher
.- Type Parameters:
T
- Type of object being published.- Parameters:
toAdapt
-Publisher
to adapt.- Returns:
- SdkPublisher
-
filter
default <U extends T> SdkPublisher<U> filter(Class<U> clzz)
Filters published events to just those that are instances of the given class. This changes the type of publisher to the type specified in theClass
.- Type Parameters:
U
- Type of class to filter to.- Parameters:
clzz
- Class to filter to. Includes subtypes of the class.- Returns:
- New publisher, filtered to the given class.
-
filter
default SdkPublisher<T> filter(Predicate<T> predicate)
Filters published events to just those that match the given predicate. Unlikefilter(Class)
, this method does not change the type of thePublisher
.- Parameters:
predicate
- Predicate to match events.- Returns:
- New publisher, filtered to just the events that match the predicate.
-
map
default <U> SdkPublisher<U> map(Function<T,U> mapper)
Perform a mapping on the published events. Returns a new publisher of the mapped events. Typically this method will change the type of the publisher.- Type Parameters:
U
- Type being mapped to.- Parameters:
mapper
- Mapping function to apply.- Returns:
- New publisher with events mapped according to the given function.
-
flatMapIterable
default <U> SdkPublisher<U> flatMapIterable(Function<T,Iterable<U>> mapper)
Performs a mapping on the published events and creates a new publisher that emits the mapped events one by one.- Type Parameters:
U
- Type of flattened event being mapped to.- Parameters:
mapper
- Mapping function that produces anIterable
of new events to be flattened.- Returns:
- New publisher of flattened events.
-
buffer
default SdkPublisher<List<T>> buffer(int bufferSize)
Buffers the events into lists of the given buffer size. Note that the last batch of events may be less than the buffer size.- Parameters:
bufferSize
- Number of events to buffer before delivering downstream.- Returns:
- New publisher of buffered events.
-
limit
default SdkPublisher<T> limit(int limit)
Limit the number of published events and cancel the subscription after that limit has been reached. The limit may never be reached if the downstream publisher doesn't have many events to publish. Once it reaches the limit, subsequent requests will be ignored.- Parameters:
limit
- Number of events to publish.- Returns:
- New publisher that will only publish up to the specified number of events.
-
addTrailingData
default SdkPublisher<T> addTrailingData(Supplier<Iterable<T>> trailingDataSupplier)
Creates a new publisher that emits trailing events provided bytrailingDataSupplier
in addition to the published events.- Parameters:
trailingDataSupplier
- supplier to provide the trailing data- Returns:
- New publisher that will publish additional events
-
doAfterOnComplete
default SdkPublisher<T> doAfterOnComplete(Runnable afterOnComplete)
Add a callback that will be invoked after this publisher invokesSubscriber.onComplete()
.- Parameters:
afterOnComplete
- The logic that should be run immediately after onComplete.- Returns:
- New publisher that invokes the requested callback.
-
doAfterOnError
default SdkPublisher<T> doAfterOnError(Consumer<Throwable> afterOnError)
Add a callback that will be invoked after this publisher invokesSubscriber.onError(Throwable)
.- Parameters:
afterOnError
- The logic that should be run immediately after onError.- Returns:
- New publisher that invokes the requested callback.
-
doAfterOnCancel
default SdkPublisher<T> doAfterOnCancel(Runnable afterOnCancel)
Add a callback that will be invoked after this publisher invokesSubscription.cancel()
.- Parameters:
afterOnCancel
- The logic that should be run immediately after cancellation of the subscription.- Returns:
- New publisher that invokes the requested callback.
-
subscribe
default CompletableFuture<Void> subscribe(Consumer<T> consumer)
Subscribes to the publisher with the givenConsumer
. This consumer will be called for each event published. There is no backpressure using this method if the Consumer dispatches processing asynchronously. If more control over backpressure is required, consider usingPublisher.subscribe(Subscriber)
.- Parameters:
consumer
- Consumer to process event.- Returns:
- CompletableFuture that will be notified when all events have been consumed or if an error occurs.
-
-