public class BufferedRateLimitHandler extends DefaultRateLimitHandler
BufferedRateLimitHandler
extends the DefaultRateLimitHandler
. It checks the rate limit headers after each request,
and if a certain threshold is exceeded, it will soft rate limit the application for a certain time.
If you have a use case where you fire a lot of simultaneous requests (like asynchronously requesting many matches from a match list)
using multiple threads or even multiple dedicated servers, if you were to use the DefaultRateLimitHandler
, you would already have
fired many more requests before you get the first 429 response, resulting in all already fired requests to also result in 429 responses
before the DefaultRateLimitHandler
can actually prevent further requests from being fired before the rate limit resets. In such a
scenario you may want to stop firing new requests for X
seconds when you reach X
% of your rate limits, so that you have a
buffer for already fired requests to end gracefully.
DefaultRateLimitHandler.RateLimit, DefaultRateLimitHandler.RateLimitList
Constructor and Description |
---|
BufferedRateLimitHandler(double threshold,
int cooldown)
Creates a new
BufferedRateLimitHandler . |
Modifier and Type | Method and Description |
---|---|
void |
onRequestDone(Request request)
This method is called for every request after it has finished.
|
onRequestAboutToFire
public BufferedRateLimitHandler(double threshold, int cooldown)
BufferedRateLimitHandler
.threshold
- Rate limit threshold to trigger a soft rate limit (e.g. 0.9 for 90%)cooldown
- Time interval in seconds for an app or method to go on cooldown once the threshold has been exceededpublic void onRequestDone(Request request)
RateLimitHandler
onRequestDone
in interface RateLimitHandler
onRequestDone
in class DefaultRateLimitHandler