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