Class BandwidthLimit
java.lang.Object
com.linecorp.armeria.server.throttling.bucket4j.BandwidthLimit
Stores configurations of a single Token-Bucket bandwidth limit.
-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of initial available tokens available to this bandwidth limit.longlimit()Returns the bucket size, which defines the count of tokens which can be held by the bucket and defines the speed at which tokens are regenerated in the bucket.static BandwidthLimitReturns a newly createdBandwidthLimit.static BandwidthLimitReturns a newly createdBandwidthLimit.static BandwidthLimitReturns a newly created simpleBandwidthLimit.static BandwidthLimitReturns a newly createdBandwidthLimit.longReturns the maximum overdraft count of tokens which can be held by the bucket.period()Returns the time window, during which the tokens will be regenerated for the given bandwidth limit.toString()
-
Method Details
-
of
Returns a newly createdBandwidthLimit. Specifies limitation in classic interpretation of token-bucket algorithm.- Parameters:
limit- the bucket size - defines the count of tokens which can be held by the bucket and defines the speed at which tokens are regenerated in the bucketoverdraftLimit- defines the maximum overdraft count of tokens which can be held by the bucket, this value must exceed thelimitinitialSize- the initial number of tokens available to this bandwidth limitperiod- the time window, during which the tokens will be regenerated
-
of
Returns a newly createdBandwidthLimit. Specifies limitation in classic interpretation of token-bucket algorithm.- Parameters:
limit- the bucket size - defines the count of tokens which can be held by the bucket and defines the speed at which tokens are regenerated in the bucketoverdraftLimit- defines the maximum overdraft count of tokens which can be held by the bucket, this value must exceed thelimitperiod- the time window, during which the tokens will be regenerated
-
of
Returns a newly created simpleBandwidthLimit. Specifies easy limitation oflimittokens perperiodtime window.- Parameters:
limit- the bucket size - defines the maximum count of tokens which can be held by the bucket and defines the speed at which tokens are regenerated in the bucketperiod- the time window, during which the tokens will be regenerated
-
of
Returns a newly createdBandwidthLimit. Computeslimit,overdraftLimit,initialSizeandperiodout of a semicolon-separatedspecificationstring that conforms to the following format, as per RateLimit Header Fields for HTTP:
All<limit>;window=<period(in seconds)>[;burst=<overdraftLimit>][;initial=<initialSize>]specificationstring elements must come in the defined order. For example:100;window=60;burst=1000(limit=100,overdraftLimit=1000,initialSizeandperiod=60seconds)100;window=60;burst=1000;initial=20(limit=100,overdraftLimit=1000,initialSize=20 andperiod=60seconds)5000;window=1(limit=5000 andperiod=1second)
- Parameters:
specification- the specification used to create aBandwidthLimit
-
limit
public long limit()Returns the bucket size, which defines the count of tokens which can be held by the bucket and defines the speed at which tokens are regenerated in the bucket.- Returns:
- Bucket size.
-
overdraftLimit
public long overdraftLimit()Returns the maximum overdraft count of tokens which can be held by the bucket. This value always exceeds theBandwidthLimit#limit()or equals to 0, if not specified.- Returns:
- Bucket maximum overdraft count.
-
initialSize
public long initialSize()Returns the number of initial available tokens available to this bandwidth limit. The initial limit allows having lesser initial size, for example, in case of cold start in order to prevent denial of service. This value equals to 0, if not set.- Returns:
- the number of initial tokens in the bandwidth.
-
period
Returns the time window, during which the tokens will be regenerated for the given bandwidth limit.- Returns:
- Time window for the limit.
-
toString
-