public class SimpleRateLimiter extends Object implements RateLimiter
RateLimiter
.Constructor and Description |
---|
SimpleRateLimiter(long permitsPerSecond,
com.google.common.base.Ticker ticker)
Creates a simple rate limiter for testing purpose.
|
Modifier and Type | Method and Description |
---|---|
Optional<Long> |
acquire()
Acquire a permit for the next operation.
|
long |
getWaitTimeNanos(long permit)
Checks how long is needed to wait for this permit to be ready.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createRateLimiter
public SimpleRateLimiter(long permitsPerSecond, com.google.common.base.Ticker ticker)
permitsPerSecond
- permits per secondticker
- the tickerpublic long getWaitTimeNanos(long permit)
RateLimiter
getWaitTimeNanos
in interface RateLimiter
permit
- the permit returned by RateLimiter.acquire()
public Optional<Long> acquire()
RateLimiter
acquire
in interface RateLimiter
Optional.empty()
if no waiting is needed, otherwise
the value contained in the returned optional is the permit, which
can be used in calls to RateLimiter.getWaitTimeNanos(long)
to see how long to wait for the operation to be ready.Copyright © 2023. All Rights Reserved.