Package net.dv8tion.jda.api.requests
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
Modifier and TypeInterfaceDescriptionstatic interface
Global rate-limit store.static class
Configuration for the rate-limiter.static interface
Type representing a pending request. -
Field Summary
Modifier and TypeFieldDescriptionstatic 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 madestatic final String
The number of remaining requests that can be madestatic 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 resetsstatic final String
The number of seconds to wait before submitting another requeststatic final String
Returned only on HTTP 429 responses. -
Method Summary
Modifier and TypeMethodDescriptionint
Cancel all currently queued requests, which are not marked aspriority
.void
enqueue
(RestRateLimiter.Work task) Enqueue a new request.boolean
Whether the queue has stopped accepting new requests.void
Indication to stop accepting new requests.
-
Field Details
-
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
Epoch time (seconds since 00:00:00 UTC on January 1, 1970) at which the rate limit resets- See Also:
-
LIMIT_HEADER
The number of requests that can be made- See Also:
-
REMAINING_HEADER
The number of remaining requests that can be made- See Also:
-
GLOBAL_HEADER
Returned only on HTTP 429 responses if the rate limit encountered is the global rate limit (not per-route)- See Also:
-
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
The number of seconds to wait before submitting another request- See Also:
-
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
Enqueue a new request.Use
RestRateLimiter.Work.getRoute()
to determine the correct bucket.- Parameters:
task
- TheRestRateLimiter.Work
to enqueue
-
stop
Indication to stop accepting new requests.- Parameters:
shutdown
- Whether to also cancel previously queued requestcallback
- 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 aspriority
.- Returns:
- The number of cancelled requests
-