use of com.lmax.disruptor.Sequence 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.Sequence in project disruptor by LMAX-Exchange.
the class Disruptor method createWorkerPool.
EventHandlerGroup<T> createWorkerPool(final Sequence[] barrierSequences, final WorkHandler<? super T>[] workHandlers) {
final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(barrierSequences);
final WorkerPool<T> workerPool = new WorkerPool<T>(ringBuffer, sequenceBarrier, exceptionHandler, workHandlers);
consumerRepository.add(workerPool, sequenceBarrier);
Sequence[] workerSequences = workerPool.getWorkerSequences();
updateGatingSequencesForNextInChain(barrierSequences, workerSequences);
return new EventHandlerGroup<T>(this, consumerRepository, workerSequences);
}
use of com.lmax.disruptor.Sequence 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.Sequence 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