public abstract class RetrySettings extends Object implements Serializable
The intent of these settings is to be used with a call to a remote server, which could either fail (and return an error code) or not respond (and cause a timeout). When there is a failure or timeout, the logic should keep trying until the total timeout has passed.
The "total timeout" and "max attempts" settings have ultimate control over how long the logic should keep trying the remote call until it gives up completely. The remote call will be retried until one of those thresholds is crossed. To avoid unbounded rpc calls, it is required to configure one of those settings. If both are 0, then retries will be disabled. The other settings are considered more advanced.
Retry delay and timeout start at specific values, and are tracked separately from each other. The very first call (before any retries) will use the initial timeout.
If the last remote call is a failure, then the retrier will wait for the current retry delay before attempting another call, and then the retry delay will be multiplied by the retry delay multiplier for the next failure. The timeout will not be affected, except in the case where the timeout would result in a deadline past the total timeout; in that circumstance, a new timeout value is computed which will terminate the call when the total time is up.
If the last remote call is a timeout, then the retrier will compute a new timeout and make another call. The new timeout is computed by multiplying the current timeout by the timeout multiplier, but if that results in a deadline after the total timeout, then a new timeout value is computed which will terminate the call when the total time is up.
Server streaming RPCs interpret RPC timeouts a bit differently. For server streaming RPCs, the
RPC timeout gets converted into a wait timeout ApiCallContext.withStreamWaitTimeout(Duration).
| Modifier and Type | Class and Description |
|---|---|
static class |
RetrySettings.Builder
A base builder class for
RetrySettings. |
| Constructor and Description |
|---|
RetrySettings() |
| Modifier and Type | Method and Description |
|---|---|
abstract org.threeten.bp.Duration |
getInitialRetryDelay()
InitialRetryDelay controls the delay before the first retry.
|
abstract org.threeten.bp.Duration |
getInitialRpcTimeout()
InitialRpcTimeout controls the timeout for the initial RPC.
|
abstract int |
getMaxAttempts()
MaxAttempts defines the maximum number of attempts to perform.
|
abstract org.threeten.bp.Duration |
getMaxRetryDelay()
MaxRetryDelay puts a limit on the value of the retry delay, so that the RetryDelayMultiplier
can't increase the retry delay higher than this amount.
|
abstract org.threeten.bp.Duration |
getMaxRpcTimeout()
MaxRpcTimeout puts a limit on the value of the RPC timeout, so that the RpcTimeoutMultiplier
can't increase the RPC timeout higher than this amount.
|
abstract double |
getRetryDelayMultiplier()
RetryDelayMultiplier controls the change in retry delay.
|
abstract double |
getRpcTimeoutMultiplier()
RpcTimeoutMultiplier controls the change in RPC timeout.
|
abstract org.threeten.bp.Duration |
getTotalTimeout()
TotalTimeout has ultimate control over how long the logic should keep trying the remote call
until it gives up completely.
|
abstract boolean |
isJittered()
Jitter determines if the delay time should be randomized.
|
static RetrySettings.Builder |
newBuilder() |
abstract RetrySettings.Builder |
toBuilder() |
public abstract org.threeten.bp.Duration getTotalTimeout()
Duration.ZERO.public abstract org.threeten.bp.Duration getInitialRetryDelay()
Duration.ZERO.public abstract double getRetryDelayMultiplier()
1.0.public abstract org.threeten.bp.Duration getMaxRetryDelay()
Duration.ZERO.public abstract int getMaxAttempts()
0.
If this value is greater than 0, and the number of attempts reaches this limit, the logic will
give up retrying even if the total retry time is still lower than TotalTimeout.public abstract boolean isJittered()
true the actual delay time is calculated in the following way:
actualDelay = rand_between(0, min(maxRetryDelay, delay))
The default value is true.public abstract org.threeten.bp.Duration getInitialRpcTimeout()
Duration.ZERO.public abstract double getRpcTimeoutMultiplier()
1.0.public abstract org.threeten.bp.Duration getMaxRpcTimeout()
Duration.ZERO.public static RetrySettings.Builder newBuilder()
public abstract RetrySettings.Builder toBuilder()