UTIL_Retry.Strategy
Class
global interface UTIL_Retry.StrategyInterface defining the retry strategy logic. Implement this interface to create custom retry strategies.
Methods
| Method | Description |
|---|---|
| global abstract Integer calculateBackoff(UTIL_Retry.Context context) | Calculates the backoff period in seconds for the next retry |
| global abstract Boolean shouldRetry(UTIL_Retry.Context context) | Determines if a retry should be attempted |
| global abstract UTIL_Retry.Strategy withBaseBackoff(Integer seconds) | Sets the base backoff period in seconds (fluent API) |
| global abstract UTIL_Retry.Strategy withExponentialMultiplier(Decimal multiplier) | Sets the exponential multiplier for exponential backoff (fluent API) |
| global abstract UTIL_Retry.Strategy withJitter(Boolean enabled) | Enables or disables random jitter (fluent API) |
| global abstract UTIL_Retry.Strategy withMaximumBackoff(Integer seconds) | Sets the maximum backoff cap in seconds (fluent API) |
| global abstract UTIL_Retry.Strategy withMaxRetries(Integer max) | Sets the maximum retry attempts (fluent API) |
calculateBackoff
global abstract Integer calculateBackoff(UTIL_Retry.Context context)Calculates the backoff period in seconds for the next retry
Parameters
| Parameter | Type | Description |
|---|---|---|
context | UTIL_Retry.Context | The retry context containing retry count and configuration |
Returns Integer — The backoff period in seconds
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.exponential();
UTIL_Retry.Context ctx = UTIL_Retry.newContext(1);
Integer backoffSeconds = strategy.calculateBackoff(ctx);
Datetime nextRetry = Datetime.now().addSeconds(backoffSeconds);shouldRetry
global abstract Boolean shouldRetry(UTIL_Retry.Context context)Determines if a retry should be attempted
Parameters
| Parameter | Type | Description |
|---|---|---|
context | UTIL_Retry.Context | The retry context containing retry count and configuration |
Returns Boolean — True if a retry should be attempted, false otherwise
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.exponential();
UTIL_Retry.Context ctx = UTIL_Retry.newContext(2);
if(strategy.shouldRetry(ctx))
{
// Perform retry logic
}withBaseBackoff
global abstract UTIL_Retry.Strategy withBaseBackoff(Integer seconds)Sets the base backoff period in seconds (fluent API)
Parameters
| Parameter | Type | Description |
|---|---|---|
seconds | Integer | The base backoff period |
Returns UTIL_Retry.Strategy — This strategy for method chaining
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.linear()
.withBaseBackoff(15);withExponentialMultiplier
global abstract UTIL_Retry.Strategy withExponentialMultiplier(Decimal multiplier)Sets the exponential multiplier for exponential backoff (fluent API)
Parameters
| Parameter | Type | Description |
|---|---|---|
multiplier | Decimal | The exponential multiplier (must be >= 1.0, default: 2.0) |
Returns UTIL_Retry.Strategy — This strategy for method chaining
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.exponential()
.withExponentialMultiplier(3.0); // Faster backoff growthwithJitter
global abstract UTIL_Retry.Strategy withJitter(Boolean enabled)Enables or disables random jitter (fluent API)
Parameters
| Parameter | Type | Description |
|---|---|---|
enabled | Boolean | Whether to enable jitter (adds up to 25% randomness) |
Returns UTIL_Retry.Strategy — This strategy for method chaining
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.exponential()
.withJitter(true);withMaximumBackoff
global abstract UTIL_Retry.Strategy withMaximumBackoff(Integer seconds)Sets the maximum backoff cap in seconds (fluent API)
Parameters
| Parameter | Type | Description |
|---|---|---|
seconds | Integer | Maximum backoff cap in seconds |
Returns UTIL_Retry.Strategy — This strategy for method chaining
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.exponential()
.withMaximumBackoff(600); // Cap at 10 minuteswithMaxRetries
global abstract UTIL_Retry.Strategy withMaxRetries(Integer max)Sets the maximum retry attempts (fluent API)
Parameters
| Parameter | Type | Description |
|---|---|---|
max | Integer | The maximum retry attempts |
Returns UTIL_Retry.Strategy — This strategy for method chaining
Example
UTIL_Retry.Strategy strategy = UTIL_Retry.exponential()
.withMaxRetries(5);