@InterfaceAudience.Private @InterfaceStability.Evolving public class RateLimiter extends Object
| Constructor and Description |
|---|
RateLimiter() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canExecute(long now,
long lastTs)
given the time interval, is there at least one resource available to allow execution?
|
boolean |
canExecute(long now,
long lastTs,
long amount)
given the time interval, are there enough available resources to allow execution?
|
void |
consume()
consume one available unit.
|
void |
consume(long amount)
consume amount available units.
|
long |
getAvailable() |
long |
getLimit() |
boolean |
isBypass() |
void |
set(long limit,
TimeUnit timeUnit)
Set the RateLimiter max available resources and refill period.
|
String |
toString() |
void |
update(RateLimiter other)
Sets the current instance of RateLimiter to a new values.
|
long |
waitInterval() |
long |
waitInterval(long amount) |
public void set(long limit,
TimeUnit timeUnit)
limit - The max value available resource units can be refilled to.timeUnit - Timeunit factor for translating to ms.public void update(RateLimiter other)
public boolean isBypass()
public long getLimit()
public long getAvailable()
public boolean canExecute(long now,
long lastTs)
now - the current timestamplastTs - the timestamp of the last updatepublic boolean canExecute(long now,
long lastTs,
long amount)
now - the current timestamplastTs - the timestamp of the last updateamount - the number of required resourcespublic void consume()
public void consume(long amount)
amount - the number of units to consumepublic long waitInterval()
public long waitInterval(long amount)
Copyright © 2015 The Apache Software Foundation. All rights reserved.