Class NonBlockingRateLimiter
- java.lang.Object
-
- org.apache.cassandra.utils.concurrent.NonBlockingRateLimiter
-
@ThreadSafe public class NonBlockingRateLimiter extends java.lang.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 Summary
Fields Modifier and Type Field Description static long
NANOS_PER_SECOND
static NonBlockingRateLimiter
NO_OP_LIMITER
-
Constructor Summary
Constructors Constructor Description NonBlockingRateLimiter(int permitsPerSecond)
NonBlockingRateLimiter(int permitsPerSecond, long burstNanos, com.google.common.base.Ticker ticker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getIntervalNanos()
int
getRate()
long
getStartedNanos()
long
reserveAndGetDelay(java.util.concurrent.TimeUnit delayUnit)
Reserves a single permit slot on the timeline which may not yet be available.void
setRate(int permitsPerSecond)
void
setRate(int permitsPerSecond, com.google.common.base.Ticker ticker)
boolean
tryReserve()
Reserves a single permit slot on the timeline, but only if one is available.
-
-
-
Field Detail
-
NANOS_PER_SECOND
public static final long NANOS_PER_SECOND
-
NO_OP_LIMITER
public static final NonBlockingRateLimiter NO_OP_LIMITER
-
-
Method Detail
-
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(java.util.concurrent.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()
-
-