public class ExponentialRetryAlgorithm extends Object implements TimedRetryAlgorithmWithContext
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 |
createFirstAttempt(RetryingContext context)
Creates a first attempt
TimedAttemptSettings. |
TimedAttemptSettings |
createNextAttempt(RetryingContext context,
TimedAttemptSettings previousSettings)
Creates a next attempt
TimedAttemptSettings. |
TimedAttemptSettings |
createNextAttempt(TimedAttemptSettings previousSettings)
Creates a next attempt
TimedAttemptSettings. |
protected long |
nextRandomLong(long bound) |
boolean |
shouldRetry(RetryingContext context,
TimedAttemptSettings nextAttemptSettings)
Returns
true if another attempt should be made, or false otherwise. |
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 createFirstAttempt(RetryingContext context)
TimedAttemptSettings. The first attempt is configured to be
executed immediately.createFirstAttempt in interface TimedRetryAlgorithmWithContextcontext - a RetryingContext that can contain custom RetrySettings and
retryable codespublic TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSettings)
TimedAttemptSettings. The implementation increments the current
attempt count and uses randomized exponential backoff factor for calculating next attempt
execution time.createNextAttempt in interface TimedRetryAlgorithmpreviousSettings - previous attempt settingspublic TimedAttemptSettings createNextAttempt(RetryingContext context, TimedAttemptSettings previousSettings)
TimedAttemptSettings. The implementation increments the current
attempt count and uses randomized exponential backoff factor for calculating next attempt
execution time.createNextAttempt in interface TimedRetryAlgorithmWithContextcontext - a RetryingContext that can contain custom RetrySettings and
retryable codespreviousSettings - 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 otherwisepublic boolean shouldRetry(RetryingContext context, TimedAttemptSettings nextAttemptSettings)
true if another attempt should be made, or false otherwise.shouldRetry in interface TimedRetryAlgorithmWithContextcontext - a RetryingContext that can contain custom RetrySettings and
retryable codes. Ignored by this implementation.nextAttemptSettings - 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)