Class RetryPolicy
java.lang.Object
com.codename1.ai.RetryPolicy
Decides whether and how long to wait before retrying a failed
LlmClient call. Default policy retries
invalid reference
LlmRateLimitException
(honouring Retry-After) and
invalid reference
LlmModelOverloadedException
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.
-
Method Summary
Modifier and TypeMethodDescriptionlongcomputeDelayMs(Throwable t, int attemptIndex) Returns the delay to wait before the next attempt, honouringRetry-Afterfrom rate-limit exceptions when present.static RetryPolicycustom(int maxAttempts, long initialDelayMs, long maxDelayMs, double multiplier, boolean jitter) static RetryPolicy4 attempts, starting at 500 ms, doubling, capped at 30 s, with jitter.intstatic RetryPolicynone()No retries -- failures are returned to the caller as-is.booleanshouldRetry(Throwable t, int attemptsSoFar) Inspect a thrown exception and decide whether to retry.
-
Method Details
-
exponentialBackoff
4 attempts, starting at 500 ms, doubling, capped at 30 s, with jitter. Good default for chat workloads. -
none
No retries -- failures are returned to the caller as-is. -
custom
public static RetryPolicy custom(int maxAttempts, long initialDelayMs, long maxDelayMs, double multiplier, boolean jitter) -
shouldRetry
Inspect a thrown exception and decide whether to retry. Apps can override to add provider-specific rules (e.g. retry on a custom 5xx code). -
computeDelayMs
Returns the delay to wait before the next attempt, honouringRetry-Afterfrom rate-limit exceptions when present. -
getMaxAttempts
public int getMaxAttempts()
-