Record Class RetryPolicy
Only rate limiting (429), evaluator overload (529) and a failed connection are retried. A 401 or a 422 is a statement about the request itself, and repeating it merely spends the caller's rate limit to be told the same thing again.
backoffFor(int, double) is a pure function of the attempt number and a random
fraction supplied by the caller. Keeping the randomness out of the policy is what lets a unit
test assert the schedule without a clock and without a sleep.
-
Constructor Summary
ConstructorsConstructorDescriptionRetryPolicy(int maxAttempts, Duration initialBackoff, double multiplier, Duration maxBackoff, double jitterFactor) Creates an instance of aRetryPolicyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbackoffFor(int attempt, double randomFraction) The wait before the attempt numberedattempt(1 means the wait after the first failure).static RetryPolicydefaults()final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.Returns the value of theinitialBackoffrecord component.doubleReturns the value of thejitterFactorrecord component.intReturns the value of themaxAttemptsrecord component.Returns the value of themaxBackoffrecord component.doubleReturns the value of themultiplierrecord component.The wait before the next attempt when the evaluator may have said how long to wait, or empty when the caller should stop retrying.static booleanretryable(int status) Whether a status is worth repeating the request for.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
RetryPolicy
public RetryPolicy(int maxAttempts, Duration initialBackoff, double multiplier, Duration maxBackoff, double jitterFactor) Creates an instance of aRetryPolicyrecord class.- Parameters:
maxAttempts- the value for themaxAttemptsrecord componentinitialBackoff- the value for theinitialBackoffrecord componentmultiplier- the value for themultiplierrecord componentmaxBackoff- the value for themaxBackoffrecord componentjitterFactor- the value for thejitterFactorrecord component
-
-
Method Details
-
defaults
-
retryable
public static boolean retryable(int status) Whether a status is worth repeating the request for. Deliberately narrow: an unknown 5xx is not retried, because a client that retries everything turns an evaluator's bad day into an outage. -
backoffFor
The wait before the attempt numberedattempt(1 means the wait after the first failure).randomFractionis in 0..1 and comes from the caller's random source. -
nextWait
public Optional<Duration> nextWait(int attempt, double randomFraction, Optional<Duration> serverAsked) The wait before the next attempt when the evaluator may have said how long to wait, or empty when the caller should stop retrying.A wait the server asked for replaces the computed backoff, as the official SDKs do: the server knows when its rate window reopens and the client can only guess. It is used without jitter, since the server has already chosen the moment. A requested wait longer than
maxBackoff()ends the retries rather than being cut short, because retrying before the server said to only earns another 429, and the caller learns the requested wait fromJevApiException.requestedWait()instead. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
maxAttempts
public int maxAttempts()Returns the value of themaxAttemptsrecord component.- Returns:
- the value of the
maxAttemptsrecord component
-
initialBackoff
Returns the value of theinitialBackoffrecord component.- Returns:
- the value of the
initialBackoffrecord component
-
multiplier
public double multiplier()Returns the value of themultiplierrecord component.- Returns:
- the value of the
multiplierrecord component
-
maxBackoff
Returns the value of themaxBackoffrecord component.- Returns:
- the value of the
maxBackoffrecord component
-
jitterFactor
public double jitterFactor()Returns the value of thejitterFactorrecord component.- Returns:
- the value of the
jitterFactorrecord component
-