Class EmailRetryExecutor
java.lang.Object
cloud.opencode.base.email.retry.EmailRetryExecutor
Email Retry Executor
邮件发送重试执行器
Executes email sending with automatic retry on failures.
在发送失败时自动重试的邮件发送执行器。
Features | 主要功能:
- Configurable retry count - 可配置重试次数
- Exponential backoff - 指数退避
- Retry callback support - 重试回调支持
- Only retry retryable errors - 仅重试可重试错误
Usage Examples | 使用示例:
EmailRetryExecutor executor = new EmailRetryExecutor(
3, // max retries
Duration.ofSeconds(1), // initial delay
2.0 // backoff multiplier
);
executor.executeWithRetry(email, sender);
// With callback
executor.executeWithRetry(email, sender, (attempt, e) -> {
log.warn("Retry attempt {}: {}", attempt, e.getMessage());
});
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-email V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for EmailRetryExecutor EmailRetryExecutor构建器static interfaceRetry callback interface 重试回调接口 -
Constructor Summary
ConstructorsConstructorDescriptionCreate retry executor with default settings 使用默认设置创建重试执行器EmailRetryExecutor(int maxRetries, Duration initialDelay, double backoffMultiplier) Create retry executor with custom settings 使用自定义设置创建重试执行器EmailRetryExecutor(int maxRetries, Duration initialDelay, double backoffMultiplier, Duration maxDelay) Create retry executor with all settings 使用所有设置创建重试执行器 -
Method Summary
Modifier and TypeMethodDescriptionstatic EmailRetryExecutor.Builderbuilder()Create a builder for EmailRetryExecutor 创建EmailRetryExecutor构建器voidexecuteWithRetry(Email email, cloud.opencode.base.email.internal.EmailSender sender) Execute email sending with retry 执行带重试的邮件发送voidexecuteWithRetry(Email email, cloud.opencode.base.email.internal.EmailSender sender, EmailRetryExecutor.RetryCallback retryCallback) Execute email sending with retry and callback 执行带重试和回调的邮件发送doubleGet backoff multiplier 获取退避因子Get initial delay 获取初始延迟Get max delay 获取最大延迟intGet max retries 获取最大重试次数
-
Constructor Details
-
EmailRetryExecutor
public EmailRetryExecutor()Create retry executor with default settings 使用默认设置创建重试执行器 -
EmailRetryExecutor
Create retry executor with custom settings 使用自定义设置创建重试执行器- Parameters:
maxRetries- max retry attempts | 最大重试次数initialDelay- initial delay between retries | 重试间隔初始延迟backoffMultiplier- backoff multiplier | 退避因子
-
EmailRetryExecutor
public EmailRetryExecutor(int maxRetries, Duration initialDelay, double backoffMultiplier, Duration maxDelay) Create retry executor with all settings 使用所有设置创建重试执行器- Parameters:
maxRetries- max retry attempts | 最大重试次数initialDelay- initial delay between retries | 重试间隔初始延迟backoffMultiplier- backoff multiplier | 退避因子maxDelay- max delay cap | 最大延迟上限
-
-
Method Details
-
executeWithRetry
Execute email sending with retry 执行带重试的邮件发送- Parameters:
email- the email to send | 要发送的邮件sender- the email sender | 邮件发送器- Throws:
EmailException- if all retries fail | 所有重试失败时抛出
-
executeWithRetry
public void executeWithRetry(Email email, cloud.opencode.base.email.internal.EmailSender sender, EmailRetryExecutor.RetryCallback retryCallback) Execute email sending with retry and callback 执行带重试和回调的邮件发送- Parameters:
email- the email to send | 要发送的邮件sender- the email sender | 邮件发送器retryCallback- callback on each retry attempt | 每次重试时的回调- Throws:
EmailException- if all retries fail | 所有重试失败时抛出
-
getMaxRetries
public int getMaxRetries()Get max retries 获取最大重试次数- Returns:
- max retries | 最大重试次数
-
getInitialDelay
-
getBackoffMultiplier
public double getBackoffMultiplier()Get backoff multiplier 获取退避因子- Returns:
- backoff multiplier | 退避因子
-
getMaxDelay
-
builder
Create a builder for EmailRetryExecutor 创建EmailRetryExecutor构建器- Returns:
- the builder | 构建器
-