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

@UnstableApi public final class TokenBucket extends Object
Stores configuration of the Token-Bucket algorithm, comprised of multiple limits.
  • Method Details

    • builder

      public static TokenBucketBuilder builder()
      Returns a newly created TokenBucketBuilder.
    • of

      public static TokenBucket of(String specification)
      Returns a newly created TokenBucket. Computes a set of BandwidthLimit out of a comma-separated specification string that conforms to the following format, as per RateLimit Header Fields for HTTP:
      
       <bandwidth limit 1>[, <bandwidth limit 2>[, etc.]]
       
      The order of elements inside specification is not defined. For example:
      • 100;window=60;burst=1000, 50000;window=3600
      Parameters:
      specification - the specification used to create a BandwidthLimit
      See Also:
      TokenBucketSpec.parseTokenBucket(String)
    • of

      public static TokenBucket of(long limit, Duration period)
      Returns a newly created TokenBucket with a single 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
      Returns:
      Newly created TokenBucket
      See Also:
      BandwidthLimit.of(long, Duration)
    • limits

      public BandwidthLimit[] limits()
      Returns multiple limits applied to the bucket. This may be empty.
      Returns:
      An array of BandwidthLimit
    • toString

      public String toString()
      Overrides:
      toString in class Object