Search in sources :

Example 6 with Disruptor

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

the class ThreeToOneDisruptor method main.

public static void main(String[] args) {
    Executor executor = Executors.newFixedThreadPool(4);
    Disruptor<DataEvent> disruptor = new Disruptor<DataEvent>(DataEvent.FACTORY, 1024, DaemonThreadFactory.INSTANCE);
    TransformingHandler handler1 = new TransformingHandler(0);
    TransformingHandler handler2 = new TransformingHandler(1);
    TransformingHandler handler3 = new TransformingHandler(2);
    CollatingHandler collator = new CollatingHandler();
    disruptor.handleEventsWith(handler1, handler2, handler3).then(collator);
    disruptor.start();
}
Also used : Executor(java.util.concurrent.Executor) Disruptor(com.lmax.disruptor.dsl.Disruptor)

Example 7 with Disruptor

use of com.lmax.disruptor.dsl.Disruptor in project iris by chicc999.

the class DisruptorTest method testDis.

private void testDis() {
    EventFactory<LongEvent> eventFactory = new LongEventFactory();
    ExecutorService executor = Executors.newFixedThreadPool(1);
    // RingBuffer 大小,必须是 2 的 N 次方;
    int ringBufferSize = 1024 * 1024;
    Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(eventFactory, ringBufferSize, executor, ProducerType.SINGLE, new YieldingWaitStrategy());
    EventHandler<LongEvent> eventHandler = new LongEventHandler();
    disruptor.handleEventsWith(eventHandler);
    disruptor.start();
    Executors.newSingleThreadExecutor().submit(new Producer(disruptor));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Disruptor(com.lmax.disruptor.dsl.Disruptor)

Aggregations

Disruptor (com.lmax.disruptor.dsl.Disruptor)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 ExecutorService (java.util.concurrent.ExecutorService)2 Test (org.junit.Test)2 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 EventHandler (com.lmax.disruptor.EventHandler)1 LongEvent (com.lmax.disruptor.support.LongEvent)1 StubEvent (com.lmax.disruptor.support.StubEvent)1 Executor (java.util.concurrent.Executor)1