Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.http.impl.nio.conn
Class PoolingNHttpClientConnectionManager

    java.lang.Object
      org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager

All Implemented Interfaces:
  NHttpClientConnectionManager, org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>

    @Contract(threading=SAFE)
    public class PoolingNHttpClientConnectionManager

extends Object
implements NHttpClientConnectionManager, org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>

`PoolingNHttpClientConnectionManager` maintains a pool of `NHttpClientConnection`s and is able to service connection requests from multiple execution threads. Connections are pooled on a per route basis. A request for a route which already the manager has persistent connections for available in the pool will be services by leasing a connection from the pool rather than creating a brand new connection.

`PoolingNHttpClientConnectionManager` maintains a maximum limit of connection on a per route basis and in total. Per default this implementation will create no more than than 2 concurrent connections per given route and no more 20 connections in total. For many real-world applications these limits may prove too constraining, especially if they use HTTP as a transport protocol for their services. Connection limits, however, can be adjusted using `ConnPoolControl` methods.

Since:
  4.0

Constructor Summary
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.conn.DnsResolver dnsResolver)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.conn.DnsResolver dnsResolver)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.conn.SchemePortResolver schemePortResolver, org.apache.http.conn.DnsResolver dnsResolver, long timeToLive, TimeUnit timeUnit)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry, org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver, long timeToLive, TimeUnit timeUnit)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory, org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)`
`PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor, org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)`

Method Summary
`void` | `closeExpiredConnections()` Closes all expired connections in the pool.
`void` | `closeIdleConnections(long idleTimeout, TimeUnit timeUnit)` Closes idle connections in the pool.
`void` | `execute(org.apache.http.nio.reactor.IOEventDispatch eventDispatch)` Starts the underlying I/O reactor and initiates the dispatch of I/O event notifications to the given `IOEventDispatch`.
`protected void` | `finalize()`
`org.apache.http.config.ConnectionConfig` | `getConnectionConfig(org.apache.http.HttpHost host)`
`org.apache.http.config.ConnectionConfig` | `getDefaultConnectionConfig()`
`int` | `getDefaultMaxPerRoute()`
`int` | `getMaxPerRoute(org.apache.http.conn.routing.HttpRoute route)`
`int` | `getMaxTotal()`
`Set<org.apache.http.conn.routing.HttpRoute>` | `getRoutes()`
`org.apache.http.pool.PoolStats` | `getStats(org.apache.http.conn.routing.HttpRoute route)`
`org.apache.http.pool.PoolStats` | `getTotalStats()`
`boolean` | `isRouteComplete(org.apache.http.nio.NHttpClientConnection managedConn)` Determines if the given connection has been fully established and marked as route complete.
`void` | `releaseConnection(org.apache.http.nio.NHttpClientConnection managedConn, Object state, long keepalive, TimeUnit timeUnit)` Releases the connection back to the manager making it potentially re-usable by other consumers.
`Future<org.apache.http.nio.NHttpClientConnection>` | `requestConnection(org.apache.http.conn.routing.HttpRoute route, Object state, long connectTimeout, long leaseTimeout, TimeUnit timeUnit, org.apache.http.concurrent.FutureCallback<org.apache.http.nio.NHttpClientConnection> callback)` Returns a `Future` for a `NHttpClientConnection`.
`void` | `routeComplete(org.apache.http.nio.NHttpClientConnection managedConn, org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)` Marks the connection as fully established with all its intermediate hops completed.
`void` | `setConnectionConfig(org.apache.http.HttpHost host, org.apache.http.config.ConnectionConfig connectionConfig)`
`void` | `setDefaultConnectionConfig(org.apache.http.config.ConnectionConfig defaultConnectionConfig)`
`void` | `setDefaultMaxPerRoute(int max)`
`void` | `setMaxPerRoute(org.apache.http.conn.routing.HttpRoute route, int max)`
`void` | `setMaxTotal(int max)`
`void` | `shutdown()` Shuts down this connection manager and releases allocated resources.
`void` | `shutdown(long waitMs)`
`void` | `startRoute(org.apache.http.nio.NHttpClientConnection managedConn, org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)` Starts the process of connection initialization.
`void` | `upgrade(org.apache.http.nio.NHttpClientConnection managedConn, org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)` Upgrades the underlying connection I/O session to TLS/SSL (or another layering protocol) after having executed `CONNECT` method to all intermediate proxy hops.
`void` | `validatePendingRequests()`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.conn.DnsResolver dnsResolver)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
                                               org.apache.http.conn.DnsResolver dnsResolver)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
                                               org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
                                               org.apache.http.conn.SchemePortResolver schemePortResolver,
                                               org.apache.http.conn.DnsResolver dnsResolver,
                                               long timeToLive,
                                               TimeUnit timeUnit)

### PoolingNHttpClientConnectionManager

    public PoolingNHttpClientConnectionManager(org.apache.http.nio.reactor.ConnectingIOReactor ioReactor,
                                               NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory,
                                               org.apache.http.config.Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry,
                                               org.apache.http.nio.pool.SocketAddressResolver<org.apache.http.conn.routing.HttpRoute> socketAddressResolver,
                                               long timeToLive,
                                               TimeUnit timeUnit)

Method Detail

### finalize

    protected void finalize()
                     throws Throwable

  Overrides:
    `finalize` in class `Object`
  Throws:
    `Throwable`

### execute

    public void execute(org.apache.http.nio.reactor.IOEventDispatch eventDispatch)
                 throws IOException

  Description copied from interface: `NHttpClientConnectionManager`
  Starts the underlying I/O reactor and initiates the dispatch of I/O event notifications to the given `IOEventDispatch`.

  Specified by:
    `execute` in interface `NHttpClientConnectionManager`
  Throws:
    `IOException`

### shutdown

    public void shutdown(long waitMs)
                  throws IOException

  Throws:
    `IOException`

### shutdown

    public void shutdown()
                  throws IOException

  Description copied from interface: `NHttpClientConnectionManager`
  Shuts down this connection manager and releases allocated resources. This includes closing all connections, whether they are currently used or not.

  Specified by:
    `shutdown` in interface `NHttpClientConnectionManager`
  Throws:
    `IOException`

### requestConnection

    public Future<org.apache.http.nio.NHttpClientConnection> requestConnection(org.apache.http.conn.routing.HttpRoute route,
                                                                               Object state,
                                                                               long connectTimeout,
                                                                               long leaseTimeout,
                                                                               TimeUnit timeUnit,
                                                                               org.apache.http.concurrent.FutureCallback<org.apache.http.nio.NHttpClientConnection> callback)

  Description copied from interface: `NHttpClientConnectionManager`
  Returns a `Future` for a `NHttpClientConnection`.

  Please note that the consumer of that connection is responsible for fully establishing the route the to the connection target by calling `startRoute` in order to start the process of connection initialization, optionally calling `upgrade` method to upgrade the connection after having executed `CONNECT` method to all intermediate proxy hops and and finally calling `routeComplete` to mark the route as fully completed.

  Specified by:
    `requestConnection` in interface `NHttpClientConnectionManager`
  Parameters:
    `route` - HTTP route of the requested connection.
    `state` - expected state of the connection or `null` if the connection is not expected to carry any state.
    `connectTimeout` - connect timeout.
    `leaseTimeout` - connection request timeout.
    `timeUnit` - time unit of the previous two timeout values.
    `callback` - future callback.

### releaseConnection

    public void releaseConnection(org.apache.http.nio.NHttpClientConnection managedConn,
                                  Object state,
                                  long keepalive,
                                  TimeUnit timeUnit)

  Description copied from interface: `NHttpClientConnectionManager`
  Releases the connection back to the manager making it potentially re-usable by other consumers. Optionally, the maximum period of how long the manager should keep the connection alive can be defined using `validDuration` and `timeUnit` parameters.

  Specified by:
    `releaseConnection` in interface `NHttpClientConnectionManager`
  Parameters:
    `managedConn` - the managed connection to release.
    `keepalive` - the duration of time this connection is valid for reuse.
    `timeUnit` - the time unit.
  See Also:
    `NHttpClientConnectionManager.closeExpiredConnections()`

### startRoute

    public void startRoute(org.apache.http.nio.NHttpClientConnection managedConn,
                           org.apache.http.conn.routing.HttpRoute route,
                           org.apache.http.protocol.HttpContext context)
                    throws IOException

  Description copied from interface: `NHttpClientConnectionManager`
  Starts the process of connection initialization. Connection route may consist of several intermediate hops and may require a protocol upgrade. Once the route is fully established the `routeComplete` method must be called.

  Specified by:
    `startRoute` in interface `NHttpClientConnectionManager`
  Parameters:
    `managedConn` - the managed connection to initialize.
    `route` - the connection route.
    `context` - the context
  Throws:
    `IOException`

### upgrade

    public void upgrade(org.apache.http.nio.NHttpClientConnection managedConn,
                        org.apache.http.conn.routing.HttpRoute route,
                        org.apache.http.protocol.HttpContext context)
                 throws IOException

  Description copied from interface: `NHttpClientConnectionManager`
  Upgrades the underlying connection I/O session to TLS/SSL (or another layering protocol) after having executed `CONNECT` method to all intermediate proxy hops.

  Specified by:
    `upgrade` in interface `NHttpClientConnectionManager`
  Parameters:
    `managedConn` - the managed connection to upgrade.
    `route` - the connection route.
    `context` - the context
  Throws:
    `IOException`

### routeComplete

    public void routeComplete(org.apache.http.nio.NHttpClientConnection managedConn,
                              org.apache.http.conn.routing.HttpRoute route,
                              org.apache.http.protocol.HttpContext context)

  Description copied from interface: `NHttpClientConnectionManager`
  Marks the connection as fully established with all its intermediate hops completed.

  Specified by:
    `routeComplete` in interface `NHttpClientConnectionManager`
  Parameters:
    `managedConn` - the managed connection to mark as route complete.
    `route` - the connection route.
    `context` - the context

### isRouteComplete

    public boolean isRouteComplete(org.apache.http.nio.NHttpClientConnection managedConn)

  Description copied from interface: `NHttpClientConnectionManager`
  Determines if the given connection has been fully established and marked as route complete.

  Specified by:
    `isRouteComplete` in interface `NHttpClientConnectionManager`
  Parameters:
    `managedConn` - the managed connection.

### closeIdleConnections

    public void closeIdleConnections(long idleTimeout,
                                     TimeUnit timeUnit)

  Description copied from interface: `NHttpClientConnectionManager`
  Closes idle connections in the pool.

  Open connections in the pool that have not been used for the timespan given by the argument will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision All expired connections will also be closed.

  Specified by:
    `closeIdleConnections` in interface `NHttpClientConnectionManager`
  Parameters:
    `idleTimeout` - the idle time of connections to be closed
    `timeUnit` - the unit for the `idletime`
  See Also:
    `NHttpClientConnectionManager.closeExpiredConnections()`

### closeExpiredConnections

    public void closeExpiredConnections()

  Description copied from interface: `NHttpClientConnectionManager`
  Closes all expired connections in the pool.

  Open connections in the pool that have not been used for the timespan defined when the connection was released will be closed. Currently allocated connections are not subject to this method. Times will be checked with milliseconds precision.

  Specified by:
    `closeExpiredConnections` in interface `NHttpClientConnectionManager`

### validatePendingRequests

    public void validatePendingRequests()

### getMaxTotal

    public int getMaxTotal()

  Specified by:
    `getMaxTotal` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### setMaxTotal

    public void setMaxTotal(int max)

  Specified by:
    `setMaxTotal` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### getDefaultMaxPerRoute

    public int getDefaultMaxPerRoute()

  Specified by:
    `getDefaultMaxPerRoute` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### setDefaultMaxPerRoute

    public void setDefaultMaxPerRoute(int max)

  Specified by:
    `setDefaultMaxPerRoute` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### getMaxPerRoute

    public int getMaxPerRoute(org.apache.http.conn.routing.HttpRoute route)

  Specified by:
    `getMaxPerRoute` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### setMaxPerRoute

    public void setMaxPerRoute(org.apache.http.conn.routing.HttpRoute route,
                               int max)

  Specified by:
    `setMaxPerRoute` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### getTotalStats

    public org.apache.http.pool.PoolStats getTotalStats()

  Specified by:
    `getTotalStats` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### getStats

    public org.apache.http.pool.PoolStats getStats(org.apache.http.conn.routing.HttpRoute route)

  Specified by:
    `getStats` in interface `org.apache.http.pool.ConnPoolControl<org.apache.http.conn.routing.HttpRoute>`

### getRoutes

    public Set<org.apache.http.conn.routing.HttpRoute> getRoutes()

  Since:
    4.1

### getDefaultConnectionConfig

    public org.apache.http.config.ConnectionConfig getDefaultConnectionConfig()

### setDefaultConnectionConfig

    public void setDefaultConnectionConfig(org.apache.http.config.ConnectionConfig defaultConnectionConfig)

### getConnectionConfig

    public org.apache.http.config.ConnectionConfig getConnectionConfig(org.apache.http.HttpHost host)

### setConnectionConfig

    public void setConnectionConfig(org.apache.http.HttpHost host,
                                    org.apache.http.config.ConnectionConfig connectionConfig)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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