Record Class RateLimitGuard.BucketState
java.lang.Object
java.lang.Record
org.apache.juneau.rest.server.guard.RateLimitGuard.BucketState
- Record Components:
key- The per-request key (e.g. remote address, principal name).tokens- The current fractional token count in the bucket. Continuously refilled at the configuredpermitsPerSecondrate up to the configured capacity.remaining- The integer number of tokens currently available —floor(tokens). Mirrors theX-RateLimit-Remainingadvisory header.throttled-true when the bucket is empty enough that the next request would be rejected (tokens < 1.0). Convenience flag for at-a-glance operator dashboards.lastRequest- The wall-clockInstantat which the bucket was last touched.
- Enclosing class:
- RateLimitGuard
public static record RateLimitGuard.BucketState(String key, double tokens, int remaining, boolean throttled, Instant lastRequest)
extends Record
Point-in-time view of a single token bucket as exposed by
RateLimitGuard.Storage.snapshot().
Used by operator-facing tooling (e.g. AdminMixin's /admin/ratelimit endpoint) to
surface live per-key bucket state alongside the static configuration. Token-bucket vocabulary
intentionally — there is no discrete refill window because the bucket refills continuously at
permitsPerSecond, so this record reports the current fill level (tokens()), the integer
tokens currently available (remaining()), a convenience throttled flag, and the wall-clock instant
of the bucket's last activity.
- Since:
- 10.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionBucketState(String key, double tokens, int remaining, boolean throttled, Instant lastRequest) Creates an instance of aBucketStaterecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.key()Returns the value of thekeyrecord component.Returns the value of thelastRequestrecord component.intReturns the value of theremainingrecord component.booleanReturns the value of thethrottledrecord component.doubletokens()Returns the value of thetokensrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
BucketState
public BucketState(String key, double tokens, int remaining, boolean throttled, Instant lastRequest) Creates an instance of aBucketStaterecord class.- Parameters:
key- the value for thekeyrecord componenttokens- the value for thetokensrecord componentremaining- the value for theremainingrecord componentthrottled- the value for thethrottledrecord componentlastRequest- the value for thelastRequestrecord component
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
key
Returns the value of thekeyrecord component.- Returns:
- the value of the
keyrecord component
-
tokens
Returns the value of thetokensrecord component.- Returns:
- the value of the
tokensrecord component
-
remaining
Returns the value of theremainingrecord component.- Returns:
- the value of the
remainingrecord component
-
throttled
Returns the value of thethrottledrecord component.- Returns:
- the value of the
throttledrecord component
-
lastRequest
Returns the value of thelastRequestrecord component.- Returns:
- the value of the
lastRequestrecord component
-