当前位置:   article > 正文

Disruptor技术调研之配置ExceptionHandler

disruptor添加exceptionhandler配置

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.

转载于:https://my.oschina.net/u/914290/blog/668597

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/254976
推荐阅读
相关标签
  

闽ICP备14008679号