use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldSupportCustomProcessorsAndHandlersAsDependencies.
@Test
public void shouldSupportCustomProcessorsAndHandlersAsDependencies() throws Exception {
final DelayedEventHandler delayedEventHandler1 = createDelayedEventHandler();
final DelayedEventHandler delayedEventHandler2 = createDelayedEventHandler();
disruptor.handleEventsWith(delayedEventHandler1);
RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler1).asSequenceBarrier();
final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, delayedEventHandler2);
disruptor.after(delayedEventHandler1).and(processor).handleEventsWith(handlerWithBarrier);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);
}
use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldSupportHandlersAsDependenciesToCustomProcessors.
@Test
public void shouldSupportHandlersAsDependenciesToCustomProcessors() throws Exception {
final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
disruptor.handleEventsWith(delayedEventHandler);
RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler).asSequenceBarrier();
final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, handlerWithBarrier);
disruptor.handleEventsWith(processor);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldHonourDependenciesForCustomProcessors.
@Test
public void shouldHonourDependenciesForCustomProcessors() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(2);
final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
disruptor.handleEventsWith(delayedEventHandler).then(new EventProcessorFactory<TestEvent>() {
@Override
public EventProcessor createEventProcessor(final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences) {
assertSame("Should have had a barrier sequence", 1, barrierSequences.length);
return new BatchEventProcessor<TestEvent>(disruptor.getRingBuffer(), ringBuffer.newBarrier(barrierSequences), eventHandler);
}
});
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
Aggregations