Class BandwidthLimit

java.lang.Object
com.linecorp.armeria.server.throttling.bucket4j.BandwidthLimit

@UnstableApi
public final class BandwidthLimit
extends Object
Stores configurations of a single Token-Bucket bandwidth limit.
  • Method Details

    • of

      public static BandwidthLimit of​(long limit, long overdraftLimit, long initialSize, Duration period)
      Returns a newly created BandwidthLimit. 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 bucket
      overdraftLimit - defines the maximum overdraft count of tokens which can be held by the bucket, this value must exceed the limit
      initialSize - the initial number of tokens available to this bandwidth limit
      period - the time window, during which the tokens will be regenerated
    • of

      public static BandwidthLimit of​(long limit, long overdraftLimit, Duration period)
      Returns a newly created BandwidthLimit. 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 bucket
      overdraftLimit - defines the maximum overdraft count of tokens which can be held by the bucket, this value must exceed the limit
      period - the time window, during which the tokens will be regenerated
    • of

      public static BandwidthLimit of​(long limit, Duration period)
      Returns a newly created simple BandwidthLimit. Specifies easy limitation of limit tokens per period time 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 bucket
      period - the time window, during which the tokens will be regenerated
    • of

      public static BandwidthLimit of​(String specification)
      Returns a newly created BandwidthLimit. Computes limit, overdraftLimit, initialSize and period out of a semicolon-separated specification string that conforms to the following format, as per RateLimit Header Scheme for HTTP:
      
       <limit>;window=<period(in seconds)>[;burst=<overdraftLimit>][;initial=<initialSize>]
       
      All specification string elements must come in the defined order. For example:
      • 100;window=60;burst=1000 (limit=100, overdraftLimit=1000, initialSize and period=60seconds)
      • 100;window=60;burst=1000;initial=20 (limit=100, overdraftLimit=1000, initialSize=20 and period=60seconds)
      • 5000;window=1 (limit=5000 and period=1second)
      Parameters:
      specification - the specification used to create a BandwidthLimit
    • 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 the BandwidthLimit#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

      public Duration period()
      Returns the time window, during which the tokens will be regenerated for the given bandwidth limit.
      Returns:
      Time window for the limit.
    • toString

      public String toString()
      Overrides:
      toString in class Object