Package com.io7m.idstore.server.service.ratelimit

# 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 Summary

  Modifier and Type
  Method
  Description
  `static IdRateLimiter`
  `create(IdMetricsServiceType metrics, String name, long expiration, TimeUnit timeUnit)`
  Create a rate limiter.
  `String`
  `description()`
  `boolean`
  `isAllowedByRateLimit(String host, String user, String operation)`
  `String`
  `toString()`
  `Duration`
  `waitTime()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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`