org.apache.hc.client5.http.impl.classic

## Class LinearBackoffManager

- java.lang.Object
- - org.apache.hc.client5.http.impl.classic.AbstractBackoff
  - - org.apache.hc.client5.http.impl.classic.LinearBackoffManager

- All Implemented Interfaces:
    BackoffManager

      @Contract(threading=SAFE)
      public class LinearBackoffManager
      extends AbstractBackoff

  An implementation of `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

  Since:
    5.3
  See Also:
    `BackoffManager`, `ConnPoolControl`, `PoolingHttpClientConnectionManager`

- - ### Constructor Summary

    Constructors
    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.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class org.apache.hc.client5.http.impl.classic.AbstractBackoff

      `getBackoffFactor, getCap, getConnPerRoute, getCoolDown, getLastRouteBackoffs, getLastRouteProbes, getLastUpdate, getTimeInterval, setCoolDown, setPerHostConnectionCap`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LinearBackoffManager

          public LinearBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPoolControl)

      Constructs a new LinearBackoffManager with the specified connection pool control. The backoff increment is set to `1` by default.
      Parameters:
        `connPoolControl` - the connection pool control to be used by this LinearBackoffManager

    - #### LinearBackoffManager

          public LinearBackoffManager(org.apache.hc.core5.pool.ConnPoolControl<HttpRoute> connPoolControl,
                                      int increment)

      Constructs a new LinearBackoffManager with the specified connection pool control and backoff increment.
      Parameters:
        `connPoolControl` - the connection pool control to be used by this LinearBackoffManager
        `increment` - the backoff increment to be used when adjusting connection pool sizes
      Throws:
        `IllegalArgumentException` - if connPoolControl is `null` or increment is not positive

  - ### Method Detail

    - #### backOff

          public void backOff(HttpRoute route)

      Description copied from class: `AbstractBackoff`
      Reduces the number of maximum allowed connections for the specified route based on the exponential backoff algorithm.
      Specified by:
        `backOff` in interface `BackoffManager`
      Overrides:
        `backOff` in class `AbstractBackoff`
      Parameters:
        `route` - the HttpRoute for which the backoff needs to be applied

    - #### probe

          public void probe(HttpRoute route)

      Adjusts the maximum number of connections for the specified route, decreasing it by the increment value. The method ensures that adjustments only happen after the cool-down period has passed since the last adjustment.
      Specified by:
        `probe` in interface `BackoffManager`
      Overrides:
        `probe` in class `AbstractBackoff`
      Parameters:
        `route` - the HttpRoute for which the maximum number of connections will be decreased

    - #### getBackedOffPoolSize

          protected int getBackedOffPoolSize(int curr)

      Returns the new pool size after applying the linear backoff algorithm. The new pool size is calculated by adding the increment value to the current pool size.
      Specified by:
        `getBackedOffPoolSize` in class `AbstractBackoff`
      Parameters:
        `curr` - the current pool size
      Returns:
        the new pool size after applying the linear backoff

    - #### setBackoffFactor

          public void setBackoffFactor(double d)

      This method is not used in LinearBackoffManager's implementation. It is provided to fulfill the interface requirement and for potential future extensions or modifications of LinearBackoffManager that may use the backoff factor.
      Parameters:
        `d` - the backoff factor, not used in the current implementation

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.