Search in sources :

Example 6 with Sequence

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);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) TestEvent(com.lmax.disruptor.support.TestEvent) EventProcessor(com.lmax.disruptor.EventProcessor) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) Sequence(com.lmax.disruptor.Sequence) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with Sequence

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);
}
Also used : WorkerPool(com.lmax.disruptor.WorkerPool) SequenceBarrier(com.lmax.disruptor.SequenceBarrier) Sequence(com.lmax.disruptor.Sequence)

Example 8 with Sequence

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);
}
Also used : SequenceBarrier(com.lmax.disruptor.SequenceBarrier) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) Sequence(com.lmax.disruptor.Sequence)

Example 9 with Sequence

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);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) TestEvent(com.lmax.disruptor.support.TestEvent) EventProcessor(com.lmax.disruptor.EventProcessor) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) Sequence(com.lmax.disruptor.Sequence) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Aggregations

Sequence (com.lmax.disruptor.Sequence)9 BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)4 EventProcessor (com.lmax.disruptor.EventProcessor)3 TestEvent (com.lmax.disruptor.support.TestEvent)3 Test (org.junit.Test)3 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)2 EventHandlerStub (com.lmax.disruptor.dsl.stubs.EventHandlerStub)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 WorkerPool (com.lmax.disruptor.WorkerPool)1 DelayedEventHandler (com.lmax.disruptor.dsl.stubs.DelayedEventHandler)1 SleepingEventHandler (com.lmax.disruptor.dsl.stubs.SleepingEventHandler)1 DummyEventProcessor (com.lmax.disruptor.support.DummyEventProcessor)1 DummySequenceBarrier (com.lmax.disruptor.support.DummySequenceBarrier)1 Before (org.junit.Before)1