Interface RestRateLimiter.Work

Enclosing interface:
RestRateLimiter

public static interface RestRateLimiter.Work
Type representing a pending request.

Use execute() to run the request (on the calling thread) and isDone() to discard it once completed.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Cancel the request.
    okhttp3.Response
    Executes the request on the calling thread (blocking).
    The JDA instance which started the request.
    The compiled route of the request.
    boolean
    Whether this request was cancelled.
    boolean
    Whether the request is completed.
    boolean
    Requests marked as priority should not be cancelled.
    boolean
    Whether the request should be skipped.
  • Method Details

    • getRoute

      The compiled route of the request.
      This is primarily used to handle rate-limit buckets.

      To correctly handle rate-limits, it is recommended to use the bucket hash header from the response.

      Returns:
      The compiled route
    • getJDA

      @Nonnull JDA getJDA()
      The JDA instance which started the request.
      Returns:
      The JDA instance
    • execute

      @Nullable @Blocking okhttp3.Response execute()
      Executes the request on the calling thread (blocking).
      This might return null when the request has been skipped while executing. Retries for certain response codes are already handled by this method.

      After completion, it is advised to use isDone() to check whether the request should be retried.

      Returns:
      Response instance, used to update the rate-limit data
    • isSkipped

      boolean isSkipped()
      Whether the request should be skipped.
      This can be caused by user cancellation.

      The rate-limiter should handle by simply discarding the task without further action.

      Returns:
      True, if this request is skipped
    • isDone

      boolean isDone()
      Whether the request is completed.
      This means you should not try using execute() again.
      Returns:
      True, if the request has completed.
    • isPriority

      boolean isPriority()
      Requests marked as priority should not be cancelled.
      Returns:
      True, if this request is marked as priority
    • isCancelled

      boolean isCancelled()
      Whether this request was cancelled.
      Similar to isSkipped(), but only checks cancellation.
      Returns:
      True, if this request was cancelled
    • cancel

      void cancel()
      Cancel the request.
      Primarily used for JDA.cancelRequests().