Package com.jsgalactic.axiom.security
Class RateLimit.Builder
java.lang.Object
com.jsgalactic.axiom.security.RateLimit.Builder
- Enclosing class:
RateLimit
Builds
RateLimits; not thread-safe, used during configuration.-
Method Summary
Modifier and TypeMethodDescriptionalgorithm(RateLimit.Algorithm algorithm) Selects the algorithm.build()Builds the limiter.burst(long burst) Sets the token bucket capacity: the most requests a idle key may send at once.Sets the time source, for deterministic tests.headers(boolean enabled) Adds theRateLimit-*headers to allowed responses (off by default).key(RateLimitKey key) Sets the key function; the default isRateLimitKey.peerAddress().maxKeys(int maxKeys) Sets the most keys tracked at once (10,000 by default).Records the limiter's metrics.Names the limiter in metrics (taglimiter); defaultdefault.
-
Method Details
-
algorithm
Selects the algorithm.- Parameters:
algorithm- the algorithm- Returns:
- this builder
-
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
Sets the key function; the default isRateLimitKey.peerAddress().- Parameters:
key- key function- Returns:
- this builder
-
maxKeys
Sets the most keys tracked at once (10,000 by default).- Parameters:
maxKeys- 1 to 10,000,000- Returns:
- this builder
-
clock
Sets the time source, for deterministic tests.- Parameters:
clock- the clock- Returns:
- this builder
-
metrics
Records the limiter's metrics.- Parameters:
metrics- the metrics sink- Returns:
- this builder
-
name
Names the limiter in metrics (taglimiter); defaultdefault.- Parameters:
name- lower-case letters, digits and underscores, starting with a letter, up to 32- Returns:
- this builder
-
headers
Adds theRateLimit-*headers to allowed responses (off by default).- Parameters:
enabled- whether to add them- Returns:
- this builder
-
build
Builds the limiter.- Returns:
- a thread-safe limiter
-