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
The timed retry algorithm which uses jittered exponential backoff factor for calculating the next
attempt execution time.
This class is thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionExponentialRetryAlgorithm(RetrySettings globalSettings, ApiClock clock) Creates a new exponential retry algorithm instance. -
Method Summary
Modifier and TypeMethodDescriptionCreates a first attemptTimedAttemptSettings.createFirstAttempt(RetryingContext context) Creates a first attemptTimedAttemptSettings.createNextAttempt(RetryingContext context, TimedAttemptSettings previousSettings) Creates a next attemptTimedAttemptSettings.createNextAttempt(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.protected booleanshouldRPCTerminate(long timeLeftMs)
-
Constructor Details
-
ExponentialRetryAlgorithm
Creates a new exponential retry algorithm instance.- Parameters:
globalSettings- global retry settings (attempt independent)clock- clock to use for time-specific calculations- Throws:
NullPointerException- if eitherglobalSettingsorclockis null
-
-
Method Details
-
createFirstAttempt
Creates a first attemptTimedAttemptSettings. The first attempt is configured to be executed immediately.- Specified by:
createFirstAttemptin interfaceTimedRetryAlgorithm- Returns:
- first attempt settings
-
createFirstAttempt
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
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
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
-
shouldRPCTerminate
-
shouldRetry
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)
-