Top Description Fields Constructors Methods
org.apache.hc.client5.http.impl.classic

public abstract Class AbstractBackoff

extends Object
implements BackoffManager
Class Inheritance
All Implemented Interfaces
org.apache.hc.client5.http.classic.BackoffManager
Known Direct Subclasses
org.apache.hc.client5.http.impl.classic.AIMDBackoffManager, org.apache.hc.client5.http.impl.classic.ExponentialBackoffManager, org.apache.hc.client5.http.impl.classic.LinearBackoffManager
Imports
org.apache.hc.client5.http.HttpRoute, org.apache.hc.client5.http.classic.BackoffManager, org.apache.hc.core5.pool.ConnPoolControl, org.apache.hc.core5.util.Args, .TimeValue, org.slf4j.Logger, .LoggerFactory, java.time.Instant, java.time.temporal.ChronoUnit, java.util.Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger, .AtomicReference

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

Field Summary

Modifier and TypeField and Description
private final AtomicReference<Double>
backoffFactor

The growth rate used in the exponential backoff algorithm.

private final AtomicInteger
cap

The per-host connection cap, as defined in RFC 2616 sec 8.1.4.

private final ConnPoolControl<HttpRoute>
connPerRoute

Connection pool control responsible for managing the maximum number of connections per HTTP route.

private final AtomicReference<TimeValue>
coolDown

The cool-down period after which the backoff or probe process can be performed again.

private final Map<HttpRoute, Instant>
lastRouteBackoffs

A map that stores the last backoff timestamp for each HTTP route.

private final Map<HttpRoute, Instant>
lastRouteProbes

A map that stores the last probe timestamp for each HTTP route.

private static final Logger
private final AtomicInteger
timeInterval

The number of time intervals used in the exponential backoff algorithm.

Constructor Summary

AccessConstructor and Description
public
AbstractBackoff(final ConnPoolControl<HttpRoute>
the connection pool control to be used for managing connections
connPerRoute
)

Constructs a new ExponentialBackoffManager with the specified connection pool control.

Method Summary

Modifier and TypeMethod and Description
public void
backOff(final HttpRoute
the HttpRoute for which the backoff needs to be applied
route
)

Implements org.apache.hc.client5.http.classic.BackoffManager.backOff.

Reduces the number of maximum allowed connections for the specified route based on the exponential backoff algorithm.
protected abstract int

Returns:

the new pool size after applying the backoff
getBackedOffPoolSize
(int
the current pool size
curr
)

Calculates the new pool size after applying the exponential backoff algorithm.

protected AtomicReference<Double>

Returns:

the AtomicReference containing the backoff factor
getBackoffFactor
()

Returns the backoff factor as an AtomicReference of Double.

protected AtomicInteger

Returns:

the AtomicInteger containing the cap value
getCap
()

Returns the cap on the maximum number of connections per route as an AtomicInteger.

protected ConnPoolControl<HttpRoute>

Returns:

the connection pool control instance
getConnPerRoute
()

Returns the connection pool control for managing the maximum number of connections per route.

protected AtomicReference<TimeValue>

Returns:

the AtomicReference containing the cool down period
getCoolDown
()

Returns the cool down period between backoff and probe operations as an AtomicReference of TimeValue.

protected Map<HttpRoute, Instant>

Returns:

the map of HttpRoute to Instant representing the last backoff times
getLastRouteBackoffs
()

Returns the map containing the last backoff times for each HttpRoute.

protected Map<HttpRoute, Instant>

Returns:

the map of HttpRoute to Instant representing the last probe times
getLastRouteProbes
()

Returns the map containing the last probe times for each HttpRoute.

public long

Returns:

the last update timestamp for the specified route or 0L if not present in the map
getLastUpdate
(final Map<HttpRoute, Long>
the map containing update timestamps for HttpRoutes
updates
,
final HttpRoute
the HttpRoute for which the last update timestamp is needed
route
)

Retrieves the last update timestamp for the specified route from the provided updates map.

protected AtomicInteger

Returns:

the AtomicInteger containing the time interval
getTimeInterval
()

Returns the time interval between backoff and probe operations as an AtomicInteger.

public void
probe(final HttpRoute
the HttpRoute for which the probe needs to be applied
route
)

Implements org.apache.hc.client5.http.classic.BackoffManager.probe.

Increases the number of maximum allowed connections for the specified route after a successful connection has been established.
pack-priv abstract void
setBackoffFactor(final double
the backoff factor to be set
d
)

Sets the backoff factor for the backoff algorithm.

public void
setCoolDown(final TimeValue
the TimeValue representing the cool-down period between adjustments
coolDown
)

Sets the cool-down time value for adjustments in pool sizes for a given host.

public void
setPerHostConnectionCap(final int
the per-host connection cap to be set
cap
)

Sets the per-host connection cap.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backoffFactorback to summary
private final AtomicReference<Double> backoffFactor

The growth rate used in the exponential backoff algorithm.

