use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldSupportCustomProcessorsAsDependencies.
@Test
public void shouldSupportCustomProcessorsAsDependencies() throws Exception {
RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);
final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, ringBuffer.newBarrier(), delayedEventHandler);
disruptor.handleEventsWith(processor).then(handlerWithBarrier);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately.
@Test
public void shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(2);
final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
disruptor.handleEventsWith(new EventProcessorFactory<TestEvent>() {
@Override
public EventProcessor createEventProcessor(final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences) {
assertEquals("Should not have had any barrier sequences", 0, barrierSequences.length);
return new BatchEventProcessor<TestEvent>(disruptor.getRingBuffer(), ringBuffer.newBarrier(barrierSequences), eventHandler);
}
});
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch);
}
use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class Disruptor method createEventProcessors.
EventHandlerGroup<T> createEventProcessors(final Sequence[] barrierSequences, final EventHandler<? super T>[] eventHandlers) {
checkNotStarted();
final Sequence[] processorSequences = new Sequence[eventHandlers.length];
final SequenceBarrier barrier = ringBuffer.newBarrier(barrierSequences);
for (int i = 0, eventHandlersLength = eventHandlers.length; i < eventHandlersLength; i++) {
final EventHandler<? super T> eventHandler = eventHandlers[i];
final BatchEventProcessor<T> batchEventProcessor = new BatchEventProcessor<T>(ringBuffer, barrier, eventHandler);
if (exceptionHandler != null) {
batchEventProcessor.setExceptionHandler(exceptionHandler);
}
consumerRepository.add(batchEventProcessor, eventHandler, barrier);
processorSequences[i] = batchEventProcessor.getSequence();
}
updateGatingSequencesForNextInChain(barrierSequences, processorSequences);
return new EventHandlerGroup<T>(this, consumerRepository, processorSequences);
}
use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldAddEventProcessorsAfterPublishing.
@Test
public void shouldAddEventProcessorsAfterPublishing() throws Exception {
RingBuffer<TestEvent> rb = disruptor.getRingBuffer();
BatchEventProcessor<TestEvent> b1 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(), new SleepingEventHandler());
BatchEventProcessor<TestEvent> b2 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(b1.getSequence()), new SleepingEventHandler());
BatchEventProcessor<TestEvent> b3 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(b2.getSequence()), new SleepingEventHandler());
assertThat(b1.getSequence().get(), is(-1L));
assertThat(b2.getSequence().get(), is(-1L));
assertThat(b3.getSequence().get(), is(-1L));
rb.publish(rb.next());
rb.publish(rb.next());
rb.publish(rb.next());
rb.publish(rb.next());
rb.publish(rb.next());
rb.publish(rb.next());
disruptor.handleEventsWith(b1, b2, b3);
assertThat(b1.getSequence().get(), is(5L));
assertThat(b2.getSequence().get(), is(5L));
assertThat(b3.getSequence().get(), is(5L));
}
use of com.lmax.disruptor.BatchEventProcessor in project disruptor by LMAX-Exchange.
the class DisruptorTest method should.
@Test
public void should() throws Exception {
RingBuffer<TestEvent> rb = disruptor.getRingBuffer();
BatchEventProcessor<TestEvent> b1 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(), new SleepingEventHandler());
EventProcessorFactory<TestEvent> b2 = new EventProcessorFactory<TestEvent>() {
@Override
public EventProcessor createEventProcessor(RingBuffer<TestEvent> ringBuffer, Sequence[] barrierSequences) {
return new BatchEventProcessor<TestEvent>(ringBuffer, ringBuffer.newBarrier(barrierSequences), new SleepingEventHandler());
}
};
disruptor.handleEventsWith(b1).then(b2);
disruptor.start();
}
Aggregations