@InterfaceAudience.Private @InterfaceStability.Evolving public abstract class RateLimiter extends Object
Modifier and Type | Field and Description |
---|---|
private long |
avail |
private long |
limit |
static String |
QUOTA_RATE_LIMITER_CONF_KEY |
private long |
tunit |
Constructor and Description |
---|
RateLimiter() |
Modifier and Type | Method and Description |
---|---|
boolean |
canExecute()
Is there at least one resource available to allow execution?
|
boolean |
canExecute(long amount)
Are there enough available resources to allow execution?
|
void |
consume()
consume one available unit.
|
void |
consume(long amount)
consume amount available units, amount could be a negative number
|
long |
getAvailable() |
long |
getLimit() |
abstract long |
getNextRefillTime() |
protected long |
getTimeUnitInMillis() |
(package private) abstract long |
getWaitInterval(long limit,
long available,
long amount)
Time in milliseconds to wait for before requesting to consume 'amount' resource.
|
boolean |
isBypass() |
(package private) abstract long |
refill(long limit)
Refill the available units w.r.t the elapsed time.
|
void |
set(long limit,
TimeUnit timeUnit)
Set the RateLimiter max available resources and refill period.
|
abstract void |
setNextRefillTime(long nextRefillTime) |
String |
toString() |
void |
update(RateLimiter other)
Sets the current instance of RateLimiter to a new values.
|
long |
waitInterval()
Returns estimate of the ms required to wait before being able to provide 1 resource.
|
long |
waitInterval(long amount)
Returns estimate of the ms required to wait before being able to provide "amount" resources.
|
public static final String QUOTA_RATE_LIMITER_CONF_KEY
private long tunit
private long limit
private long avail
public RateLimiter()
abstract long refill(long limit)
limit
- Maximum available resource units that can be refilled to.abstract long getWaitInterval(long limit, long available, long amount)
limit
- Maximum available resource units that can be refilled to.available
- Currently available resource unitsamount
- Resources for which time interval to calculate forpublic 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()
protected long getTimeUnitInMillis()
public boolean canExecute()
public boolean canExecute(long amount)
amount
- the number of required resources, a non-negative numberpublic void consume()
public void consume(long amount)
amount
- the number of units to consumepublic long waitInterval()
public long waitInterval(long amount)
public abstract void setNextRefillTime(long nextRefillTime)
public abstract long getNextRefillTime()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.