Java Code Examples for com.lmax.disruptor.dsl.Disruptor#setDefaultExceptionHandler()
The following examples show how to use
com.lmax.disruptor.dsl.Disruptor#setDefaultExceptionHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisruptorUtil.java From nuls with MIT License | 6 votes |
public Disruptor<DisruptorData> createDisruptor(String name, int ringBufferSize, ThreadFactory factory) { if (DISRUPTOR_MAP.keySet().contains(name)) { throw new RuntimeException("create disruptor faild,the name is repetitive!"); } Disruptor<DisruptorData> disruptor = new Disruptor<DisruptorData>(EVENT_FACTORY, ringBufferSize, factory, ProducerType.MULTI, new BlockingWaitStrategy()); disruptor.setDefaultExceptionHandler(new NulsExceptionHandler()); //SleepingWaitStrategy // disruptor.handleEventsWith(new EventHandler<DisruptorData>() { // @Override // public void onEvent(DisruptorData DisruptorData, long l, boolean b) throws Exception { // Log.debug(DisruptorData.getData() + ""); // } // }); DISRUPTOR_MAP.put(name, disruptor); return disruptor; }
Example 2
Source File: DisruptorProviderManage.java From hmily with Apache License 2.0 | 6 votes |
/** * start disruptor. */ @SuppressWarnings("unchecked") public void startup() { Disruptor<DataEvent<T>> disruptor = new Disruptor<>(new DisruptorEventFactory<>(), size, HmilyThreadFactory.create("disruptor_consumer_" + consumerFactory.fixName(), false), ProducerType.MULTI, new BlockingWaitStrategy()); DisruptorConsumer<T>[] consumers = new DisruptorConsumer[consumerSize]; for (int i = 0; i < consumerSize; i++) { consumers[i] = new DisruptorConsumer<>(consumerFactory); } disruptor.handleEventsWithWorkerPool(consumers); disruptor.setDefaultExceptionHandler(new IgnoreExceptionHandler()); disruptor.start(); RingBuffer<DataEvent<T>> ringBuffer = disruptor.getRingBuffer(); provider = new DisruptorProvider<>(ringBuffer); }
Example 3
Source File: DisruptorConfigure.java From youkefu with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "deprecation" }) @Bean(name="multiupdate") public Disruptor<UserDataEvent> multiupdate() { Executor executor = Executors.newCachedThreadPool(); MultiUpdateEventFactory factory = new MultiUpdateEventFactory(); Disruptor<UserDataEvent> disruptor = new Disruptor<UserDataEvent>(factory, 1024, executor, ProducerType.MULTI , new BlockingWaitStrategy()); disruptor.handleEventsWith(new MultiUpdateEventHandler()); disruptor.setDefaultExceptionHandler(new UKeFuExceptionHandler()); disruptor.start(); return disruptor; }
Example 4
Source File: DisruptorConfig.java From match-trade with Apache License 2.0 | 5 votes |
@Bean public RingBuffer<MatchOrder> ringBuffer() { EventFactory<MatchOrder> factory = new OrderFactory(); int ringBufferSize = 1024 * 1024; ThreadFactory disruptorThreadPool = new ThreadFactoryBuilder().setNameFormat("DisruptorThreadPool").build(); Disruptor<MatchOrder> disruptor = new Disruptor<MatchOrder>(factory, ringBufferSize, disruptorThreadPool, ProducerType.MULTI, new YieldingWaitStrategy()); disruptor.setDefaultExceptionHandler(new MyHandlerException());// Disruptor异常统计 // 单线处理撮合, 并行处理盘口和订单薄 disruptor.handleEventsWithWorkerPool(new MatchHandler(),new MatchHandler()).then(new InputDepthHandler(),new OutDepthHandler()); disruptor.start(); return disruptor.getRingBuffer(); }
Example 5
Source File: ItemAmountUpdateProcessorConfiguration.java From artemis-disruptor-miaosha with Apache License 2.0 | 5 votes |
@Bean public ItemAmountUpdateCommandProcessor lessonStdCountUpdateCmdProcessor() { CommandEventProducer<ItemAmountUpdateCommand>[] commandEventProducerList = new CommandEventProducer[conf.getNum()]; for (int i = 0; i < conf.getNum(); i++) { ItemAmountUpdateCommandBuffer cmdBuffer = new ItemAmountUpdateCommandBuffer(conf.getSqlBufferSize()); ItemAmountUpdateCommandExecutor cmdExecutor = new ItemAmountUpdateCommandExecutor(jdbcTemplate); Disruptor<CommandEvent<ItemAmountUpdateCommand>> disruptor = new Disruptor<>( new CommandEventFactory(), conf.getQueueSize(), Executors.defaultThreadFactory()); disruptor .handleEventsWith(new CommandEventDbHandler(cmdBuffer, cmdExecutor)) .then(new CommandEventGcHandler()) ; // disruptor 的异常处理是这样的, // 不论这种形式 A->B, 还是这种形式 A,B->C,D, 只有抛出异常的那个handler会中断执行 disruptor.setDefaultExceptionHandler(new CommandEventExceptionHandler()); commandEventProducerList[i] = new CommandEventProducer<>(disruptor.getRingBuffer()); BeanRegisterUtils.registerSingleton( applicationContext, "CommandEvent<ItemAmountUpdateCommand>_DisruptorLifeCycleContainer_" + i, new DisruptorLifeCycleContainer("CommandEvent<ItemAmountUpdateCommand>_Disruptor_" + i, disruptor, StartupOrderConstants.DISRUPTOR_ITEM_UPDATE)); } ItemAmountUpdateCommandProcessor cmdProcessor = new ItemAmountUpdateCommandProcessor(commandEventProducerList); commandDispatcher.registerCommandProcessor(cmdProcessor); return cmdProcessor; }
Example 6
Source File: OrderInsertProcessorConfiguration.java From artemis-disruptor-miaosha with Apache License 2.0 | 4 votes |
@Bean public OrderInsertCommandProcessor courseTakeInsertCmdProcessor() { LOGGER.info("Configure OrderInsertCommandProcessor"); CommandEventProducer<OrderInsertCommand>[] commandEventProducerList = new CommandEventProducer[conf.getNum()]; for (int i = 0; i < conf.getNum(); i++) { OrderInsertCommandBuffer cmdBuffer = new OrderInsertCommandBuffer(conf.getSqlBufferSize()); OrderInsertCommandExecutor cmdExecutor = new OrderInsertCommandExecutor(jdbcTemplate); Disruptor<CommandEvent<OrderInsertCommand>> disruptor = new Disruptor<>( new CommandEventFactory(), conf.getQueueSize(), Executors.defaultThreadFactory()); disruptor .handleEventsWith(new CommandEventDbHandler(cmdBuffer, cmdExecutor)) .then(new CommandEventGcHandler()) ; // disruptor 的异常处理是这样的, // 不论这种形式 A->B, 还是这种形式 A,B->C,D, 只有抛出异常的那个handler会中断执行 disruptor.setDefaultExceptionHandler(new CommandEventExceptionHandler()); commandEventProducerList[i] = new CommandEventProducer<>(disruptor.getRingBuffer()); BeanRegisterUtils.registerSingleton( applicationContext, "CommandEvent<OrderInsertCommand>_DisruptorLifeCycleContainer_" + i, new DisruptorLifeCycleContainer("CommandEvent<OrderInsertCommand>_Disruptor_" + i, disruptor, StartupOrderConstants.DISRUPTOR_ORDER_INSERT)); } OrderInsertCommandProcessor cmdProcessor = new OrderInsertCommandProcessor(commandEventProducerList); commandDispatcher.registerCommandProcessor(cmdProcessor); return cmdProcessor; }