Search in sources :

Example 6 with BatchEventProcessor

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);
}
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 7 with BatchEventProcessor

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);
}
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 8 with BatchEventProcessor

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);
}
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

BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)8 TestEvent (com.lmax.disruptor.support.TestEvent)7 Test (org.junit.Test)7 EventHandlerStub (com.lmax.disruptor.dsl.stubs.EventHandlerStub)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 DelayedEventHandler (com.lmax.disruptor.dsl.stubs.DelayedEventHandler)4 Sequence (com.lmax.disruptor.Sequence)3 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)3 EventProcessor (com.lmax.disruptor.EventProcessor)2 SleepingEventHandler (com.lmax.disruptor.dsl.stubs.SleepingEventHandler)2 RingBuffer (com.lmax.disruptor.RingBuffer)1