|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ITokenBucket
Basically token bucket is used to control the bandwidth used by a stream or a connection or a client. There's a background thread that distributes tokens to the buckets in the system according to the configuration of the bucket. The configuration includes how fast the tokens are distributed. When a stream, for example, needs to send out a packet, the packet's byte count is calculated and each byte corresponds to a token in the bucket. The stream is assigned a bucket and the tokens in the bucket are acquired before the packet can be sent out. So if the speed(or bandwidth) in configuration is low, the stream can't send out packets fast.
Nested Class Summary | |
---|---|
static interface |
ITokenBucket.ITokenBucketCallback
Callback for tocket bucket |
Method Summary | |
---|---|
boolean |
acquireToken(long tokenCount,
long wait)
Acquire tokens amount of tokenCount waiting wait milliseconds if token not available. |
long |
acquireTokenBestEffort(long upperLimitCount)
Nonblockingly acquire token. |
boolean |
acquireTokenNonblocking(long tokenCount,
ITokenBucket.ITokenBucketCallback callback)
Nonblockingly acquire token. |
long |
getCapacity()
Get the capacity of this bucket in Byte. |
double |
getSpeed()
The amount of tokens increased per millisecond. |
void |
reset()
Reset this token bucket. |
Method Detail |
---|
boolean acquireToken(long tokenCount, long wait)
tokenCount
- The count of tokens to acquire.wait
- Milliseconds to wait. 0 means no wait
and any value below zero means wait forever.
boolean acquireTokenNonblocking(long tokenCount, ITokenBucket.ITokenBucketCallback callback)
tokenCount
- Number of tokenscallback
- Callback
long acquireTokenBestEffort(long upperLimitCount)
upperLimitCount
- Upper limit of aquisition
long getCapacity()
double getSpeed()
void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |