Class RetryConfig.Builder
- Enclosing class:
- RetryConfig
RetryConfig instances.
This builder uses the following defaults:
- maxRetries = 0
- initialBackoffMillis = 1000
- backoffMultiplier = 2.0
- connectionTimeoutMillis = 10000
- socketTimeoutMillis = 10000
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbackoffMultiplier(double backoffMultiplier) Sets the multiplier used for exponential backoff between retry attempts.build()Builds a newRetryConfiginstance with the current builder settings.connectionTimeoutMillis(int connectionTimeoutMillis) Sets the connection timeout in milliseconds.initialBackoffMillis(long initialBackoffMillis) Sets the initial backoff time in milliseconds before the first retry attempt.jitterFactor(double jitterFactor) Sets the jitter factor to apply to backoff times.maxRetries(int maxRetries) Sets the maximum number of retry attempts.socketTimeoutMillis(int socketTimeoutMillis) Sets the socket timeout in milliseconds.useJitter(boolean useJitter) Sets whether to apply jitter to backoff times.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
maxRetries
Sets the maximum number of retry attempts.The default value is 3. A value of 0 means no retries will be attempted. Negative values are allowed but not recommended as they don't make practical sense.
- Parameters:
maxRetries- The maximum number of retry attempts- Returns:
- This builder instance for method chaining
-
initialBackoffMillis
Sets the initial backoff time in milliseconds before the first retry attempt.The default value is 1000 (1 second). This is the amount of time to wait before the first retry attempt. Subsequent retry attempts will use exponential backoff based on this value and the backoff multiplier.
- Parameters:
initialBackoffMillis- The initial backoff time in milliseconds- Returns:
- This builder instance for method chaining
-
backoffMultiplier
Sets the multiplier used for exponential backoff between retry attempts.The default value is 2.0. This means that each retry will wait twice as long as the previous retry. For example, with an initial backoff of 1000ms and a multiplier of 2.0, the retry delays would be: 1000ms, 2000ms, 4000ms, etc.
- Parameters:
backoffMultiplier- The backoff multiplier- Returns:
- This builder instance for method chaining
-
connectionTimeoutMillis
Sets the connection timeout in milliseconds.The default value is 10000 (10 seconds). This is the timeout for establishing a connection with the remote server.
- Parameters:
connectionTimeoutMillis- The connection timeout in milliseconds- Returns:
- This builder instance for method chaining
-
socketTimeoutMillis
Sets the socket timeout in milliseconds.The default value is 10000 (10 seconds). This is the timeout for waiting for data from an established connection.
- Parameters:
socketTimeoutMillis- The socket timeout in milliseconds- Returns:
- This builder instance for method chaining
-
useJitter
Sets whether to apply jitter to backoff times.The default value is
true. When set totrue, the system will add randomness to backoff times to prevent synchronized retry storms when multiple clients are retrying at the same time.- Parameters:
useJitter-trueto apply jitter,falseotherwise- Returns:
- This builder instance for method chaining
-
jitterFactor
Sets the jitter factor to apply to backoff times.The default value is 0.5. This means the actual backoff time will be between 50% and 150% of the calculated exponential backoff time. For example, if the calculated backoff time is 1000ms, the actual backoff time will be between 500ms and 1500ms.
- Parameters:
jitterFactor- The jitter factor- Returns:
- This builder instance for method chaining
-
build
Builds a newRetryConfiginstance with the current builder settings.- Returns:
- A new
RetryConfiginstance
-