Record Class Retry.Policy
java.lang.Object
java.lang.Record
dev.fforj.Retry.Policy
- Record Components:
maxAttempts- total attempts including the first call.1= no retry.initialDelay- delay before the first retry.backoffFactor- delay multiplier between attempts.1.0= fixed delay.maxDelay- upper bound on any single delay after backoff; uncapped exponential backoff gets silly fast. The three-argument constructor defaults it to effectively unbounded.jitter- fraction in[0, 1): each sleep is scaled by a uniform random factor in[1 - jitter, 1 + jitter]to spread synchronized clients ("thundering herds").0(the default) means fully deterministic delays. Keep it0in tests.
- Enclosing class:
Retry
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the value of thebackoffFactorrecord component.delayBefore(int attempt) The planned delay before the given attempt (the first retry is attempt2):initialDelayscaled bybackoffFactoronce per prior retry, capped atmaxDelay.final booleanIndicates whether some other object is "equal to" this one.static Retry.Policyexponential(int maxAttempts, Duration initialDelay) Exponential backoff (doubling) between retries.static Retry.PolicyConstant delay between retries.final inthashCode()Returns a hash code value for this object.Returns the value of theinitialDelayrecord component.doublejitter()Returns the value of thejitterrecord component.intReturns the value of themaxAttemptsrecord component.maxDelay()Returns the value of themaxDelayrecord component.final StringtoString()Returns a string representation of this record class.withJitter(double jitter) Same policy with the given jitter fraction (seejitter).withMaxDelay(Duration maxDelay) Same policy with every delay capped atmaxDelay.
-
Constructor Details
-
Policy
public Policy(int maxAttempts, Duration initialDelay, double backoffFactor, Duration maxDelay, double jitter) Creates an instance of aPolicyrecord class.- Parameters:
maxAttempts- the value for themaxAttemptsrecord componentinitialDelay- the value for theinitialDelayrecord componentbackoffFactor- the value for thebackoffFactorrecord componentmaxDelay- the value for themaxDelayrecord componentjitter- the value for thejitterrecord component
-
Policy
Uncapped, jitter-free policy; the common starting point.
-
-
Method Details
-
fixed
Constant delay between retries. -
exponential
Exponential backoff (doubling) between retries. -
withMaxDelay
Same policy with every delay capped atmaxDelay. -
withJitter
Same policy with the given jitter fraction (seejitter). -
delayBefore
The planned delay before the given attempt (the first retry is attempt2):initialDelayscaled bybackoffFactoronce per prior retry, capped atmaxDelay. Pure and deterministic (jitter is applied at sleep time byRetry.run(Retry.Policy, Predicate, IntFunction), never here), so retry timing can be asserted in tests without sleeping through it. -
toString
-
hashCode
-
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 thecomparemethod from their corresponding wrapper classes. -
maxAttempts
public int maxAttempts()Returns the value of themaxAttemptsrecord component.- Returns:
- the value of the
maxAttemptsrecord component
-
initialDelay
Returns the value of theinitialDelayrecord component.- Returns:
- the value of the
initialDelayrecord component
-
backoffFactor
public double backoffFactor()Returns the value of thebackoffFactorrecord component.- Returns:
- the value of the
backoffFactorrecord component
-
maxDelay
-
jitter
-