1、举例:handleExceptionsWith设置
disruptor.handleExceptionsWith(exceptionHandler);
disruptor.handleEventsWith(handler);
2、举例:handleExceptionsWith方式设置需要在handler注册前设置
disruptor.handleExceptionsWith(exceptionHandler);
disruptor.handleEventsWith(handler);
disruptor.handleExceptionsWith(new FatalExceptionHandler());
注册handler时,通过获取Disruptor上下文中已经设置的exceptionHandler --->>
if (exceptionHandler != null)
{
batchEventProcessor.setExceptionHandler(exceptionHandler);
}
3、举例:推荐使用setDefaultExceptionHandler方法设置exceptionHandler
disruptor.setDefaultExceptionHandler(exceptionHandler);
disruptor.handleEventsWith(handler);
--->>
private ExceptionHandler<? super T> exceptionHandler = new ExceptionHandlerWrapper<T>();
--->>
private ExceptionHandler<? super T> delegate = new FatalExceptionHandler();
public void switchTo(final ExceptionHandler<? super T> exceptionHandler)
{
this.delegate = exceptionHandler;
}
4、举例:setDefaultExceptionHandler不同于handleExceptionsWith方法可以在handler注册后设置,原因是重新设置的exceptionHandler代理,见上述代码
disruptor.handleEventsWith(handler);
disruptor.setDefaultExceptionHandler(exceptionHandler);
5、举例:灵活设置
disruptor.handleEventsWith(eventHandler);
disruptor.handleExceptionsFor(eventHandler).with(exceptionHandler);
--->>
com.lmax.disruptor.dsl.ExceptionHandlerSetting<T>
A support class used as part of setting an exception handler for a specific event handler. For example:
disruptorWizard.handleExceptionsIn(eventHandler).with(exceptionHandler);
Type Parameters:
<T> the type of event being handled.