@Contract(threading=SAFE) public class LinearBackoffManager extends AbstractBackoff
BackoffManager
that uses a linear backoff strategy to adjust the maximum number
of connections per route in an PoolingHttpClientConnectionManager
.
This class is designed to be thread-safe and can be used in multi-threaded environments.
The linear backoff strategy increases or decreases the maximum number of connections per route by a fixed increment when backing off or probing, respectively. The adjustments are made based on a cool-down period, during which no further adjustments will be made.
The LinearBackoffManager
is intended to be used with a PoolingHttpClientConnectionManager
,
which provides the ConnPoolControl
interface. This class interacts with the PoolingHttpClientConnectionManager
to adjust the maximum number of connections per route.
Example usage:
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); LinearBackoffManager backoffManager = new LinearBackoffManager(connectionManager, 1); // Use the backoffManager with the connectionManager in your application
BackoffManager
,
ConnPoolControl
,
PoolingHttpClientConnectionManager
Constructor and Description |
---|
LinearBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPoolControl)
Constructs a new LinearBackoffManager with the specified connection pool control.
|
LinearBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPoolControl,
int increment)
Constructs a new LinearBackoffManager with the specified connection pool control and backoff increment.
|
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 int |
getBackedOffPoolSize(int curr)
Returns the new pool size after applying the linear backoff algorithm.
|
void |
probe(HttpRoute route)
Adjusts the maximum number of connections for the specified route, decreasing it by the increment value.
|
void |
setBackoffFactor(double d)
This method is not used in LinearBackoffManager's implementation.
|
getBackoffFactor, getCap, getConnPerRoute, getCoolDown, getLastRouteBackoffs, getLastRouteProbes, getLastUpdate, getTimeInterval, setCoolDown, setPerHostConnectionCap
public LinearBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPoolControl)
1
by default.connPoolControl
- the connection pool control to be used by this LinearBackoffManagerpublic LinearBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPoolControl, int increment)
connPoolControl
- the connection pool control to be used by this LinearBackoffManagerincrement
- the backoff increment to be used when adjusting connection pool sizesIllegalArgumentException
- if connPoolControl is null
or increment is not positivepublic void backOff(HttpRoute route)
AbstractBackoff
backOff
in interface BackoffManager
backOff
in class AbstractBackoff
route
- the HttpRoute for which the backoff needs to be appliedpublic void probe(HttpRoute route)
probe
in interface BackoffManager
probe
in class AbstractBackoff
route
- the HttpRoute for which the maximum number of connections will be decreasedprotected int getBackedOffPoolSize(int curr)
getBackedOffPoolSize
in class AbstractBackoff
curr
- the current pool sizepublic void setBackoffFactor(double d)
d
- the backoff factor, not used in the current implementationCopyright © 1999–2021 The Apache Software Foundation. All rights reserved.