Class ThrottlingHandler

java.lang.Object
java.util.logging.Handler
org.nasdanika.models.gitlab.util.ThrottlingHandler

public class ThrottlingHandler extends Handler
A Handler for throttling API calls based on rate limit HTTP response headers
  • Constructor Details

    • ThrottlingHandler

    • ThrottlingHandler

      public ThrottlingHandler(long clientRateLimitWindow, int clientRateLimit)
      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

      public int getConservatism()
    • setConservatism

      public void setConservatism(int conservatism)
      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

      public int getFactor()
    • setFactor

      public void setFactor(int factor)
      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

      public void publish(LogRecord logRecord)
      Specified by:
      publish in class Handler
    • flush

      public void flush()
      Specified by:
      flush in class Handler
    • close

      public void close() throws SecurityException
      Specified by:
      close in class Handler
      Throws:
      SecurityException