Search in sources :

Example 1 with DelayedEventHandler

use of com.lmax.disruptor.dsl.stubs.DelayedEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method createDelayedEventHandler.

private DelayedEventHandler createDelayedEventHandler() {
    final DelayedEventHandler delayedEventHandler = new DelayedEventHandler();
    delayedEventHandlers.add(delayedEventHandler);
    return delayedEventHandler;
}
Also used : DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler)

Example 2 with DelayedEventHandler

use of com.lmax.disruptor.dsl.stubs.DelayedEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldWaitUntilAllFirstEventProcessorsProcessEventBeforeMakingItAvailableToDependentEventProcessors.

@Test
public void shouldWaitUntilAllFirstEventProcessorsProcessEventBeforeMakingItAvailableToDependentEventProcessors() throws Exception {
    DelayedEventHandler eventHandler1 = createDelayedEventHandler();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> eventHandler2 = new EventHandlerStub<TestEvent>(countDownLatch);
    disruptor.handleEventsWith(eventHandler1).then(eventHandler2);
    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, eventHandler1);
}
Also used : EventHandlerStub(com.lmax.disruptor.dsl.stubs.EventHandlerStub) TestEvent(com.lmax.disruptor.support.TestEvent) CountDownLatch(java.util.concurrent.CountDownLatch) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 3 with DelayedEventHandler

use of com.lmax.disruptor.dsl.stubs.DelayedEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldSupportCombiningWorkerPoolWithEventHandlerAsDependencyWhenNotPreviouslyRegistered.

@Test
public void shouldSupportCombiningWorkerPoolWithEventHandlerAsDependencyWhenNotPreviouslyRegistered() throws Exception {
    final TestWorkHandler workHandler1 = createTestWorkHandler();
    final DelayedEventHandler delayedEventHandler1 = createDelayedEventHandler();
    final DelayedEventHandler delayedEventHandler2 = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler1).and(disruptor.handleEventsWithWorkerPool(workHandler1)).then(delayedEventHandler2);
    publishEvent();
    publishEvent();
    delayedEventHandler1.processEvent();
    delayedEventHandler1.processEvent();
    workHandler1.processEvent();
    delayedEventHandler2.processEvent();
    workHandler1.processEvent();
    delayedEventHandler2.processEvent();
}
Also used : TestWorkHandler(com.lmax.disruptor.dsl.stubs.TestWorkHandler) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) Test(org.junit.Test)

Example 4 with DelayedEventHandler

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

Example 5 with DelayedEventHandler

use of com.lmax.disruptor.dsl.stubs.DelayedEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method tearDown.

@After
public void tearDown() throws Exception {
    for (DelayedEventHandler delayedEventHandler : delayedEventHandlers) {
        delayedEventHandler.stopWaiting();
    }
    for (TestWorkHandler testWorkHandler : testWorkHandlers) {
        testWorkHandler.stopWaiting();
    }
    disruptor.halt();
    executor.joinAllThreads();
}
Also used : TestWorkHandler(com.lmax.disruptor.dsl.stubs.TestWorkHandler) DelayedEventHandler(com.lmax.disruptor.dsl.stubs.DelayedEventHandler) After(org.junit.After)

Aggregations

DelayedEventHandler (com.lmax.disruptor.dsl.stubs.DelayedEventHandler)17 Test (org.junit.Test)14 EventHandlerStub (com.lmax.disruptor.dsl.stubs.EventHandlerStub)8 TestEvent (com.lmax.disruptor.support.TestEvent)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 TestWorkHandler (com.lmax.disruptor.dsl.stubs.TestWorkHandler)5 BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)4 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)2 EventProcessor (com.lmax.disruptor.EventProcessor)1 Sequence (com.lmax.disruptor.Sequence)1 StubPublisher (com.lmax.disruptor.dsl.stubs.StubPublisher)1 After (org.junit.After)1