- Direct Known Subclasses:
public abstract class RateLimitChecker extends ObjectA GitHub API Rate Limit Checker called before each request
GitHub allots a certain number of requests to each user or application per period of time. The number of requests remaining and the time when the number will be reset is returned in the response header and can also be requested using
GitHub.getRateLimit(). The "requests per interval" is referred to as the "rate limit".
GitHub prefers that clients stop before exceeding their rate limit rather than stopping after they exceed it. The
RateLimitCheckeris called before each request to check the rate limit and wait if the checker criteria are met.
Constructors Constructor Description
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
checkRateLimit(GHRateLimit.Record rateLimitRecord, long count)Decides whether the current request exceeds the allowed "rate limit" budget.
public static final RateLimitChecker NONE
protected boolean checkRateLimit(GHRateLimit.Record rateLimitRecord, long count) throws InterruptedExceptionDecides whether the current request exceeds the allowed "rate limit" budget. If this determines the rate limit will be exceeded, this method should sleep for some amount of time and must return
true. Implementers are free to choose whatever strategy they prefer for what is considered to exceed the budget and how long to sleep.
The caller of this method figures out which
GHRateLimit.Recordapplies for the current request and provides it to this method.
As long as this method returns
trueit is guaranteed that
GitHubRateLimitCheckerwill retrieve updated rate limit information and call this method again with
countincremented by one. When this checker returns
false, the calling
GitHubRateLimitCheckerwill let the request continue.
Rate limit reset times are only accurate to the second. Trying to sleep to exactly the reset time could result in requests being sent before the new rate limit was available. For this reason, if this method returned
trueat least once for a particular request,
GitHubRateLimitCheckermay choose to sleep for some small additional between calls and before letting the request continue.
rateLimitRecord- the current
GHRateLimit.Recordto check against.
count- the number of times in a row this method has been called for the current request
falseif the current request does not exceed the allowed budget,
trueif the current request exceeded the budget.
InterruptedException- if the thread is interrupted while sleeping