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