Class NonBlockingRateLimiter

java.lang.Object
org.apache.cassandra.utils.concurrent.NonBlockingRateLimiter

@ThreadSafe public class NonBlockingRateLimiter extends Object
A rate limiter implementation that allows callers to reserve permits that may only be available in the future, delegating to them decisions about how to schedule/delay work and whether or not to block execution to do so.
  • Field Details

    • NANOS_PER_SECOND

      public static final long NANOS_PER_SECOND
    • NO_OP_LIMITER

      public static final NonBlockingRateLimiter NO_OP_LIMITER
  • Constructor Details

    • NonBlockingRateLimiter

      public NonBlockingRateLimiter(int permitsPerSecond)
    • NonBlockingRateLimiter

      public NonBlockingRateLimiter(int permitsPerSecond, long burstNanos, com.google.common.base.Ticker ticker)
  • Method Details

    • setRate

      public void setRate(int permitsPerSecond)
    • setRate

      public void setRate(int permitsPerSecond, com.google.common.base.Ticker ticker)
    • getRate

      public int getRate()
      Returns:
      the number of available permits per second
    • reserveAndGetDelay

      public long reserveAndGetDelay(TimeUnit delayUnit)
      Reserves a single permit slot on the timeline which may not yet be available.
      Returns:
      time until the reserved permit will be available (or zero if it already is) in the specified units
    • tryReserve

      public boolean tryReserve()
      Reserves a single permit slot on the timeline, but only if one is available.
      Returns:
      true if a permit is available, false if one is not
    • getIntervalNanos

      public long getIntervalNanos()
    • getStartedNanos

      public long getStartedNanos()