Class RateLimit.Builder

java.lang.Object
com.jsgalactic.axiom.security.RateLimit.Builder
Enclosing class:
RateLimit

public static final class RateLimit.Builder extends Object
Builds RateLimits; not thread-safe, used during configuration.
  • Method Details

    • algorithm

      public RateLimit.Builder algorithm(RateLimit.Algorithm algorithm)
      Selects the algorithm.
      Parameters:
      algorithm - the algorithm
      Returns:
      this builder
    • burst

      public RateLimit.Builder burst(long burst)
      Sets the token bucket capacity: the most requests a idle key may send at once. By default it equals the limit. Ignored by the sliding window.
      Parameters:
      burst - capacity, 1 to the limit
      Returns:
      this builder
    • key

      public RateLimit.Builder key(RateLimitKey key)
      Sets the key function; the default is RateLimitKey.peerAddress().
      Parameters:
      key - key function
      Returns:
      this builder
    • maxKeys

      public RateLimit.Builder maxKeys(int maxKeys)
      Sets the most keys tracked at once (10,000 by default).
      Parameters:
      maxKeys - 1 to 10,000,000
      Returns:
      this builder
    • clock

      public RateLimit.Builder clock(Clock clock)
      Sets the time source, for deterministic tests.
      Parameters:
      clock - the clock
      Returns:
      this builder
    • metrics

      public RateLimit.Builder metrics(Metrics metrics)
      Records the limiter's metrics.
      Parameters:
      metrics - the metrics sink
      Returns:
      this builder
    • name

      public RateLimit.Builder name(String name)
      Names the limiter in metrics (tag limiter); default default.
      Parameters:
      name - lower-case letters, digits and underscores, starting with a letter, up to 32
      Returns:
      this builder
    • headers

      public RateLimit.Builder headers(boolean enabled)
      Adds the RateLimit-* headers to allowed responses (off by default).
      Parameters:
      enabled - whether to add them
      Returns:
      this builder
    • build

      public RateLimit build()
      Builds the limiter.
      Returns:
      a thread-safe limiter