Class AbstractBackoff
java.lang.Object
org.apache.hc.client5.http.impl.classic.AbstractBackoff
- All Implemented Interfaces:
BackoffManager
- Direct Known Subclasses:
AIMDBackoffManager, ExponentialBackoffManager, LinearBackoffManager
AbstractBackoff is an abstract class that provides a common implementation for managing
backoff behavior in HttpClient connection pool. Subclasses should implement the specific
backoff algorithms by overriding the abstract methods.
This class provides common functionality for maintaining the route-wise backoff and probe timestamps, as well as the cool-down period for each backoff attempt.
It also contains the basic structure of the backOff and probe methods, which use the route-wise timestamps to determine if the backoff or probe should be applied, and then call the specific algorithm implementation for calculating the new pool size.
- Since:
- 5.3
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractBackoff(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPerRoute) Constructs a new ExponentialBackoffManager with the specified connection pool control. -
Method Summary
Modifier and TypeMethodDescriptionvoidReduces the number of maximum allowed connections for the specified route based on the exponential backoff algorithm.protected abstract intgetBackedOffPoolSize(int curr) Calculates the new pool size after applying the exponential backoff algorithm.protected AtomicReference<Double> Returns the backoff factor as an AtomicReference of Double.protected AtomicIntegergetCap()Returns the cap on the maximum number of connections per route as an AtomicInteger.protected org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> Returns the connection pool control for managing the maximum number of connections per route.protected AtomicReference<org.apache.hc.core5.util.TimeValue> Returns the cool down period between backoff and probe operations as an AtomicReference of TimeValue.Returns the map containing the last backoff times for each HttpRoute.Returns the map containing the last probe times for each HttpRoute.longgetLastUpdate(Map<HttpRoute, Long> updates, HttpRoute route) Retrieves the last update timestamp for the specified route from the provided updates map.protected AtomicIntegerReturns the time interval between backoff and probe operations as an AtomicInteger.voidIncreases the number of maximum allowed connections for the specified route after a successful connection has been established.voidsetCoolDown(org.apache.hc.core5.util.TimeValue coolDown) Sets the cool-down time value for adjustments in pool sizes for a given host.voidsetPerHostConnectionCap(int cap) Sets the per-host connection cap.
-
Constructor Details
-
AbstractBackoff
Constructs a new ExponentialBackoffManager with the specified connection pool control.- Parameters:
connPerRoute- the connection pool control to be used for managing connections- Throws:
IllegalArgumentException- if connPerRoute is null
-
-
Method Details
-
backOff
Reduces the number of maximum allowed connections for the specified route based on the exponential backoff algorithm.- Specified by:
backOffin interfaceBackoffManager- Parameters:
route- the HttpRoute for which the backoff needs to be applied
-
getBackedOffPoolSize
protected abstract int getBackedOffPoolSize(int curr) Calculates the new pool size after applying the exponential backoff algorithm. The new pool size is calculated using the formula: floor(curr / (1 + growthRate) ^ t), where curr is the current pool size, growthRate is the exponential growth rate, and t is the time interval.- Parameters:
curr- the current pool size- Returns:
- the new pool size after applying the backoff
-
probe
Increases the number of maximum allowed connections for the specified route after a successful connection has been established.- Specified by:
probein interfaceBackoffManager- Parameters:
route- the HttpRoute for which the probe needs to be applied
-
getLastUpdate
Retrieves the last update timestamp for the specified route from the provided updates map.- Parameters:
updates- the map containing update timestamps for HttpRoutesroute- the HttpRoute for which the last update timestamp is needed- Returns:
- the last update timestamp for the specified route or 0L if not present in the map
-
setPerHostConnectionCap
public void setPerHostConnectionCap(int cap) Sets the per-host connection cap.- Parameters:
cap- the per-host connection cap to be set- Throws:
IllegalArgumentException- if the cap is not positive
-
setCoolDown
public void setCoolDown(org.apache.hc.core5.util.TimeValue coolDown) Sets the cool-down time value for adjustments in pool sizes for a given host. This time value allows enough time for the adjustments to take effect before further adjustments are made. The cool-down time value must be positive and not null.- Parameters:
coolDown- the TimeValue representing the cool-down period between adjustments- Throws:
IllegalArgumentException- if the provided cool-down time value is null or non-positive
-
getConnPerRoute
Returns the connection pool control for managing the maximum number of connections per route.- Returns:
- the connection pool control instance
-
getLastRouteProbes
-
getLastRouteBackoffs
-
getCoolDown
Returns the cool down period between backoff and probe operations as an AtomicReference of TimeValue.- Returns:
- the AtomicReference containing the cool down period
-
getBackoffFactor
Returns the backoff factor as an AtomicReference of Double.- Returns:
- the AtomicReference containing the backoff factor
-
getCap
Returns the cap on the maximum number of connections per route as an AtomicInteger.- Returns:
- the AtomicInteger containing the cap value
-
getTimeInterval
Returns the time interval between backoff and probe operations as an AtomicInteger.- Returns:
- the AtomicInteger containing the time interval
-