Package net.ygbstudio.jbrave.api.rate
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 windowwindowSecond- Window size in seconds (typically one second).limitPerMonth- Limit of 1 request over a one-month windowwindowMonth- 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 Summary
ConstructorsConstructorDescriptionXRateLimitPolicy(int limit, int windowSecond, int limitPerMonth, int windowMonth) Creates an instance of aXRateLimitPolicyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.static <T> Optional<XRateLimitPolicy> from(@NotNull HttpResponse<T> httpResponse) Extracts the rate limit policy from the HTTP Response.final inthashCode()Returns a hash code value for this object.intlimit()Returns the value of thelimitrecord component.intReturns the value of thelimitPerMonthrecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thewindowMonthrecord component.intReturns the value of thewindowSecondrecord component.
-
Constructor Details
-
XRateLimitPolicy
public XRateLimitPolicy(int limit, int windowSecond, int limitPerMonth, int windowMonth) Creates an instance of aXRateLimitPolicyrecord class.- Parameters:
limit- the value for thelimitrecord componentwindowSecond- the value for thewindowSecondrecord componentlimitPerMonth- the value for thelimitPerMonthrecord componentwindowMonth- the value for thewindowMonthrecord component
-
-
Method Details
-
from
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
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
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. -
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. All components in this record class are compared with '=='. -
limit
public int limit()Returns the value of thelimitrecord component.- Returns:
- the value of the
limitrecord component
-
windowSecond
public int windowSecond()Returns the value of thewindowSecondrecord component.- Returns:
- the value of the
windowSecondrecord component
-
limitPerMonth
public int limitPerMonth()Returns the value of thelimitPerMonthrecord component.- Returns:
- the value of the
limitPerMonthrecord component
-
windowMonth
public int windowMonth()Returns the value of thewindowMonthrecord component.- Returns:
- the value of the
windowMonthrecord component
-