Package ch.bztf.m226blb1.Utils
Class RateLimiter
java.lang.Object
ch.bztf.m226blb1.Utils.RateLimiter
This class is used to limit the amount of requests. There is a limiter for
each
platform
.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RateLimiter
getInstance
(@NonNull Platform platform) Gets the rate limiter for the given platform.boolean
tryConsume
(@javax.validation.constraints.PositiveOrZero long accountId) Checks if the given platform is allowed to make a request.
-
Field Details
-
LIMIT
public static final int LIMITThe limit (900) of requests.- See Also:
-
-
Method Details
-
getInstance
Gets the rate limiter for the given platform.- Parameters:
platform
- the platform to get the rate limiter for- Returns:
- the rate limiter for the given platform
- Implementation Note:
- This method is thread-safe.
-
tryConsume
public boolean tryConsume(@PositiveOrZero @javax.validation.constraints.PositiveOrZero long accountId) Checks if the given platform is allowed to make a request.- Parameters:
accountId
- the id of the account to check- Returns:
- true if the given account is allowed to make a request to the given platform, false otherwise
- Implementation Note:
- If the account id is negative, the request is always blocked.
-