Interface RestRateLimiter

All Known Implementing Classes:
SequentialRestRateLimiter

public interface RestRateLimiter
Interface used to handle requests to the Discord API.

Requests are handed to the rate-limiter via enqueue(Work) and executed using RestRateLimiter.Work.execute(). The rate-limiter is responsible to ensure that requests do not exceed the rate-limit set by Discord.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Global rate-limit store.
    static class 
    Configuration for the rate-limiter.
    static interface 
    Type representing a pending request.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Returned only on HTTP 429 responses if the rate limit encountered is the global rate limit (not per-route)
    static final String
    A unique string denoting the rate limit being encountered (non-inclusive of top-level resources in the path)
    static final String
    The number of requests that can be made
    static final String
    The number of remaining requests that can be made
    static final String
    Total time (in seconds) of when the current rate limit bucket will reset.
    static final String
    Epoch time (seconds since 00:00:00 UTC on January 1, 1970) at which the rate limit resets
    static final String
    The number of seconds to wait before submitting another request
    static final String
    Returned only on HTTP 429 responses.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Cancel all currently queued requests, which are not marked as priority.
    void
    Enqueue a new request.
    boolean
    Whether the queue has stopped accepting new requests.
    void
    stop(boolean shutdown, Runnable callback)
    Indication to stop accepting new requests.
  • Field Details

    • RESET_AFTER_HEADER

      static final String RESET_AFTER_HEADER
      Total time (in seconds) of when the current rate limit bucket will reset. Can have decimals to match previous millisecond ratelimit precision
      See Also:
    • RESET_HEADER

      static final String RESET_HEADER
      Epoch time (seconds since 00:00:00 UTC on January 1, 1970) at which the rate limit resets
      See Also:
    • LIMIT_HEADER

      static final String LIMIT_HEADER
      The number of requests that can be made
      See Also:
    • REMAINING_HEADER

      static final String REMAINING_HEADER
      The number of remaining requests that can be made
      See Also:
    • HASH_HEADER

      static final String HASH_HEADER
      A unique string denoting the rate limit being encountered (non-inclusive of top-level resources in the path)
      See Also:
    • RETRY_AFTER_HEADER

      static final String RETRY_AFTER_HEADER
      The number of seconds to wait before submitting another request
      See Also:
    • SCOPE_HEADER

      static final String SCOPE_HEADER
      Returned only on HTTP 429 responses. Value can be user (per bot or user limit), global (per bot or user global limit), or shared (per resource limit)
      See Also:
  • Method Details

    • enqueue

      void enqueue(@Nonnull RestRateLimiter.Work task)
      Enqueue a new request.

      Use RestRateLimiter.Work.getRoute() to determine the correct bucket.

      Parameters:
      task - The RestRateLimiter.Work to enqueue
    • stop

      void stop(boolean shutdown, @Nonnull Runnable callback)
      Indication to stop accepting new requests.
      Parameters:
      shutdown - Whether to also cancel previously queued request
      callback - Function to call once all requests are completed, used for final cleanup
    • isStopped

      boolean isStopped()
      Whether the queue has stopped accepting new requests.
      Returns:
      True, if the queue is stopped
    • cancelRequests

      int cancelRequests()
      Cancel all currently queued requests, which are not marked as priority.
      Returns:
      The number of cancelled requests