public final class RetryPolicy

  1. Object
  2. RetryPolicy

Decides whether and how long to wait before retrying a failed LlmClient call. Default policy retries LlmRateLimitException (honouring Retry-After) and LlmModelOverloadedException with exponential backoff + jitter; other failures are surfaced immediately.

Wire a policy onto a request like this:

AsyncResource<ChatResponse> r = RetryPolicy.exponentialBackoff()
        .runChat(client, request);

The synchronous block runs on the calling thread. On the EDT it uses Display.invokeAndBlock automatically so the UI stays responsive between attempts.

Methods

public static RetryPolicy exponentialBackoff()4 attempts, starting at 500 ms, doubling, capped at 30 s, with jitter.
public static RetryPolicy none()No retries – failures are returned to the caller as-is.
public static RetryPolicy custom(int maxAttempts, long initialDelayMs, long maxDelayMs, double multiplier, boolean jitter)Creates a bounded exponential retry policy.
public boolean shouldRetry(Throwable t, int attemptsSoFar)Inspects a thrown exception and decides whether this policy permits another attempt.
public long computeDelayMs(Throwable t, int attemptIndex)Returns the delay to wait before the next attempt, honouring Retry-After from rate-limit exceptions when present.
public int getMaxAttempts()

Inherited methods

Method details

exponentialBackoff

public static RetryPolicy exponentialBackoff()
4 attempts, starting at 500 ms, doubling, capped at 30 s, with jitter. Good default for chat workloads.

Returns

recommended transient-failure policy

none

public static RetryPolicy none()
No retries – failures are returned to the caller as-is.

Returns

single-attempt policy

custom

public static RetryPolicy custom(int maxAttempts, long initialDelayMs, long maxDelayMs, double multiplier, boolean jitter)
Creates a bounded exponential retry policy.

Parameters

maxAttempts int
total attempts including the initial call
initialDelayMs long
delay before the first retry
maxDelayMs long
upper bound for computed delays
multiplier double
growth factor applied after each attempt
jitter boolean
whether to randomize each delay from zero to its bound

Returns

normalized retry policy

shouldRetry

public boolean shouldRetry(Throwable t, int attemptsSoFar)
Inspects a thrown exception and decides whether this policy permits another attempt.

Parameters

t Throwable
operation failure
attemptsSoFar int
attempts already made, including the failed one

Returns

true for a transient failure within the attempt limit

computeDelayMs

public long computeDelayMs(Throwable t, int attemptIndex)
Returns the delay to wait before the next attempt, honouring Retry-After from rate-limit exceptions when present.

Parameters

t Throwable
failure that triggered the retry
attemptIndex int
zero-based retry index

Returns

delay in milliseconds

getMaxAttempts

public int getMaxAttempts()

Returns

total allowed attempts including the initial call