Class IdRateLimiter

java.lang.Object
com.io7m.idstore.server.service.ratelimit.IdRateLimiter
All Implemented Interfaces:
IdRateLimiterType, com.io7m.repetoir.core.RPServiceType

public final class IdRateLimiter extends Object implements IdRateLimiterType
A trivial rate limiter.
  • Method Details

    • create

      public static IdRateLimiter create(IdMetricsServiceType metrics, String name, long expiration, TimeUnit timeUnit)
      Create a rate limiter.
      Parameters:
      metrics - The metrics service
      name - The rate name
      expiration - The expiration for tokens
      timeUnit - The time unit for expirations
      Returns:
      A rate limiter
    • isAllowedByRateLimit

      public boolean isAllowedByRateLimit(String host, String user, String operation)
      Parameters:
      host - The host performing the action
      user - The user performing the action
      operation - The operation
      Returns:
      true if the given operation is allowed by rate limiting
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • waitTime

      public Duration waitTime()
      Specified by:
      waitTime in interface IdRateLimiterType
      Returns:
      The suggested wait time if a rate limit is exceeded
    • description

      public String description()
      Specified by:
      description in interface com.io7m.repetoir.core.RPServiceType