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 configured permitsPerSecond rate up to the configured capacity.
remaining - The integer number of tokens currently available — floor(tokens). Mirrors the X-RateLimit-Remaining advisory 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-clock Instant at 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 Details

    • BucketState

      public BucketState(String key, double tokens, int remaining, boolean throttled, Instant lastRequest)
      Creates an instance of a BucketState record class.
      Parameters:
      key - the value for the key record component
      tokens - the value for the tokens record component
      remaining - the value for the remaining record component
      throttled - the value for the throttled record component
      lastRequest - the value for the lastRequest record component
  • Method Details

    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • key

      public String key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • tokens

      public double tokens()
      Returns the value of the tokens record component.
      Returns:
      the value of the tokens record component
    • remaining

      public int remaining()
      Returns the value of the remaining record component.
      Returns:
      the value of the remaining record component
    • throttled

      public boolean throttled()
      Returns the value of the throttled record component.
      Returns:
      the value of the throttled record component
    • lastRequest

      public Instant lastRequest()
      Returns the value of the lastRequest record component.
      Returns:
      the value of the lastRequest record component