Class IdempotentAsyncResponseHandler<T,R>
java.lang.Object
software.amazon.awssdk.core.internal.http.IdempotentAsyncResponseHandler<T,R>
- Type Parameters:
T
- The type of the wrappedTransformingAsyncResponseHandler
R
- The type of the object used to determine scope.
- All Implemented Interfaces:
TransformingAsyncResponseHandler<T>
,SdkAsyncHttpResponseHandler
@ThreadSafe
public class IdempotentAsyncResponseHandler<T,R>
extends Object
implements TransformingAsyncResponseHandler<T>
Wrapper for a
TransformingAsyncResponseHandler
that allows attachment to an external scope and given a way
of evaluating whether that scope has changed or not will only allow prepare() to be called on its delegate once
per state change and will cache and reserve the future that is returned by the delegate the rest of the time.
One application of this wrapper is to ensure that prepare() is not called on the underlying response handler more than once per retry no matter where or how many times its invoked.
This class is asserted to be thread-safe and it should be fine to have multiple threads call prepare() simultaneously.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
R> IdempotentAsyncResponseHandler <T, R> create
(TransformingAsyncResponseHandler<T> wrappedHandler, Supplier<R> preparedScopeSupplier, BiPredicate<R, R> scopeInRangePredicate) Creates a new wrappedTransformingAsyncResponseHandler
void
Called when there is an error making the request or receiving the response.void
onHeaders
(SdkHttpResponse headers) Called when the headers have been received.void
onStream
(org.reactivestreams.Publisher<ByteBuffer> stream) Called when the streaming body is ready.prepare()
Return the future holding the transformed response.
-
Method Details
-
create
public static <T,R> IdempotentAsyncResponseHandler<T,R> create(TransformingAsyncResponseHandler<T> wrappedHandler, Supplier<R> preparedScopeSupplier, BiPredicate<R, R> scopeInRangePredicate) Creates a new wrappedTransformingAsyncResponseHandler
- Type Parameters:
T
- The type of the wrappedTransformingAsyncResponseHandler
R
- The type of the object used to determine scope.- Parameters:
wrappedHandler
- A different handler to wrap.preparedScopeSupplier
- A function that retrieves the current scope to determine if a new future can be prepared.scopeInRangePredicate
- A predicate that can be used to test the cached scope against the newly retrieved scope to determine if a new future can be prepared.
-
prepare
Description copied from interface:TransformingAsyncResponseHandler
Return the future holding the transformed response.This method is guaranteed to be called before the request is executed, and before
SdkAsyncHttpResponseHandler.onHeaders(software.amazon.awssdk.http.SdkHttpResponse)
is signaled.- Specified by:
prepare
in interfaceTransformingAsyncResponseHandler<T>
- Returns:
- The future holding the transformed response.
-
onHeaders
Description copied from interface:SdkAsyncHttpResponseHandler
Called when the headers have been received.- Specified by:
onHeaders
in interfaceSdkAsyncHttpResponseHandler
- Parameters:
headers
- The headers.
-
onStream
Description copied from interface:SdkAsyncHttpResponseHandler
Called when the streaming body is ready.This method is always called. If the response does not have a body, then the publisher will complete the subscription without signalling any elements.
- Specified by:
onStream
in interfaceSdkAsyncHttpResponseHandler
- Parameters:
stream
- The streaming body.
-
onError
Description copied from interface:SdkAsyncHttpResponseHandler
Called when there is an error making the request or receiving the response. If the error is encountered while streaming the body, then the error is also delivered to theSubscriber
.- Specified by:
onError
in interfaceSdkAsyncHttpResponseHandler
- Parameters:
error
- The error.
-