Search in sources :

Example 1 with BlockingWaitStrategy

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

the class MultiProducerWithTranslator method main.

public static void main(String[] args) throws InterruptedException {
    Disruptor<ObjectBox> disruptor = new Disruptor<ObjectBox>(ObjectBox.FACTORY, RING_SIZE, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new BlockingWaitStrategy());
    disruptor.handleEventsWith(new Consumer()).then(new Consumer());
    final RingBuffer<ObjectBox> ringBuffer = disruptor.getRingBuffer();
    Publisher p = new Publisher();
    IMessage message = new IMessage();
    ITransportable transportable = new ITransportable();
    String streamName = "com.lmax.wibble";
    System.out.println("publishing " + RING_SIZE + " messages");
    for (int i = 0; i < RING_SIZE; i++) {
        ringBuffer.publishEvent(p, message, transportable, streamName);
        Thread.sleep(10);
    }
    System.out.println("start disruptor");
    disruptor.start();
    System.out.println("continue publishing");
    while (true) {
        ringBuffer.publishEvent(p, message, transportable, streamName);
        Thread.sleep(10);
    }
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) Disruptor(com.lmax.disruptor.dsl.Disruptor)

Example 2 with BlockingWaitStrategy

use of com.lmax.disruptor.BlockingWaitStrategy in project jstorm by alibaba.

the class NettyUnitTest method initNettyServer.

private IConnection initNettyServer(int port) {
    ConcurrentHashMap<Integer, DisruptorQueue> deserializeQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
    //ConcurrentHashMap<Integer, DisruptorQueue> deserializeCtrlQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
    WaitStrategy wait = (WaitStrategy) Utils.newInstance("com.lmax.disruptor.TimeoutBlockingWaitStrategy", 5, TimeUnit.MILLISECONDS);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, 256, wait, false, 0, 0);
    Set<Integer> taskSet = new HashSet<Integer>();
    taskSet.add(1);
    IConnection server = context.bind(null, port, deserializeQueues, recvControlQueue, true, taskSet);
    WaitStrategy waitStrategy = new BlockingWaitStrategy();
    DisruptorQueue recvQueue = DisruptorQueue.mkInstance("NettyUnitTest", ProducerType.SINGLE, 1024, waitStrategy, false, 0, 0);
    server.registerQueue(task, recvQueue);
    return server;
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) DisruptorQueue(backtype.storm.utils.DisruptorQueue) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy) IConnection(backtype.storm.messaging.IConnection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)2 IConnection (backtype.storm.messaging.IConnection)1 DisruptorQueue (backtype.storm.utils.DisruptorQueue)1 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)1 WaitStrategy (com.lmax.disruptor.WaitStrategy)1 Disruptor (com.lmax.disruptor.dsl.Disruptor)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1