Java Code Examples for com.lmax.disruptor.RingBuffer#createMultiProducer()

The following examples show how to use com.lmax.disruptor.RingBuffer#createMultiProducer() . 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: SamplingProfiler.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
private RingBuffer<ActivationEvent> createRingBuffer() {
    return RingBuffer.<ActivationEvent>createMultiProducer(
        new EventFactory<ActivationEvent>() {
            @Override
            public ActivationEvent newInstance() {
                return new ActivationEvent();
            }
        },
        RING_BUFFER_SIZE,
        new NoWaitStrategy());
}
 
Example 2
Source File: DisruptorMessageQueue.java    From akka-disruptor with MIT License 5 votes vote down vote up
DisruptorMessageQueue(int bufferSize, WaitStrategy waitStrategy) {
    ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, bufferSize, waitStrategy);
    ringBuffer.addGatingSequences(sequence);
    sequenceBarrier = ringBuffer.newBarrier();
    mask = bufferSize - 1;
    buffer = new Envelope[bufferSize];
}
 
Example 3
Source File: DisruptorMessageQueue.java    From akka-disruptor with MIT License 5 votes vote down vote up
DisruptorMessageQueue(int bufferSize, WaitStrategy waitStrategy) {
    ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, bufferSize, waitStrategy);
    ringBuffer.addGatingSequences(sequence);
    sequenceBarrier = ringBuffer.newBarrier();
    mask = bufferSize - 1;
    buffer = new Envelope[bufferSize];
}
 
Example 4
Source File: AsyncFSWAL.java    From hbase with Apache License 2.0 4 votes vote down vote up
public AsyncFSWAL(FileSystem fs, Path rootDir, String logDir, String archiveDir,
    Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists,
    String prefix, String suffix, EventLoopGroup eventLoopGroup,
    Class<? extends Channel> channelClass) throws FailedLogCloseException, IOException {
  super(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix, suffix);
  this.eventLoopGroup = eventLoopGroup;
  this.channelClass = channelClass;
  Supplier<Boolean> hasConsumerTask;
  if (conf.getBoolean(ASYNC_WAL_USE_SHARED_EVENT_LOOP, DEFAULT_ASYNC_WAL_USE_SHARED_EVENT_LOOP)) {
    this.consumeExecutor = eventLoopGroup.next();
    if (consumeExecutor instanceof SingleThreadEventExecutor) {
      try {
        Field field = SingleThreadEventExecutor.class.getDeclaredField("taskQueue");
        field.setAccessible(true);
        Queue<?> queue = (Queue<?>) field.get(consumeExecutor);
        hasConsumerTask = () -> queue.peek() == consumer;
      } catch (Exception e) {
        LOG.warn("Can not get task queue of " + consumeExecutor +
          ", this is not necessary, just give up", e);
        hasConsumerTask = () -> false;
      }
    } else {
      hasConsumerTask = () -> false;
    }
  } else {
    ThreadPoolExecutor threadPool =
      new ThreadPoolExecutor(1, 1, 0L,
        TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),
          new ThreadFactoryBuilder().setNameFormat("AsyncFSWAL-%d-" + rootDir.toString()).
            setDaemon(true).build());
    hasConsumerTask = () -> threadPool.getQueue().peek() == consumer;
    this.consumeExecutor = threadPool;
  }

  this.hasConsumerTask = hasConsumerTask;
  int preallocatedEventCount =
    conf.getInt("hbase.regionserver.wal.disruptor.event.count", 1024 * 16);
  waitingConsumePayloads =
    RingBuffer.createMultiProducer(RingBufferTruck::new, preallocatedEventCount);
  waitingConsumePayloadsGatingSequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
  waitingConsumePayloads.addGatingSequences(waitingConsumePayloadsGatingSequence);

  // inrease the ringbuffer sequence so our txid is start from 1
  waitingConsumePayloads.publish(waitingConsumePayloads.next());
  waitingConsumePayloadsGatingSequence.set(waitingConsumePayloads.getCursor());

  batchSize = conf.getLong(WAL_BATCH_SIZE, DEFAULT_WAL_BATCH_SIZE);
  waitOnShutdownInSeconds = conf.getInt(ASYNC_WAL_WAIT_ON_SHUTDOWN_IN_SECONDS,
    DEFAULT_ASYNC_WAL_WAIT_ON_SHUTDOWN_IN_SECONDS);
}