Interface RateLimiter

All Superinterfaces:
AutoCloseable, Serializable
All Known Implementing Classes:
EnvoyRateLimiter

public interface RateLimiter extends Serializable, AutoCloseable
A RateLimiter allows to fetch permits from a rate limiter service and blocks execution when the rate limit is exceeded.

Implementations must be Serializable as they are passed to workers.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    allow(int permits)
    Blocks until the specified number of permits are acquired and returns true if the request was allowed or false if the request was rejected.

    Methods inherited from interface java.lang.AutoCloseable

    close
  • Method Details

    • allow

      boolean allow(int permits) throws IOException, InterruptedException
      Blocks until the specified number of permits are acquired and returns true if the request was allowed or false if the request was rejected.
      Parameters:
      permits - Number of permits to acquire.
      Returns:
      true if the request was allowed, false if it was rejected (and retries exceeded).
      Throws:
      IOException - if there is an error communicating with the rate limiter service.
      InterruptedException - if the thread is interrupted while waiting.