Search in sources :

Example 1 with SequenceBarrier

use of com.lmax.disruptor.SequenceBarrier 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 2 with SequenceBarrier

use of com.lmax.disruptor.SequenceBarrier 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 3 with SequenceBarrier

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

Example 4 with SequenceBarrier

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

Aggregations

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