capback to summary
private final AtomicInteger cap

The per-host connection cap, as defined in RFC 2616 sec 8.1.4.

connPerRouteback to summary
private final ConnPoolControl<HttpRoute> connPerRoute

Connection pool control responsible for managing the maximum number of connections per HTTP route.

coolDownback to summary
private final AtomicReference<TimeValue> coolDown

The cool-down period after which the backoff or probe process can be performed again.

lastRouteBackoffsback to summary
private final Map<HttpRoute, Instant> lastRouteBackoffs

A map that stores the last backoff timestamp for each HTTP route.

lastRouteProbesback to summary
private final Map<HttpRoute, Instant> lastRouteProbes

A map that stores the last probe timestamp for each HTTP route.

LOGback to summary
private static final Logger LOG
timeIntervalback to summary
private final AtomicInteger timeInterval

The number of time intervals used in the exponential backoff algorithm.

Constructor Detail

AbstractBackoffback to summary
public AbstractBackoff(final ConnPoolControl<HttpRoute> connPerRoute)

Constructs a new ExponentialBackoffManager with the specified connection pool control.

Parameters
connPerRoute:ConnPoolControl<HttpRoute>

the connection pool control to be used for managing connections

Exceptions
IllegalArgumentException:
if connPerRoute is null

Method Detail

backOffback to summary
public void backOff(final HttpRoute route)

Implements org.apache.hc.client5.http.classic.BackoffManager.backOff.

Reduces the number of maximum allowed connections for the specified route based on the exponential backoff algorithm.

Parameters
route:HttpRoute

the HttpRoute for which the backoff needs to be applied

Annotations
@Override
getBackedOffPoolSizeback to summary
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:int

the current pool size

Returns:int

the new pool size after applying the backoff

getBackoffFactorback to summary
protected AtomicReference<Double> getBackoffFactor()

Returns the backoff factor as an AtomicReference of Double.

Returns:AtomicReference<Double>

the AtomicReference containing the backoff factor

getCapback to summary
protected AtomicInteger getCap()

Returns the cap on the maximum number of connections per route as an AtomicInteger.

Returns:AtomicInteger

the AtomicInteger containing the cap value

getConnPerRouteback to summary
protected ConnPoolControl<HttpRoute> getConnPerRoute()

Returns the connection pool control for managing the maximum number of connections per route.

Returns:ConnPoolControl<HttpRoute>

the connection pool control instance

getCoolDownback to summary
protected AtomicReference<TimeValue> getCoolDown()

Returns the cool down period between backoff and probe operations as an AtomicReference of TimeValue.

Returns:AtomicReference<TimeValue>

the AtomicReference containing the cool down period

getLastRouteBackoffsback to summary
protected Map<HttpRoute, Instant> getLastRouteBackoffs()

Returns the map containing the last backoff times for each HttpRoute.

Returns:Map<HttpRoute, Instant>

the map of HttpRoute to Instant representing the last backoff times

getLastRouteProbesback to summary
protected Map<HttpRoute, Instant> getLastRouteProbes()

Returns the map containing the last probe times for each HttpRoute.

Returns:Map<HttpRoute, Instant>

the map of HttpRoute to Instant representing the last probe times

getLastUpdateback to summary
public long getLastUpdate(final Map<HttpRoute, Long> updates, final HttpRoute route)

Retrieves the last update timestamp for the specified route from the provided updates map.

Parameters
updates:Map<HttpRoute, Long>

the map containing update timestamps for HttpRoutes

route:HttpRoute

the HttpRoute for which the last update timestamp is needed

Returns:long

the last update timestamp for the specified route or 0L if not present in the map

getTimeIntervalback to summary
protected AtomicInteger getTimeInterval()

Returns the time interval between backoff and probe operations as an AtomicInteger.

Returns:AtomicInteger

the AtomicInteger containing the time interval

probeback to summary
public void probe(final HttpRoute route)

Implements org.apache.hc.client5.http.classic.BackoffManager.probe.

Increases the number of maximum allowed connections for the specified route after a successful connection has been established.

Parameters
route:HttpRoute

the HttpRoute for which the probe needs to be applied

Annotations
@Override
setBackoffFactorback to summary
pack-priv abstract void setBackoffFactor(final double d)

Sets the backoff factor for the backoff algorithm. The backoff factor should be a value between 0.0 and 1.0. The specific implementation of how the backoff factor is used should be provided by subclasses.

Parameters
d:double

the backoff factor to be set

setCoolDownback to summary
public void setCoolDown(final 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:TimeValue

the TimeValue representing the cool-down period between adjustments

Exceptions
IllegalArgumentException:
if the provided cool-down time value is null or non-positive
setPerHostConnectionCapback to summary
public void setPerHostConnectionCap(final int cap)

Sets the per-host connection cap.

Parameters
cap:int

the per-host connection cap to be set

Exceptions
IllegalArgumentException:
if the cap is not positive