Search in sources :

Example 1 with Sequence

use of com.lmax.disruptor.Sequence in project disruptor by LMAX-Exchange.

the class ConsumerRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    consumerRepository = new ConsumerRepository<TestEvent>();
    eventProcessor1 = new DummyEventProcessor(new Sequence());
    eventProcessor2 = new DummyEventProcessor(new Sequence());
    eventProcessor1.run();
    eventProcessor2.run();
    handler1 = new SleepingEventHandler();
    handler2 = new SleepingEventHandler();
    barrier1 = new DummySequenceBarrier();
    barrier2 = new DummySequenceBarrier();
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) DummyEventProcessor(com.lmax.disruptor.support.DummyEventProcessor) DummySequenceBarrier(com.lmax.disruptor.support.DummySequenceBarrier) TestEvent(com.lmax.disruptor.support.TestEvent) Sequence(com.lmax.disruptor.Sequence) Before(org.junit.Before)

Example 2 with Sequence

use of com.lmax.disruptor.Sequence in project disruptor by LMAX-Exchange.

the class Disruptor method updateGatingSequencesForNextInChain.

private void updateGatingSequencesForNextInChain(Sequence[] barrierSequences, Sequence[] processorSequences) {
    if (processorSequences.length > 0) {
        ringBuffer.addGatingSequences(processorSequences);
        for (final Sequence barrierSequence : barrierSequences) {
            ringBuffer.removeGatingSequence(barrierSequence);
        }
        consumerRepository.unMarkEventProcessorsAsEndOfChain(barrierSequences);
    }
}
Also used : Sequence(com.lmax.disruptor.Sequence)

Example 3 with Sequence

use of com.lmax.disruptor.Sequence in project disruptor by LMAX-Exchange.

the class Disruptor method handleEventsWith.

/**
     * <p>Set up custom event processors to handle events from the ring buffer. The Disruptor will
     * automatically start this processors when {@link #start()} is called.</p>
     * <p>
     * <p>This method can be used as the start of a chain. For example if the processor <code>A</code> must
     * process events before handler <code>B</code>:</p>
     * <pre><code>dw.handleEventsWith(A).then(B);</code></pre>
     *
     * @param processors the event processors that will process events.
     * @return a {@link EventHandlerGroup} that can be used to chain dependencies.
     */
public EventHandlerGroup<T> handleEventsWith(final EventProcessor... processors) {
    for (final EventProcessor processor : processors) {
        consumerRepository.add(processor);
    }
    Sequence[] sequences = new Sequence[processors.length];
    for (int i = 0; i < processors.length; i++) {
        sequences[i] = processors[i].getSequence();
    }
    ringBuffer.addGatingSequences(sequences);
    return new EventHandlerGroup<T>(this, consumerRepository, Util.getSequencesFor(processors));
}
Also used : EventProcessor(com.lmax.disruptor.EventProcessor) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) Sequence(com.lmax.disruptor.Sequence)

Example 4 with Sequence

use of com.lmax.disruptor.Sequence in project disruptor by LMAX-Exchange.

the class WaitStrategyTestUtil method assertWaitForWithDelayOf.

public static void assertWaitForWithDelayOf(long sleepTimeMillis, WaitStrategy waitStrategy) throws InterruptedException, BrokenBarrierException, AlertException, TimeoutException {
    SequenceUpdater sequenceUpdater = new SequenceUpdater(sleepTimeMillis, waitStrategy);
    EXECUTOR.execute(sequenceUpdater);
    sequenceUpdater.waitForStartup();
    Sequence cursor = new Sequence(0);
    long sequence = waitStrategy.waitFor(0, cursor, sequenceUpdater.sequence, new DummySequenceBarrier());
    assertThat(sequence, is(0L));
}
Also used : Sequence(com.lmax.disruptor.Sequence)

Example 5 with Sequence

use of com.lmax.disruptor.Sequence in project disruptor by LMAX-Exchange.

the class UtilTest method shouldReturnMinimumSequence.

@Test
public void shouldReturnMinimumSequence() {
    final Sequence[] sequences = { new Sequence(7L), new Sequence(3L), new Sequence(12L) };
    Assert.assertEquals(3L, Util.getMinimumSequence(sequences));
}
Also used : Sequence(com.lmax.disruptor.Sequence) 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