public abstract class AbstractBackoff extends Object implements BackoffManager
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.
Constructor and Description |
---|
AbstractBackoff(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPerRoute)
Constructs a new ExponentialBackoffManager with the specified connection pool control.
|
Modifier and Type | Method and Description |
---|---|
void |
backOff(HttpRoute route)
Reduces the number of maximum allowed connections for the specified route based on the exponential backoff algorithm.
|
protected abstract int |
getBackedOffPoolSize(int curr)
Calculates the new pool size after applying the exponential backoff algorithm.
|
protected AtomicReference<Double> |
getBackoffFactor()
Returns the backoff factor as an AtomicReference of Double.
|
protected AtomicInteger |
getCap()
Returns the cap on the maximum number of connections per route as an AtomicInteger.
|
protected org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> |
getConnPerRoute()
Returns the connection pool control for managing the maximum number of connections per route.
|
protected AtomicReference<org.apache.hc.core5.util.TimeValue> |
getCoolDown()
Returns the cool down period between backoff and probe operations as an AtomicReference of TimeValue.
|
protected Map<HttpRoute,Instant> |
getLastRouteBackoffs()
Returns the map containing the last backoff times for each HttpRoute.
|
protected Map<HttpRoute,Instant> |
getLastRouteProbes()
Returns the map containing the last probe times for each HttpRoute.
|
long |
getLastUpdate(Map<HttpRoute,Long> updates,
HttpRoute route)
Retrieves the last update timestamp for the specified route from the provided updates map.
|
protected AtomicInteger |
getTimeInterval()
Returns the time interval between backoff and probe operations as an AtomicInteger.
|
void |
probe(HttpRoute route)
Increases the number of maximum allowed connections for the specified route after a successful connection has been established.
|
void |
setCoolDown(org.apache.hc.core5.util.TimeValue coolDown)
Sets the cool-down time value for adjustments in pool sizes for a given host.
|
void |
setPerHostConnectionCap(int cap)
Sets the per-host connection cap.
|
public AbstractBackoff(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPerRoute)
connPerRoute
- the connection pool control to be used for managing connectionsIllegalArgumentException
- if connPerRoute is nullpublic void backOff(HttpRoute route)
backOff
in interface BackoffManager
route
- the HttpRoute for which the backoff needs to be appliedprotected abstract int getBackedOffPoolSize(int curr)
curr
- the current pool sizepublic void probe(HttpRoute route)
probe
in interface BackoffManager
route
- the HttpRoute for which the probe needs to be appliedpublic long getLastUpdate(Map<HttpRoute,Long> updates, HttpRoute route)
updates
- the map containing update timestamps for HttpRoutesroute
- the HttpRoute for which the last update timestamp is neededpublic void setPerHostConnectionCap(int cap)
cap
- the per-host connection cap to be setIllegalArgumentException
- if the cap is not positivepublic void setCoolDown(org.apache.hc.core5.util.TimeValue coolDown)
coolDown
- the TimeValue representing the cool-down period between adjustmentsIllegalArgumentException
- if the provided cool-down time value is null or non-positiveprotected org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> getConnPerRoute()
protected Map<HttpRoute,Instant> getLastRouteProbes()
protected Map<HttpRoute,Instant> getLastRouteBackoffs()
protected AtomicReference<org.apache.hc.core5.util.TimeValue> getCoolDown()
protected AtomicReference<Double> getBackoffFactor()
protected AtomicInteger getCap()
protected AtomicInteger getTimeInterval()
Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.