Class RetryExceptionHandler
java.lang.Object
cloud.opencode.base.event.handler.RetryExceptionHandler
- All Implemented Interfaces:
EventExceptionHandler
Retry Exception Handler
重试异常处理器
Exception handler that retries failed listeners with backoff.
使用退避策略重试失败监听器的异常处理器。
Features | 主要功能:
- Configurable retry count - 可配置的重试次数
- Delay between retries - 重试之间的延迟
- Dead letter queue - 死信队列
Usage Examples | 使用示例:
RetryExceptionHandler handler = new RetryExceptionHandler(3, Duration.ofSeconds(1));
// With retry action
handler.setRetryAction(event -> eventBus.publish(event));
// Process dead letters
handler.processDeadLetters(failedEvent -> {
log.error("Permanently failed: {}", failedEvent);
});
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-event V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordFailed Event Record 失败事件记录 -
Constructor Summary
ConstructorsConstructorDescriptionCreate retry handler with default settings 使用默认设置创建重试处理器RetryExceptionHandler(int maxRetries, Duration delay) Create retry handler with custom settings 使用自定义设置创建重试处理器 -
Method Summary
Modifier and TypeMethodDescriptionvoidClear dead letter queue 清除死信队列intGet dead letter queue size 获取死信队列大小getDelay()Get retry delay 获取重试延迟intGet max retries 获取最大重试次数voidhandleException(Event event, Throwable exception, String listenerName) Handle exception with retry logic 使用重试逻辑处理异常voidProcess dead letter queue 处理死信队列voidsetRetryAction(Consumer<Event> retryAction) Set the retry action 设置重试动作
-
Constructor Details
-
RetryExceptionHandler
public RetryExceptionHandler()Create retry handler with default settings 使用默认设置创建重试处理器 -
RetryExceptionHandler
Create retry handler with custom settings 使用自定义设置创建重试处理器- Parameters:
maxRetries- max retry attempts | 最大重试次数delay- delay between retries | 重试之间的延迟
-
-
Method Details
-
setRetryAction
-
handleException
Handle exception with retry logic 使用重试逻辑处理异常- Specified by:
handleExceptionin interfaceEventExceptionHandler- Parameters:
event- the event being processed | 正在处理的事件exception- the exception that occurred | 发生的异常listenerName- the name of the listener that threw | 抛出异常的监听器名称
-
processDeadLetters
Process dead letter queue 处理死信队列- Parameters:
handler- the handler for failed events | 失败事件的处理器
-
getDeadLetterQueueSize
public int getDeadLetterQueueSize()Get dead letter queue size 获取死信队列大小- Returns:
- queue size | 队列大小
-
clearDeadLetterQueue
public void clearDeadLetterQueue()Clear dead letter queue 清除死信队列 -
getMaxRetries
public int getMaxRetries()Get max retries 获取最大重试次数- Returns:
- max retries | 最大重试次数
-
getDelay
-