public class ExponentialRetryAlgorithm extends Object implements TimedRetryAlgorithm
This class is thread-safe.
| Constructor and Description |
|---|
ExponentialRetryAlgorithm(RetrySettings globalSettings,
com.google.api.core.ApiClock clock)
Creates a new exponential retry algorithm instance.
|
| Modifier and Type | Method and Description |
|---|---|
TimedAttemptSettings |
createFirstAttempt()
Creates a first attempt
TimedAttemptSettings. |
TimedAttemptSettings |
createNextAttempt(TimedAttemptSettings prevSettings)
Creates a next attempt
TimedAttemptSettings. |
protected long |
nextRandomLong(long bound) |
boolean |
shouldRetry(TimedAttemptSettings nextAttemptSettings)
Returns
true if another attempt should be made, or false otherwise. |
public ExponentialRetryAlgorithm(RetrySettings globalSettings, com.google.api.core.ApiClock clock)
globalSettings - global retry settings (attempt independent)clock - clock to use for time-specific calculationsNullPointerException - if either globalSettings or clock is nullpublic TimedAttemptSettings createFirstAttempt()
TimedAttemptSettings. The first attempt is configured to be
executed immediately.createFirstAttempt in interface TimedRetryAlgorithmpublic TimedAttemptSettings createNextAttempt(TimedAttemptSettings prevSettings)
TimedAttemptSettings. The implementation increments the current
attempt count and uses randomized exponential backoff factor for calculating next attempt
execution time.createNextAttempt in interface TimedRetryAlgorithmprevSettings - previous attempt settingspublic boolean shouldRetry(TimedAttemptSettings nextAttemptSettings)
true if another attempt should be made, or false otherwise.shouldRetry in interface TimedRetryAlgorithmnextAttemptSettings - attempt settings, which will be used for the next attempt, if
acceptedtrue if nextAttemptSettings does not exceed either maxAttempts limit or
totalTimeout limit, or false otherwiseprotected long nextRandomLong(long bound)