RateLimiter implements AutoCloseable, PermitSupplier { public boolean tryAcquire() { return tryAcquire(1); } RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long maxBurstSize, final long minReplenishInterval, final TimeUnit tu);  RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long maxBurstSize);  RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long maxBurstSize,
          final ScheduledExecutorService scheduler);  RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long maxBurstSize,
          final ScheduledExecutorService scheduler,
          final LongSupplier nanoTimeSupplier);  RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long maxBurstSize,
          final long minReplenishInterval,
          final TimeUnit tu,
          final ScheduledExecutorService scheduler,
          final LongSupplier nanoTimeSupplier);  RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long maxAvailablePermits,
          final long minReplenishInterval,
          final TimeUnit tu,
          final ScheduledExecutorService scheduler,
          final LongSupplier nanoTimeSupplier,
          final int maxBackoffNanos);  RateLimiter(final long permitsPerReplenishInterval,
          final Duration replenishmentInterval,
          final long initialNrOfPermits,
          final long maxAvailablePermits,
          final long minReplenishInterval,
          final TimeUnit tu,
          final ScheduledExecutorService scheduler,
          final LongSupplier nanoTimeSupplier,
          final int maxBackoffNanos); @Override boolean addPermits(final int nrPermits); boolean tryAcquire(); boolean tryAcquire(final int nrPermits); long getNrPermits(); @Override @SuppressFBWarnings("MDM_THREAD_YIELD") //fb has a point here... boolean tryAcquire(final int nrPermits, final long deadlineNanos); @CheckReturnValue @Override boolean tryAcquire(@Nonnegative final int nrPermits, @Nonnegative final long timeout, final TimeUnit unit); @Override Acquisition tryAcquireEx(final int nrPermits, final long timeout, final TimeUnit unit); @Override Acquisition tryAcquireEx(final int nrPermits, final long deadlineNanos); @Override void close(); long getPermitsPerReplenishInterval(); long getPermitReplenishIntervalNanos(); long getLastReplenishmentNanos(); @Override String toString();  }
@Test public void testRateLimitTryAcquisition() throws InterruptedException { try (RateLimiter rateLimiter = new RateLimiter(10, Duration.ofSeconds(1), 10)) { LOG.debug("Rate Limiter = {}", rateLimiter); Assert.assertFalse(rateLimiter.tryAcquire(20, 0, TimeUnit.MILLISECONDS)); long startTime = TimeSource.nanoTime(); boolean tryAcquire = rateLimiter.tryAcquire(20, 2, TimeUnit.SECONDS); LOG.debug("waited {} ns for {}", (TimeSource.nanoTime() - startTime), rateLimiter); Assert.assertTrue(tryAcquire); Assert.assertFalse(rateLimiter.tryAcquire(20, 1, TimeUnit.SECONDS)); } }