Tracks request capacity available to a resource. Intended to be used with Calls to potentially wait
until
capacity is available before making a request to avoid rate-limiting issues. Capacity is reduced in a weighted fashion
per call, and also potentially when response errors are observed.
var jsonConfig = "null";var ji = JsonIterator.parse(jsonConfig);var capacityConfig = CapacityConfig.parse(ji);if (capacityConfig == null) { // 10 requests per second with a maximum complete backoff of 5 seconds. capacityConfig = CapacityConfig.createSimpleConfig( Duration.ofSeconds(5), // minCapacityDuration 10, // maxCapacity Duration.ofSeconds(1) // resetDuration );}// Custom error tracker's may be implemented to handle responses other than HttpResponse<byte[]>.ErrorTrackedCapacityMonitor<HttpResponse<byte[]>> capacityMonitor = capacityConfig .createHttpResponseMonitor("service_name");
Facilitates retrying remote calls, using backoff strategies to delay between failures.If the backoff strategy returns a negative number or the error count exceeds the max retries for the call context,
the exception is re-thrown wrapped in a RuntimeException.