Package com.contentstack.sdk
Class RetryOptions
- java.lang.Object
-
- com.contentstack.sdk.RetryOptions
-
public class RetryOptions extends Object
Configuration options for HTTP request retry mechanism.This class allows customization of retry behavior for failed HTTP requests. By default, retries are enabled with exponential backoff strategy.
Default Configuration:
- Retry limit: 3 attempts
- Retry delay: 1000ms (1 second)
- Backoff strategy: EXPONENTIAL
- Retryable status codes: 408, 429, 502, 503, 504
- Retry enabled: true
Example Usage:
// Custom retry configuration RetryOptions options = new RetryOptions() .setRetryLimit(5) .setRetryDelay(2000) .setBackoffStrategy(BackoffStrategy.LINEAR) .setRetryableStatusCodes(429, 502, 503); Config config = new Config(); config.setRetryOptions(options); // Disable retries RetryOptions noRetry = new RetryOptions().setRetryEnabled(false);- Since:
- 2.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRetryOptions.BackoffStrategyDefines how delay between retries is calculated.
-
Constructor Summary
Constructors Constructor Description RetryOptions()Creates RetryOptions with default configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RetryOptions.BackoffStrategygetBackoffStrategy()Returns the backoff strategy used for calculating retry delays.CustomBackoffStrategygetCustomBackoffStrategy()Returns the custom backoff strategy.int[]getRetryableStatusCodes()Returns the HTTP status codes that trigger retries.longgetRetryDelay()Returns the base delay in milliseconds between retry attempts.intgetRetryLimit()Returns the maximum number of retry attempts.booleanhasCustomBackoff()Checks if custom backoff is configured.booleanisRetryEnabled()Returns whether the retry mechanism is enabled.RetryOptionssetBackoffStrategy(RetryOptions.BackoffStrategy strategy)Sets the backoff strategy for calculating retry delays.RetryOptionssetCustomBackoffStrategy(CustomBackoffStrategy customStrategy)Sets the custom backoff strategy.RetryOptionssetRetryableStatusCodes(int... codes)Sets the HTTP status codes that should trigger a retry.RetryOptionssetRetryDelay(long delayMs)Sets the base delay between retry attempts in milliseconds.RetryOptionssetRetryEnabled(boolean enabled)Enables or disables the retry mechanism.RetryOptionssetRetryLimit(int limit)Sets the maximum number of retry attempts.StringtoString()Returns a string representation of the retry configuration.
-
-
-
Method Detail
-
setRetryLimit
public RetryOptions setRetryLimit(int limit)
Sets the maximum number of retry attempts.- Parameters:
limit- maximum retry attempts (0-10)- Returns:
- this RetryOptions instance for method chaining
- Throws:
IllegalArgumentException- if limit is negative or exceeds maximum
-
setRetryDelay
public RetryOptions setRetryDelay(long delayMs)
Sets the base delay between retry attempts in milliseconds.- Parameters:
delayMs- base delay in milliseconds (must be non-negative)- Returns:
- this RetryOptions instance for method chaining
- Throws:
IllegalArgumentException- if delay is negative
-
setBackoffStrategy
public RetryOptions setBackoffStrategy(RetryOptions.BackoffStrategy strategy)
Sets the backoff strategy for calculating retry delays.- Parameters:
strategy- backoff strategy (FIXED, LINEAR, or EXPONENTIAL)- Returns:
- this RetryOptions instance for method chaining
- Throws:
NullPointerException- if strategy is null
-
setRetryableStatusCodes
public RetryOptions setRetryableStatusCodes(int... codes)
Sets the HTTP status codes that should trigger a retry.Only requests that fail with these status codes will be retried. Other status codes will fail immediately.
If null or empty array is provided, no status code-based retries will occur.
- Parameters:
codes- HTTP status codes to retry (e.g., 429, 502, 503)- Returns:
- this RetryOptions instance for method chaining
- Throws:
IllegalArgumentException- if any status code is outside valid HTTP range (100-599)
-
setRetryEnabled
public RetryOptions setRetryEnabled(boolean enabled)
Enables or disables the retry mechanism.When disabled, no retries will occur regardless of other settings.
- Parameters:
enabled- true to enable retries, false to disable- Returns:
- this RetryOptions instance for method chaining
-
setCustomBackoffStrategy
public RetryOptions setCustomBackoffStrategy(CustomBackoffStrategy customStrategy)
Sets the custom backoff strategy.
-
getCustomBackoffStrategy
public CustomBackoffStrategy getCustomBackoffStrategy()
Returns the custom backoff strategy.
-
hasCustomBackoff
public boolean hasCustomBackoff()
Checks if custom backoff is configured.
-
getRetryLimit
public int getRetryLimit()
Returns the maximum number of retry attempts.- Returns:
- retry limit (0-10)
-
getRetryDelay
public long getRetryDelay()
Returns the base delay in milliseconds between retry attempts.- Returns:
- retry delay in milliseconds
-
getBackoffStrategy
public RetryOptions.BackoffStrategy getBackoffStrategy()
Returns the backoff strategy used for calculating retry delays.- Returns:
- backoff strategy (FIXED, LINEAR, or EXPONENTIAL)
-
getRetryableStatusCodes
public int[] getRetryableStatusCodes()
Returns the HTTP status codes that trigger retries.Returns a copy to prevent external modification.
- Returns:
- array of retryable HTTP status codes
-
isRetryEnabled
public boolean isRetryEnabled()
Returns whether the retry mechanism is enabled.- Returns:
- true if retry is enabled, false otherwise
-
-