Пример #1
0
    private boolean sendMessages(
        RingBuffer<byte[]> ringBuffer, long messagesPerSecond, int runtimeSeconds)
        throws InterruptedException {
      LOGGER.info("Rate: " + messagesPerSecond + ", for " + runtimeSeconds + "s");

      long runtimeNanos = TimeUnit.SECONDS.toNanos(runtimeSeconds);

      long t0 = System.nanoTime();
      long delta = 0;
      long sent = 0;

      try {
        do {
          delta = System.nanoTime() - t0;
          long shouldHaveSent = (messagesPerSecond * delta) / 1000000000;

          for (; sent < shouldHaveSent; sent++) {
            if (!send(ringBuffer)) {
              return false;
            }
          }

          LockSupport.parkNanos(1);
        } while (delta <= runtimeNanos);

        Thread.sleep(1000);
        return ringBuffer.hasAvailableCapacity(ringBuffer.getBufferSize());

      } finally {
        while (!ringBuffer.hasAvailableCapacity(ringBuffer.getBufferSize())) {
          Thread.sleep(1000);
        }
      }
    }
 private void prefillArgumentHolderObjects(
     final RingBuffer<ProxyMethodInvocation> ringBuffer,
     final ArgumentHolderGenerator argumentHolderGenerator) {
   final int bufferSize = ringBuffer.getBufferSize();
   for (int i = 0; i < bufferSize; i++) {
     ringBuffer
         .get(i)
         .setArgumentHolder(
             (Resetable) instantiate(argumentHolderGenerator.getGeneratedClass(), new Class[] {}));
   }
 }
Пример #3
0
 public long capacity() {
   return _buffer.getBufferSize();
 }
Пример #4
0
 /** Returns {@code true} if the specified disruptor still has unprocessed events. */
 private static boolean hasBacklog(final Disruptor<?> theDisruptor) {
   final RingBuffer<?> ringBuffer = theDisruptor.getRingBuffer();
   return !ringBuffer.hasAvailableCapacity(ringBuffer.getBufferSize());
 }