Class BufferedSplittableAsyncRequestBody
- java.lang.Object
-
- software.amazon.awssdk.core.async.BufferedSplittableAsyncRequestBody
-
- All Implemented Interfaces:
org.reactivestreams.Publisher<ByteBuffer>,AsyncRequestBody,SdkPublisher<ByteBuffer>
public final class BufferedSplittableAsyncRequestBody extends Object implements AsyncRequestBody
AnAsyncRequestBodydecorator that enables splitting into retryable sub-request bodies.This wrapper allows any
AsyncRequestBodyto be split into multiple parts where each part can be retried independently. When split, each sub-body buffers its portion of data, enabling resubscription if a retry is needed (e.g., due to network failures or service errors).Retry Requirements:
Retry is only possible if all the data has been successfully buffered during the first subscription. If the first subscriber fails to consume all the data (e.g., due to early cancellation or errors), subsequent retry attempts will fail since the complete data set is not available for resubscription.
Usage Example:
Performance Considerations:
This implementation buffers data in memory to enable retries, but memory usage is controlled by the
bufferSizeInBytesconfiguration. However, this buffering limits the ability to request more data from the original AsyncRequestBody until buffered data is consumed (i.e., when subscribers closes sub-body), which may increase latency compared to non-buffered implementations.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface software.amazon.awssdk.core.async.AsyncRequestBody
AsyncRequestBody.BodyType
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringbody()Each AsyncRequestBody should return a well-formed name that can be used to identify the implementation.Optional<Long>contentLength()static BufferedSplittableAsyncRequestBodycreate(AsyncRequestBody delegate)Creates a newBufferedSplittableAsyncRequestBodythat wraps the providedAsyncRequestBody.SdkPublisher<CloseableAsyncRequestBody>splitCloseable(AsyncRequestBodySplitConfiguration splitConfiguration)Splits this request body into multiple retryable parts based on the provided configuration.voidsubscribe(org.reactivestreams.Subscriber<? super ByteBuffer> s)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface software.amazon.awssdk.core.async.AsyncRequestBody
contentType, split, split, splitCloseable
-
Methods inherited from interface software.amazon.awssdk.core.async.SdkPublisher
addTrailingData, buffer, doAfterOnCancel, doAfterOnComplete, doAfterOnError, filter, filter, flatMapIterable, limit, map, subscribe
-
-
-
-
Method Detail
-
create
public static BufferedSplittableAsyncRequestBody create(AsyncRequestBody delegate)
Creates a newBufferedSplittableAsyncRequestBodythat wraps the providedAsyncRequestBody.- Parameters:
delegate- theAsyncRequestBodyto wrap and make retryable. Must not be null.- Returns:
- a new
BufferedSplittableAsyncRequestBodyinstance - Throws:
NullPointerException- if delegate is null
-
contentLength
public Optional<Long> contentLength()
- Specified by:
contentLengthin interfaceAsyncRequestBody- Returns:
- The content length of the data being produced.
-
splitCloseable
public SdkPublisher<CloseableAsyncRequestBody> splitCloseable(AsyncRequestBodySplitConfiguration splitConfiguration)
Splits this request body into multiple retryable parts based on the provided configuration.Each part returned by the publisher will be a
CloseableAsyncRequestBodythat buffers its portion of data, enabling resubscription for retry scenarios. This is the key difference from non-buffered splitting - each part can be safely retried without data loss.The splitting process respects the chunk size and buffer size specified in the configuration to optimize memory usage.
The subscriber MUST close each
CloseableAsyncRequestBodyto ensure resource is released- Specified by:
splitCloseablein interfaceAsyncRequestBody- Parameters:
splitConfiguration- configuration specifying how to split the request body- Returns:
- a publisher that emits retryable closable request body parts
- See Also:
AsyncRequestBodySplitConfiguration
-
subscribe
public void subscribe(org.reactivestreams.Subscriber<? super ByteBuffer> s)
- Specified by:
subscribein interfaceorg.reactivestreams.Publisher<ByteBuffer>
-
body
public String body()
Description copied from interface:AsyncRequestBodyEach AsyncRequestBody should return a well-formed name that can be used to identify the implementation. The body name should only include alphanumeric characters.- Specified by:
bodyin interfaceAsyncRequestBody- Returns:
- String containing the identifying name of this AsyncRequestBody implementation.
-
-