Class EmailRetryExecutor

java.lang.Object
cloud.opencode.base.email.retry.EmailRetryExecutor

public class EmailRetryExecutor extends Object
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:
  • Constructor Details

    • EmailRetryExecutor

      public EmailRetryExecutor()
      Create retry executor with default settings 使用默认设置创建重试执行器
    • EmailRetryExecutor

      public EmailRetryExecutor(int maxRetries, Duration initialDelay, double backoffMultiplier)
      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

      public void executeWithRetry(Email email, cloud.opencode.base.email.internal.EmailSender sender)
      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

      public Duration getInitialDelay()
      Get initial delay 获取初始延迟
      Returns:
      initial delay | 初始延迟
    • getBackoffMultiplier

      public double getBackoffMultiplier()
      Get backoff multiplier 获取退避因子
      Returns:
      backoff multiplier | 退避因子
    • getMaxDelay

      public Duration getMaxDelay()
      Get max delay 获取最大延迟
      Returns:
      max delay | 最大延迟
    • builder

      public static EmailRetryExecutor.Builder builder()
      Create a builder for EmailRetryExecutor 创建EmailRetryExecutor构建器
      Returns:
      the builder | 构建器