Record Class XRateLimitPolicy

java.lang.Object
java.lang.Record
net.ygbstudio.jbrave.api.rate.XRateLimitPolicy
Record Components:
limit - Limit of 1 request over a 1-second window
windowSecond - Window size in seconds (typically one second).
limitPerMonth - Limit of 1 request over a one-month window
windowMonth - Window size equivalent to one month in seconds

public record XRateLimitPolicy(int limit, int windowSecond, int limitPerMonth, int windowMonth) extends Record
Provides the complete policy specification including time window sizes.

Tip: According to the official docs, it is recommended that instead of bursting all requests at once, distribute them evenly throughout your time window to maximize throughput and avoid hitting the per-second limit.

Regarding time windows: Your plan may have multiple limit windows (per-second, quota). The docs recommend tracking all to ensure you do not exceed either limit.

Windows are always expressed in seconds.

  • Constructor Details

    • XRateLimitPolicy

      public XRateLimitPolicy(int limit, int windowSecond, int limitPerMonth, int windowMonth)
      Creates an instance of a XRateLimitPolicy record class.
      Parameters:
      limit - the value for the limit record component
      windowSecond - the value for the windowSecond record component
      limitPerMonth - the value for the limitPerMonth record component
      windowMonth - the value for the windowMonth record component
  • Method Details

    • from

      public static <T> Optional<XRateLimitPolicy> from(@NotNull @NotNull HttpResponse<T> httpResponse)
      Extracts the rate limit policy from the HTTP Response.
      Type Parameters:
      T - the type of the response body
      Parameters:
      httpResponse - the HTTP Response object containing the rate limit policy information
      Returns:
      an optional of the rate limit policy extracted from the httpResponse
    • 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. All components in this record class 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.
    • limit

      public int limit()
      Returns the value of the limit record component.
      Returns:
      the value of the limit record component
    • windowSecond

      public int windowSecond()
      Returns the value of the windowSecond record component.
      Returns:
      the value of the windowSecond record component
    • limitPerMonth

      public int limitPerMonth()
      Returns the value of the limitPerMonth record component.
      Returns:
      the value of the limitPerMonth record component
    • windowMonth

      public int windowMonth()
      Returns the value of the windowMonth record component.
      Returns:
      the value of the windowMonth record component