Class RouteSegmentedConnPool<R,C extends ModalCloseable>

java.lang.Object
org.apache.hc.core5.pool.RouteSegmentedConnPool<R,C>
Type Parameters:
R - route key type
C - connection type (must be ModalCloseable)
All Implemented Interfaces:
Closeable, AutoCloseable, ModalCloseable, ConnPool<R,C>, ConnPoolControl<R>, ConnPoolStats<R>, ManagedConnPool<R,C>

@Contract(threading=SAFE_CONDITIONAL) @Experimental public final class RouteSegmentedConnPool<R,C extends ModalCloseable> extends Object implements ManagedConnPool<R,C>
Lock-free, route-segmented connection pool with tiny, conditional round-robin assistance.

Per-route state is kept in independent segments. Disposal of connections is offloaded to a bounded executor so slow closes do not block threads leasing on other routes. A minimal round-robin drainer is engaged only when there are many pending routes and there is global headroom; it never scans all routes.

Since:
5.4
See Also:
  • Constructor Details

  • Method Details

    • lease

      public Future<PoolEntry<R,C>> lease(R route, Object state, Timeout requestTimeout, FutureCallback<PoolEntry<R,C>> callback)
      Description copied from interface: ConnPool
      Attempts to lease a connection for the given route and with the given state from the pool.

      Please note the connection request can get automatically cancelled by the pool in case of a request timeout.

      Specified by:
      lease in interface ConnPool<R,C extends ModalCloseable>
      Parameters:
      route - route of the connection.
      state - arbitrary object that represents a particular state (usually a security principal or a unique token identifying the user whose credentials have been used while establishing the connection). May be null.
      requestTimeout - request timeout. In case of a timeout the request can get automatically cancelled by the pool.
      callback - operation completion callback.
      Returns:
      future for a leased pool entry.
    • release

      public void release(PoolEntry<R,C> entry, boolean reusable)
      Description copied from interface: ConnPool
      Releases the pool entry back to the pool.
      Specified by:
      release in interface ConnPool<R,C extends ModalCloseable>
      Parameters:
      entry - pool entry leased from the pool
      reusable - flag indicating whether or not the released connection is in a consistent state and is safe for further use.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • close

      public void close(CloseMode closeMode)
      Description copied from interface: ModalCloseable
      Closes this process or endpoint and releases any system resources associated with it. If the endpoint or the process is already closed then invoking this method has no effect.
      Specified by:
      close in interface ModalCloseable
      Parameters:
      closeMode - How to close the receiver.
    • closeIdle

      public void closeIdle(TimeValue idleTime)
      Specified by:
      closeIdle in interface ConnPoolControl<R>
    • closeExpired

      public void closeExpired()
      Specified by:
      closeExpired in interface ConnPoolControl<R>
    • getRoutes

      public Set<R> getRoutes()
      Specified by:
      getRoutes in interface ConnPoolControl<R>
    • getMaxTotal

      public int getMaxTotal()
      Specified by:
      getMaxTotal in interface ConnPoolControl<R>
    • setMaxTotal

      public void setMaxTotal(int max)
      Specified by:
      setMaxTotal in interface ConnPoolControl<R>
    • getDefaultMaxPerRoute

      public int getDefaultMaxPerRoute()
      Specified by:
      getDefaultMaxPerRoute in interface ConnPoolControl<R>
    • setDefaultMaxPerRoute

      public void setDefaultMaxPerRoute(int max)
      Specified by:
      setDefaultMaxPerRoute in interface ConnPoolControl<R>
    • getMaxPerRoute

      public int getMaxPerRoute(R route)
      Specified by:
      getMaxPerRoute in interface ConnPoolControl<R>
    • setMaxPerRoute

      public void setMaxPerRoute(R route, int max)
      Specified by:
      setMaxPerRoute in interface ConnPoolControl<R>
    • getTotalStats

      public PoolStats getTotalStats()
      Specified by:
      getTotalStats in interface ConnPoolStats<R>
    • getStats

      public PoolStats getStats(R route)
      Specified by:
      getStats in interface ConnPoolStats<R>