Class ExponentialBackOffPolicy
- java.lang.Object
-
- com.google.api.client.http.ExponentialBackOffPolicy
-
- All Implemented Interfaces:
BackOffPolicy
@Beta @Deprecated public class ExponentialBackOffPolicy extends java.lang.Object implements BackOffPolicy
Deprecated.(scheduled to be removed in 1.18). UseHttpBackOffUnsuccessfulResponseHandlerwithExponentialBackOffinstead.Beta
Implementation ofBackOffPolicythat increases the back off period for each retry attempt using a randomization function that grows exponentially.getNextBackOffMillis()is calculated using the following formula:randomized_interval = retry_interval * (random value in range [1 - randomization_factor, 1 + randomization_factor])In other wordsgetNextBackOffMillis()will range between the randomization factor percentage below and above the retry interval. For example, using 2 seconds as the base retry interval and 0.5 as the randomization factor, the actual back off period used in the next retry attempt will be between 1 and 3 seconds.Note: max_interval caps the retry_interval and not the randomized_interval.
If the time elapsed since an
ExponentialBackOffPolicyinstance is created goes past the max_elapsed_time then the methodgetNextBackOffMillis()starts returningBackOffPolicy.STOP. The elapsed time can be reset by callingreset().Example: The default retry_interval is .5 seconds, default randomization_factor is 0.5, default multiplier is 1.5 and the default max_interval is 1 minute. For 10 requests the sequence will be (values in seconds) and assuming we go over the max_elapsed_time on the 10th request:
request# retry_interval randomized_interval 1 0.5 [0.25, 0.75] 2 0.75 [0.375, 1.125] 3 1.125 [0.562, 1.687] 4 1.687 [0.8435, 2.53] 5 2.53 [1.265, 3.795] 6 3.795 [1.897, 5.692] 7 5.692 [2.846, 8.538] 8 8.538 [4.269, 12.807] 9 12.807 [6.403, 19.210] 10 19.210
BackOffPolicy.STOPImplementation is not thread-safe.
- Since:
- 1.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExponentialBackOffPolicy.BuilderDeprecated.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_INITIAL_INTERVAL_MILLISDeprecated.The default initial interval value in milliseconds (0.5 seconds).static intDEFAULT_MAX_ELAPSED_TIME_MILLISDeprecated.The default maximum elapsed time in milliseconds (15 minutes).static intDEFAULT_MAX_INTERVAL_MILLISDeprecated.The default maximum back off time in milliseconds (1 minute).static doubleDEFAULT_MULTIPLIERDeprecated.The default multiplier value (1.5 which is 50% increase per back off).static doubleDEFAULT_RANDOMIZATION_FACTORDeprecated.The default randomization factor (0.5 which results in a random period ranging between 50% below and 50% above the retry interval).private ExponentialBackOffexponentialBackOffDeprecated.Exponential backoff.-
Fields inherited from interface com.google.api.client.http.BackOffPolicy
STOP
-
-
Constructor Summary
Constructors Modifier Constructor Description ExponentialBackOffPolicy()Deprecated.Creates an instance of ExponentialBackOffPolicy using default values.protectedExponentialBackOffPolicy(ExponentialBackOffPolicy.Builder builder)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ExponentialBackOffPolicy.Builderbuilder()Deprecated.Returns an instance of a new builder.intgetCurrentIntervalMillis()Deprecated.Returns the current retry interval in milliseconds.longgetElapsedTimeMillis()Deprecated.Returns the elapsed time in milliseconds since anExponentialBackOffPolicyinstance is created and is reset whenreset()is called.intgetInitialIntervalMillis()Deprecated.Returns the initial retry interval in milliseconds.intgetMaxElapsedTimeMillis()Deprecated.Returns the maximum elapsed time in milliseconds.intgetMaxIntervalMillis()Deprecated.Returns the maximum value of the back off period in milliseconds.doublegetMultiplier()Deprecated.Returns the value to multiply the current interval with for each retry attempt.longgetNextBackOffMillis()Deprecated.Gets the number of milliseconds to wait before retrying an HTTP request.doublegetRandomizationFactor()Deprecated.Returns the randomization factor to use for creating a range around the retry interval.booleanisBackOffRequired(int statusCode)Deprecated.Determines if back off is required based on the specified status code.voidreset()Deprecated.Sets the interval back to the initial retry interval and restarts the timer.
-
-
-
Field Detail
-
DEFAULT_INITIAL_INTERVAL_MILLIS
public static final int DEFAULT_INITIAL_INTERVAL_MILLIS
Deprecated.The default initial interval value in milliseconds (0.5 seconds).- See Also:
- Constant Field Values
-
DEFAULT_RANDOMIZATION_FACTOR
public static final double DEFAULT_RANDOMIZATION_FACTOR
Deprecated.The default randomization factor (0.5 which results in a random period ranging between 50% below and 50% above the retry interval).- See Also:
- Constant Field Values
-
DEFAULT_MULTIPLIER
public static final double DEFAULT_MULTIPLIER
Deprecated.The default multiplier value (1.5 which is 50% increase per back off).- See Also:
- Constant Field Values
-
DEFAULT_MAX_INTERVAL_MILLIS
public static final int DEFAULT_MAX_INTERVAL_MILLIS
Deprecated.The default maximum back off time in milliseconds (1 minute).- See Also:
- Constant Field Values
-
DEFAULT_MAX_ELAPSED_TIME_MILLIS
public static final int DEFAULT_MAX_ELAPSED_TIME_MILLIS
Deprecated.The default maximum elapsed time in milliseconds (15 minutes).- See Also:
- Constant Field Values
-
exponentialBackOff
private final ExponentialBackOff exponentialBackOff
Deprecated.Exponential backoff.
-
-
Constructor Detail
-
ExponentialBackOffPolicy
public ExponentialBackOffPolicy()
Deprecated.Creates an instance of ExponentialBackOffPolicy using default values. To override the defaults usebuilder().initialIntervalMillisis defaulted toDEFAULT_INITIAL_INTERVAL_MILLISrandomizationFactoris defaulted toDEFAULT_RANDOMIZATION_FACTORmultiplieris defaulted toDEFAULT_MULTIPLIERmaxIntervalMillisis defaulted toDEFAULT_MAX_INTERVAL_MILLISmaxElapsedTimeMillisis defaulted inDEFAULT_MAX_ELAPSED_TIME_MILLIS
-
ExponentialBackOffPolicy
protected ExponentialBackOffPolicy(ExponentialBackOffPolicy.Builder builder)
Deprecated.- Parameters:
builder- builder- Since:
- 1.14
-
-
Method Detail
-
isBackOffRequired
public boolean isBackOffRequired(int statusCode)
Deprecated.Determines if back off is required based on the specified status code.The idea is that the servers are only temporarily unavailable, and they should not be overwhelmed when they are trying to get back up.
The default implementation requires back off for 500 and 503 status codes. Subclasses may override if different status codes are required.
- Specified by:
isBackOffRequiredin interfaceBackOffPolicy- Parameters:
statusCode- HTTP status code
-
reset
public final void reset()
Deprecated.Sets the interval back to the initial retry interval and restarts the timer.- Specified by:
resetin interfaceBackOffPolicy
-
getNextBackOffMillis
public long getNextBackOffMillis() throws java.io.IOExceptionDeprecated.Gets the number of milliseconds to wait before retrying an HTTP request. IfBackOffPolicy.STOPis returned, no retries should be made.This method calculates the next back off interval using the formula: randomized_interval = retry_interval +/- (randomization_factor * retry_interval)
Subclasses may override if a different algorithm is required.
- Specified by:
getNextBackOffMillisin interfaceBackOffPolicy- Returns:
- the number of milliseconds to wait when backing off requests, or
BackOffPolicy.STOPif no more retries should be made - Throws:
java.io.IOException
-
getInitialIntervalMillis
public final int getInitialIntervalMillis()
Deprecated.Returns the initial retry interval in milliseconds.
-
getRandomizationFactor
public final double getRandomizationFactor()
Deprecated.Returns the randomization factor to use for creating a range around the retry interval.A randomization factor of 0.5 results in a random period ranging between 50% below and 50% above the retry interval.
-
getCurrentIntervalMillis
public final int getCurrentIntervalMillis()
Deprecated.Returns the current retry interval in milliseconds.
-
getMultiplier
public final double getMultiplier()
Deprecated.Returns the value to multiply the current interval with for each retry attempt.
-
getMaxIntervalMillis
public final int getMaxIntervalMillis()
Deprecated.Returns the maximum value of the back off period in milliseconds. Once the current interval reaches this value it stops increasing.
-
getMaxElapsedTimeMillis
public final int getMaxElapsedTimeMillis()
Deprecated.Returns the maximum elapsed time in milliseconds.If the time elapsed since an
ExponentialBackOffPolicyinstance is created goes past the max_elapsed_time then the methodgetNextBackOffMillis()starts returningBackOffPolicy.STOP. The elapsed time can be reset by callingreset().
-
getElapsedTimeMillis
public final long getElapsedTimeMillis()
Deprecated.Returns the elapsed time in milliseconds since anExponentialBackOffPolicyinstance is created and is reset whenreset()is called.The elapsed time is computed using
System.nanoTime().
-
builder
public static ExponentialBackOffPolicy.Builder builder()
Deprecated.Returns an instance of a new builder.
-
-