Class RateLimitSpec

java.lang.Object
org.frontcache.guard.ratelimit.RateLimitSpec

public class RateLimitSpec extends Object
The parsed form of a rate: predicate, computed once at load time.
  rate:<limit>/<window> [bucket=<name>] [scope=<toplevel|all>]

  rate:100/10s                 100 requests per 10-second slot, per IP
  rate:10/s                    a bare unit means 1, so this is 10 per second
  rate:10/1m bucket=login      shares its counter with any other rule naming bucket 'login'
bucket defaults to the rule name, which is resolved by the rule parser - the predicate factory does not know it. That default is deliberate: it makes a dry-run rule and a live rule separate counters, so a stricter limit can be measured against real traffic while the current one still enforces.
  • Method Details

    • parse

      public static RateLimitSpec parse(String arg, String expr)
      Parameters:
      arg - everything after "rate:"
      expr - the whole predicate as written, used in messages and by describe()
    • withDefaultBucket

      public RateLimitSpec withDefaultBucket(String ruleName)
      Returns:
      a copy with the bucket resolved, called by the rule parser once the rule name is known
    • getLimit

      public int getLimit()
    • getWindowMillis

      public long getWindowMillis()
    • getBucket

      public String getBucket()
    • isToplevelOnly

      public boolean isToplevelOnly()
    • getSource

      public String getSource()