/** * Returns a copy of this {@link FluentBackoff} that limits the total number of retries, aka the * total number of calls to {@link BackOff#nextBackOffMillis()} before returning {@link * BackOff#STOP}. * * <p>Does not modify this object. * * @see FluentBackoff */ public FluentBackoff withMaxRetries(int maxRetries) { checkArgument(maxRetries >= 0, "maxRetries %s cannot be negative", maxRetries); return new FluentBackoff( exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxRetries); }
/** * Returns a copy of this {@link FluentBackoff} that instead uses the specified exponent to * control the exponential growth of delay. * * <p>Does not modify this object. * * @see FluentBackoff */ public FluentBackoff withExponent(double exponent) { checkArgument(exponent > 0, "exponent %s must be greater than 0", exponent); return new FluentBackoff( exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxRetries); }
/** * Returns a copy of this {@link FluentBackoff} that limits the maximum backoff of an individual * attempt to the specified duration. * * <p>Does not modify this object. * * @see FluentBackoff */ public FluentBackoff withMaxBackoff(Duration maxBackoff) { checkArgument( maxBackoff.getMillis() > 0, "maxBackoff %s must be at least 1 millisecond", maxBackoff); return new FluentBackoff( exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxRetries); }
/** * Returns a copy of this {@link FluentBackoff} that limits the total time spent in backoff * returned across all calls to {@link BackOff#nextBackOffMillis()}. * * <p>Does not modify this object. * * @see FluentBackoff */ public FluentBackoff withMaxCumulativeBackoff(Duration maxCumulativeBackoff) { checkArgument( maxCumulativeBackoff.isLongerThan(Duration.ZERO), "maxCumulativeBackoff %s must be at least 1 millisecond", maxCumulativeBackoff); return new FluentBackoff( exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxRetries); }
/** * Returns a copy of this {@link FluentBackoff} that instead uses the specified initial backoff * duration. * * <p>Does not modify this object. * * @see FluentBackoff */ public FluentBackoff withInitialBackoff(Duration initialBackoff) { checkArgument( initialBackoff.isLongerThan(Duration.ZERO), "initialBackoff %s must be at least 1 millisecond", initialBackoff); return new FluentBackoff( exponent, initialBackoff, maxBackoff, maxCumulativeBackoff, maxRetries); }