class DelayedResponseLevelRetryHandler implements ServiceUnavailableRetryStrategy {

    @Override
    public boolean retryRequest(HttpResponse response, int executionCount, HttpContext ctx) {
        log.fine(() -> String.format("retryRequest(responseCode='%s', executionCount='%d', ctx='%s'",
                                     response.getStatusLine().getStatusCode(), executionCount, ctx));
        HttpClientContext clientCtx = HttpClientContext.adapt(ctx);
        if (!predicate.test(response, clientCtx)) {
            log.fine(() -> String.format("Not retrying for '%s'", ctx));
            return false;
        }
        if (executionCount > maxRetries) {
            log.fine(() -> String.format("Max retries exceeded for '%s'", ctx));
            retryFailedConsumer.onRetryFailed(response, executionCount, clientCtx);
            return false;
        }
        Duration delay = delaySupplier.getDelay(executionCount);
        log.fine(() -> String.format("Retrying after %s for '%s'", delay, ctx));
        retryInterval.set(delay.toMillis());
        retryConsumer.onRetry(response, delay, executionCount, clientCtx);
        return true;
    }

    private  DelayedResponseLevelRetryHandler(
            DelaySupplier delaySupplier,
            int maxRetries,
            RetryPredicate<HttpResponse> predicate,
            RetryConsumer<HttpResponse> retryConsumer,
            RetryFailedConsumer<HttpResponse> retryFailedConsumer);

}