Search in sources :

Example 1 with WaitStrategy

use of com.lmax.disruptor.WaitStrategy in project camel by apache.

the class DisruptorWaitStrategyCreationTest method testCreateWaitStrategyInstance.

@Test
public void testCreateWaitStrategyInstance() throws Exception {
    for (final DisruptorWaitStrategy strategy : DisruptorWaitStrategy.values()) {
        final WaitStrategy waitStrategyInstance = strategy.createWaitStrategyInstance();
        assertNotNull(waitStrategyInstance);
        assertTrue(waitStrategyInstance instanceof WaitStrategy);
    }
}
Also used : WaitStrategy(com.lmax.disruptor.WaitStrategy) Test(org.junit.Test)

Example 2 with WaitStrategy

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

the class Worker method startDispatchThread.

private AsyncLoopThread startDispatchThread() {
    // send tuple directly from netty server
    // send control tuple to dispatch thread
    // startDispatchDisruptor();
    IContext context = workerData.getContext();
    String topologyId = workerData.getTopologyId();
    //create recv connection
    Map stormConf = workerData.getStormConf();
    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
    //metric for recvControlQueue
    QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
    IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskids());
    workerData.setRecvConnection(recvConnection);
    // create recvice control messages's thread
    RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
    return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
Also used : IContext(backtype.storm.messaging.IContext) DisruptorQueue(backtype.storm.utils.DisruptorQueue) IConnection(backtype.storm.messaging.IConnection) RunnableCallback(com.alibaba.jstorm.callback.RunnableCallback) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy)

Example 3 with WaitStrategy

use of com.lmax.disruptor.WaitStrategy 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)

Example 4 with WaitStrategy

use of com.lmax.disruptor.WaitStrategy in project logging-log4j2 by apache.

the class AsyncLoggerDisruptor method start.

/**
     * Creates and starts a new Disruptor and associated thread if none currently exists.
     *
     * @see #stop()
     */
@Override
public synchronized void start() {
    if (disruptor != null) {
        LOGGER.trace("[{}] AsyncLoggerDisruptor not starting new disruptor for this context, using existing object.", contextName);
        return;
    }
    LOGGER.trace("[{}] AsyncLoggerDisruptor creating new disruptor for this context.", contextName);
    ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLogger.RingBufferSize");
    final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLogger.WaitStrategy");
    executor = Executors.newSingleThreadExecutor(Log4jThreadFactory.createDaemonThreadFactory("AsyncLogger[" + contextName + "]"));
    backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor);
    asyncQueueFullPolicy = AsyncQueueFullPolicyFactory.create();
    disruptor = new Disruptor<>(RingBufferLogEvent.FACTORY, ringBufferSize, executor, ProducerType.MULTI, waitStrategy);
    final ExceptionHandler<RingBufferLogEvent> errorHandler = DisruptorUtil.getAsyncLoggerExceptionHandler();
    disruptor.handleExceptionsWith(errorHandler);
    final RingBufferLogEventHandler[] handlers = { new RingBufferLogEventHandler() };
    disruptor.handleEventsWith(handlers);
    LOGGER.debug("[{}] Starting AsyncLogger disruptor for this context with ringbufferSize={}, waitStrategy={}, " + "exceptionHandler={}...", contextName, disruptor.getRingBuffer().getBufferSize(), waitStrategy.getClass().getSimpleName(), errorHandler);
    disruptor.start();
    LOGGER.trace("[{}] AsyncLoggers use a {} translator", contextName, useThreadLocalTranslator ? "threadlocal" : "vararg");
    super.start();
}
Also used : WaitStrategy(com.lmax.disruptor.WaitStrategy)

Example 5 with WaitStrategy

use of com.lmax.disruptor.WaitStrategy in project logging-log4j2 by apache.

the class AsyncLoggerConfigDisruptor method start.

/**
     * Increases the reference count and creates and starts a new Disruptor and associated thread if none currently
     * exists.
     *
     * @see #stop()
     */
@Override
public synchronized void start() {
    if (disruptor != null) {
        LOGGER.trace("AsyncLoggerConfigDisruptor not starting new disruptor for this configuration, " + "using existing object.");
        return;
    }
    LOGGER.trace("AsyncLoggerConfigDisruptor creating new disruptor for this configuration.");
    ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLoggerConfig.RingBufferSize");
    final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLoggerConfig.WaitStrategy");
    executor = Executors.newSingleThreadExecutor(THREAD_FACTORY);
    backgroundThreadId = DisruptorUtil.getExecutorThreadId(executor);
    asyncQueueFullPolicy = AsyncQueueFullPolicyFactory.create();
    translator = mutable ? MUTABLE_TRANSLATOR : TRANSLATOR;
    factory = mutable ? MUTABLE_FACTORY : FACTORY;
    disruptor = new Disruptor<>(factory, ringBufferSize, executor, ProducerType.MULTI, waitStrategy);
    final ExceptionHandler<Log4jEventWrapper> errorHandler = DisruptorUtil.getAsyncLoggerConfigExceptionHandler();
    disruptor.handleExceptionsWith(errorHandler);
    final Log4jEventWrapperHandler[] handlers = { new Log4jEventWrapperHandler() };
    disruptor.handleEventsWith(handlers);
    LOGGER.debug("Starting AsyncLoggerConfig disruptor for this configuration with ringbufferSize={}, " + "waitStrategy={}, exceptionHandler={}...", disruptor.getRingBuffer().getBufferSize(), waitStrategy.getClass().getSimpleName(), errorHandler);
    disruptor.start();
    super.start();
}
Also used : WaitStrategy(com.lmax.disruptor.WaitStrategy)

Aggregations

WaitStrategy (com.lmax.disruptor.WaitStrategy)5 IConnection (backtype.storm.messaging.IConnection)2 DisruptorQueue (backtype.storm.utils.DisruptorQueue)2 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)2 IContext (backtype.storm.messaging.IContext)1 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.Test)1