Interface RetryConfigMapping<T extends Response>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface RetryConfigMapping<T extends Response>
Returns a
RetryConfig
given the ClientRequestContext
.
Allows users to change retry behavior according to any context element, like host, method, path ...etc.-
Method Summary
Modifier and Type Method Description RetryConfig<T>
get(ClientRequestContext ctx, Request req)
static <T extends Response>
RetryConfigMapping<T>of(BiFunction<? super ClientRequestContext,Request,String> keyFactory, BiFunction<? super ClientRequestContext,Request,RetryConfig<T>> retryConfigFactory)
Creates aRetryConfigMapping
that maps keys created bykeyFactory
toRetryConfig
s created byretryConfigFactory
.
-
Method Details
-
of
static <T extends Response> RetryConfigMapping<T> of(BiFunction<? super ClientRequestContext,Request,String> keyFactory, BiFunction<? super ClientRequestContext,Request,RetryConfig<T>> retryConfigFactory)Creates aRetryConfigMapping
that maps keys created bykeyFactory
toRetryConfig
s created byretryConfigFactory
. The key produced bykeyFactory
is used to cache the correspondingRetryConfig
produced byretryConfigFactory
. So ifkeyFactory
produces a key that has been seen before, the cachedRetryConfig
is used, and the output ofretryConfigFactory
is ignored. Example:BiFunction<ClientRequestContext, Request, String> keyFactory = (ctx, req) -> ctx.endpoint().host(); BiFunction<ClientRequestContext, Request, RetryConfig<HttpResponse>> configFactory = (ctx, req) -> { if (ctx.endpoint().host().equals("host1")) { return RetryConfig.<HttpResponse>builder(RetryRule.onException()).maxTotalAttempts(2).build(); } else if (ctx.endpoint().host().equals("host2")) { return RetryConfig.<HttpResponse>builder(RetryRule.onException()).maxTotalAttempts(4).build(); } else { return RetryConfig.<HttpResponse>builder(RetryRule.onException()).maxTotalAttempts(1).build(); } }; RetryConfigMapping mapping = RetryConfigMapping.of(keyFactory, configFactory);
-
get
-