Package com.google.api.gax.retrying
Class ExponentialRetryAlgorithm
- java.lang.Object
-
- com.google.api.gax.retrying.ExponentialRetryAlgorithm
-
- All Implemented Interfaces:
TimedRetryAlgorithm,TimedRetryAlgorithmWithContext
- Direct Known Subclasses:
ExponentialPollAlgorithm,OperationTimedPollAlgorithm
public class ExponentialRetryAlgorithm extends java.lang.Object implements TimedRetryAlgorithmWithContext
The timed retry algorithm which uses jittered exponential backoff factor for calculating the next attempt execution time.This class is thread-safe.
-
-
Constructor Summary
Constructors Constructor Description ExponentialRetryAlgorithm(RetrySettings globalSettings, com.google.api.core.ApiClock clock)Creates a new exponential retry algorithm instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TimedAttemptSettingscreateFirstAttempt()Creates a first attemptTimedAttemptSettings.TimedAttemptSettingscreateFirstAttempt(RetryingContext context)Creates a first attemptTimedAttemptSettings.TimedAttemptSettingscreateNextAttempt(RetryingContext context, TimedAttemptSettings previousSettings)Creates a next attemptTimedAttemptSettings.TimedAttemptSettingscreateNextAttempt(TimedAttemptSettings previousSettings)Creates a next attemptTimedAttemptSettings.protected longnextRandomLong(long bound)booleanshouldRetry(RetryingContext context, TimedAttemptSettings nextAttemptSettings)Returnstrueif another attempt should be made, orfalseotherwise.booleanshouldRetry(TimedAttemptSettings nextAttemptSettings)Returnstrueif another attempt should be made, orfalseotherwise.
-
-
-
Constructor Detail
-
ExponentialRetryAlgorithm
public ExponentialRetryAlgorithm(RetrySettings globalSettings, com.google.api.core.ApiClock clock)
Creates a new exponential retry algorithm instance.- Parameters:
globalSettings- global retry settings (attempt independent)clock- clock to use for time-specific calculations- Throws:
java.lang.NullPointerException- if eitherglobalSettingsorclockis null
-
-
Method Detail
-
createFirstAttempt
public TimedAttemptSettings createFirstAttempt()
Creates a first attemptTimedAttemptSettings. The first attempt is configured to be executed immediately.- Specified by:
createFirstAttemptin interfaceTimedRetryAlgorithm- Returns:
- first attempt settings
-
createFirstAttempt
public TimedAttemptSettings createFirstAttempt(RetryingContext context)
Creates a first attemptTimedAttemptSettings. The first attempt is configured to be executed immediately.- Specified by:
createFirstAttemptin interfaceTimedRetryAlgorithmWithContext- Parameters:
context- aRetryingContextthat can contain customRetrySettingsand retryable codes- Returns:
- first attempt settings
-
createNextAttempt
public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSettings)
Creates a next attemptTimedAttemptSettings. The implementation increments the current attempt count and uses randomized exponential backoff factor for calculating next attempt execution time.- Specified by:
createNextAttemptin interfaceTimedRetryAlgorithm- Parameters:
previousSettings- previous attempt settings- Returns:
- next attempt settings
-
createNextAttempt
public TimedAttemptSettings createNextAttempt(RetryingContext context, TimedAttemptSettings previousSettings)
Creates a next attemptTimedAttemptSettings. The implementation increments the current attempt count and uses randomized exponential backoff factor for calculating next attempt execution time.- Specified by:
createNextAttemptin interfaceTimedRetryAlgorithmWithContext- Parameters:
context- aRetryingContextthat can contain customRetrySettingsand retryable codespreviousSettings- previous attempt settings- Returns:
- next attempt settings
-
shouldRetry
public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings)
Returnstrueif another attempt should be made, orfalseotherwise.- Specified by:
shouldRetryin interfaceTimedRetryAlgorithm- Parameters:
nextAttemptSettings- attempt settings, which will be used for the next attempt, if accepted- Returns:
trueifnextAttemptSettingsdoes not exceed either maxAttempts limit or totalTimeout limit, orfalseotherwise
-
shouldRetry
public boolean shouldRetry(RetryingContext context, TimedAttemptSettings nextAttemptSettings)
Returnstrueif another attempt should be made, orfalseotherwise.- Specified by:
shouldRetryin interfaceTimedRetryAlgorithmWithContext- Parameters:
context- aRetryingContextthat can contain customRetrySettingsand retryable codes. Ignored by this implementation.nextAttemptSettings- attempt settings, which will be used for the next attempt, if accepted- Returns:
trueifnextAttemptSettingsdoes not exceed either maxAttempts limit or totalTimeout limit, orfalseotherwise
-
nextRandomLong
protected long nextRandomLong(long bound)
-
-