java.lang.Object
java.util.logging.Handler
org.nasdanika.models.gitlab.util.ThrottlingHandler
A
Handler for throttling API calls based on rate limit HTTP response headers-
Constructor Summary
ConstructorsConstructorDescriptionThrottlingHandler(long clientRateLimitWindow, int clientRateLimit) Client rate limit is enforced before sending a request. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()intintvoidvoidsetConservatism(int conservatism) Number in seconds to add to the server rate window when computing throttling sleep interval.voidsetFactor(int factor) Determines when to start throttling.Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
-
Constructor Details
-
ThrottlingHandler
public ThrottlingHandler() -
ThrottlingHandler
Client rate limit is enforced before sending a request.- Parameters:
clientRateLimitWindow- Client rate window in milliseconds. Client rate limit is enforced if this value and clientRateLimit are positive.clientRateLimit- Client rate limit per rate window. Client rate limit is enforced if this value and clientRateLimitWindow are positive.
-
-
Method Details
-
getConservatism
-
setConservatism
Number in seconds to add to the server rate window when computing throttling sleep interval. Non-zero conservatism ensures that not all rate is used before the window ends. The default value is 3.- Parameters:
conservatism-
-
getFactor
-
setFactor
Determines when to start throttling. Throttling starts when the remaining server rate limit is less than rate limit divided by factor. E.g. if factor is 20 then throttling will start when 95% of the rate has been used. The default is 10 - throttling starts after 90% of the rate has been used.- Parameters:
factor-
-
publish
-
flush
-
close
- Specified by:
closein classHandler- Throws:
SecurityException
-