com.lmax.disruptor.SleepingWaitStrategy Java Examples

The following examples show how to use com.lmax.disruptor.SleepingWaitStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisruptorLogAppenderBase.java    From High-concurrent-server with Apache License 2.0 7 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void start() {
	if (appenderCount == 0) {
		addError("No attached appenders found.");
		return;
	}
	if (queueSize < 1) {
		addError("Invalid queue size [" + queueSize + "]");
		return;
	}
	addInfo("环形缓冲区的大小: " + queueSize);
	Executor executor = Executors.newCachedThreadPool();
	Disruptor<LogValueEvent> disruptor = new Disruptor<LogValueEvent>(
			LogValueEvent.EVENT_FACTORY, queueSize, executor,
			ProducerType.MULTI, new SleepingWaitStrategy());
	disruptor.handleEventsWith(new LogDisruptorEventHandle());
	disruptor.start();
	ringBuffer = disruptor.getRingBuffer();
	super.start();
}
 
Example #2
Source File: DisruptorAsyncSpanProcessor.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@Override
protected Builder fromConfigMap(
    Map<String, String> configMap, NamingConvention namingConvention) {
  configMap = namingConvention.normalize(configMap);
  Integer intValue = getIntProperty(KEY_DISRUPTOR_BUFFER_SIZE, configMap);
  if (intValue != null) {
    this.setBufferSize(intValue);
  }
  Boolean boolValue = getBooleanProperty(KEY_BLOCKING, configMap);
  if (boolValue != null) {
    this.setBlocking(boolValue);
  }
  Integer retries = getIntProperty(KEY_NUM_RETRIES, configMap);
  if (retries == null) {
    retries = DEFAULT_NUM_RETRIES;
  }
  Long sleepingNs = getLongProperty(KEY_SLEEPING_TIME_NS, configMap);
  if (sleepingNs == null) {
    sleepingNs = DEFAULT_SLEEPING_TIME_NS;
  }
  return setWaitingStrategy(new SleepingWaitStrategy(retries, sleepingNs));
}
 
Example #3
Source File: FastEventServiceImpl.java    From redtorch with MIT License 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	if ("BusySpinWaitStrategy".equals(waitStrategy)) {
		disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE,
				ProducerType.MULTI, new BusySpinWaitStrategy());
	} else if ("SleepingWaitStrategy".equals(waitStrategy)) {
		disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE,
				ProducerType.MULTI, new SleepingWaitStrategy());
	} else if ("BlockingWaitStrategy".equals(waitStrategy)) {
		disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE,
				ProducerType.MULTI, new BlockingWaitStrategy());
	} else {
		disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE,
				ProducerType.MULTI, new YieldingWaitStrategy());
	}
	ringBuffer = disruptor.start();
}
 
Example #4
Source File: DisruptorLogAppenderBase.java    From NettyFileTransfer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void start() {
	if (appenderCount == 0) {
		addError("No attached appenders found.");
		return;
	}
	if (queueSize < 1) {
		addError("Invalid queue size [" + queueSize + "]");
		return;
	}
	addInfo("环形缓冲区的大小: " + queueSize);
	Executor executor = Executors.newCachedThreadPool();
	Disruptor<LogValueEvent> disruptor = new Disruptor<LogValueEvent>(
			LogValueEvent.EVENT_FACTORY, queueSize, executor,
			ProducerType.MULTI, new SleepingWaitStrategy());
	disruptor.handleEventsWith(new LogDisruptorEventHandle());
	disruptor.start();
	ringBuffer = disruptor.getRingBuffer();
	super.start();
}
 
Example #5
Source File: DisruptorUtil.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
static WaitStrategy createWaitStrategy(final String propertyName, final long timeoutMillis) {
    final String strategy = PropertiesUtil.getProperties().getStringProperty(propertyName, "TIMEOUT");
    LOGGER.trace("property {}={}", propertyName, strategy);
    final String strategyUp = strategy.toUpperCase(Locale.ROOT); // TODO Refactor into Strings.toRootUpperCase(String)
    switch (strategyUp) { // TODO Define a DisruptorWaitStrategy enum?
    case "SLEEP":
        return new SleepingWaitStrategy();
    case "YIELD":
        return new YieldingWaitStrategy();
    case "BLOCK":
        return new BlockingWaitStrategy();
    case "BUSYSPIN":
        return new BusySpinWaitStrategy();
    case "TIMEOUT":
        return new TimeoutBlockingWaitStrategy(timeoutMillis, TimeUnit.MILLISECONDS);
    default:
        return new TimeoutBlockingWaitStrategy(timeoutMillis, TimeUnit.MILLISECONDS);
    }
}
 
Example #6
Source File: DisruptorEventQueue.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
private static DisruptorEventQueue create() {
  // Create new Disruptor for processing. Note that Disruptor creates a single thread per
  // consumer (see https://github.com/LMAX-Exchange/disruptor/issues/121 for details);
  // this ensures that the event handler can take unsynchronized actions whenever possible.
  Disruptor<DisruptorEvent> disruptor =
      new Disruptor<>(
          DisruptorEventFactory.INSTANCE,
          DISRUPTOR_BUFFER_SIZE,
          new DaemonThreadFactory("OpenCensus.Disruptor"),
          ProducerType.MULTI,
          new SleepingWaitStrategy(0, 1000 * 1000));
  disruptor.handleEventsWith(new DisruptorEventHandler[] {DisruptorEventHandler.INSTANCE});
  disruptor.start();
  final RingBuffer<DisruptorEvent> ringBuffer = disruptor.getRingBuffer();

  DisruptorEnqueuer enqueuer =
      new DisruptorEnqueuer() {
        @Override
        public void enqueue(Entry entry) {
          long sequence = ringBuffer.next();
          try {
            DisruptorEvent event = ringBuffer.get(sequence);
            event.setEntry(entry);
          } finally {
            ringBuffer.publish(sequence);
          }
        }
      };
  return new DisruptorEventQueue(disruptor, enqueuer);
}
 
Example #7
Source File: WaitStrategyTypeTest.java    From disruptor-spring-manager with MIT License 5 votes vote down vote up
@Test
public void test_All_WaitStrategies() {
	assertTrue(WaitStrategyType.BLOCKING.instance() instanceof BlockingWaitStrategy);
	assertTrue(WaitStrategyType.BUSY_SPIN.instance() instanceof BusySpinWaitStrategy);
	assertTrue(WaitStrategyType.LITE_BLOCKING.instance() instanceof LiteBlockingWaitStrategy);
	assertTrue(WaitStrategyType.SLEEPING_WAIT.instance() instanceof SleepingWaitStrategy);
	assertTrue(WaitStrategyType.YIELDING.instance() instanceof YieldingWaitStrategy);
}
 
Example #8
Source File: ThreadInfo.java    From litchi with Apache License 2.0 4 votes vote down vote up
public static ThreadInfo valueOf(String name, int threadId, int threadNum) {
    return valueOf(name, threadId, threadNum, new SleepingWaitStrategy());
}
 
Example #9
Source File: DisruptorMailbox.java    From akka-disruptor with MIT License 4 votes vote down vote up
@Override
public MessageQueue create(Option<ActorRef> owner, Option<ActorSystem> system) {
    return new DisruptorMessageQueue(bufferSize, new SleepingWaitStrategy());
}
 
Example #10
Source File: DisruptorMailbox.java    From akka-disruptor with MIT License 4 votes vote down vote up
@Override
public MessageQueue create(Option<ActorRef> owner, Option<ActorSystem> system) {
    return new DisruptorMessageQueue(bufferSize, new SleepingWaitStrategy());
}