com.lmax.disruptor.BatchEventProcessor Java Examples

The following examples show how to use com.lmax.disruptor.BatchEventProcessor. 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: FastEventServiceImpl.java    From redtorch with MIT License 6 votes vote down vote up
@Override
public void removeHandler(FastEventDynamicHandler handler) {
	if (handlerProcessorMap.containsKey(handler)) {
		BatchEventProcessor<FastEvent> processor = handlerProcessorMap.get(handler);
		// Remove a processor.
		// Stop the processor
		processor.halt();
		// Wait for shutdown the complete
		try {
			handler.awaitShutdown();
		} catch (InterruptedException e) {
			e.printStackTrace();
			logger.error("关闭时发生异常", e);
		}
		// Remove the gating sequence from the ring buffer
		ringBuffer.removeGatingSequence(processor.getSequence());
		handlerProcessorMap.remove(handler);
	} else {
		logger.warn("未找到Processor,无法移除");
	}

}
 
Example #2
Source File: FastEventServiceImpl.java    From redtorch with MIT License 5 votes vote down vote up
@Override
public synchronized BatchEventProcessor<FastEvent> addHandler(FastEventDynamicHandler handler) {
	BatchEventProcessor<FastEvent> processor;
	processor = new BatchEventProcessor<FastEvent>(ringBuffer, ringBuffer.newBarrier(), handler);
	ringBuffer.addGatingSequences(processor.getSequence());
	executor.execute(processor);
	handlerProcessorMap.put(handler, processor);
	return processor;
}
 
Example #3
Source File: MysqlMultiStageCoprocessor.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public void start() {
    super.start();
    this.exception = null;
    this.disruptorMsgBuffer = RingBuffer.createSingleProducer(new MessageEventFactory(),
        ringBufferSize,
        new BlockingWaitStrategy());
    int tc = parserThreadCount > 0 ? parserThreadCount : 1;
    this.parserExecutor = Executors.newFixedThreadPool(tc, new NamedThreadFactory("MultiStageCoprocessor-Parser-"
                                                                                  + destination));

    this.stageExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("MultiStageCoprocessor-other-"
                                                                                + destination));
    SequenceBarrier sequenceBarrier = disruptorMsgBuffer.newBarrier();
    ExceptionHandler exceptionHandler = new SimpleFatalExceptionHandler();
    // stage 2
    this.logContext = new LogContext();
    simpleParserStage = new BatchEventProcessor<MessageEvent>(disruptorMsgBuffer,
        sequenceBarrier,
        new SimpleParserStage(logContext));
    simpleParserStage.setExceptionHandler(exceptionHandler);
    disruptorMsgBuffer.addGatingSequences(simpleParserStage.getSequence());

    // stage 3
    SequenceBarrier dmlParserSequenceBarrier = disruptorMsgBuffer.newBarrier(simpleParserStage.getSequence());
    WorkHandler<MessageEvent>[] workHandlers = new DmlParserStage[tc];
    for (int i = 0; i < tc; i++) {
        workHandlers[i] = new DmlParserStage();
    }
    workerPool = new WorkerPool<MessageEvent>(disruptorMsgBuffer,
        dmlParserSequenceBarrier,
        exceptionHandler,
        workHandlers);
    Sequence[] sequence = workerPool.getWorkerSequences();
    disruptorMsgBuffer.addGatingSequences(sequence);

    // stage 4
    SequenceBarrier sinkSequenceBarrier = disruptorMsgBuffer.newBarrier(sequence);
    sinkStoreStage = new BatchEventProcessor<MessageEvent>(disruptorMsgBuffer,
        sinkSequenceBarrier,
        new SinkStoreStage());
    sinkStoreStage.setExceptionHandler(exceptionHandler);
    disruptorMsgBuffer.addGatingSequences(sinkStoreStage.getSequence());

    // start work
    stageExecutor.submit(simpleParserStage);
    stageExecutor.submit(sinkStoreStage);
    workerPool.start(parserExecutor);
}
 
Example #4
Source File: FastEventService.java    From redtorch with MIT License votes vote down vote up
BatchEventProcessor<FastEvent> addHandler(FastEventDynamicHandler handler);