Class RateLimiter

java.lang.Object
ch.bztf.m226blb1.Utils.RateLimiter

public class RateLimiter extends Object
This class is used to limit the amount of requests. There is a limiter for each platform.
See Also:
Implementation Requirements:
The implementation is based on the Bucket4j library.
Implementation Note:
This class is a singleton.
  • Field Details

  • Method Details

    • getInstance

      public static RateLimiter getInstance(@NonNull @NonNull Platform platform)
      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.