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 Details

    • of

      static <T extends Response> RetryConfigMapping<T> of​(BiFunction<? super ClientRequestContext,​Request,​String> keyFactory, BiFunction<? super ClientRequestContext,​Request,​RetryConfig<T>> retryConfigFactory)
      Creates a RetryConfigMapping that maps keys created by keyFactory to RetryConfigs created by retryConfigFactory. The key produced by keyFactory is used to cache the corresponding RetryConfig produced by retryConfigFactory. So if keyFactory produces a key that has been seen before, the cached RetryConfig is used, and the output of retryConfigFactory 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

      Returns the RetryConfig that maps to the given ClientRequestContext and Request.