Top Description Methods
org.apache.http.conn

public Interface HttpClientConnectionManager

Known Direct Implementers
org.apache.http.impl.conn.BasicHttpClientConnectionManager, org.apache.http.impl.conn.PoolingHttpClientConnectionManager
Imports
java.io.IOException, java.util.concurrent.TimeUnit, org.apache.http.HttpClientConnection, org.apache.http.conn.routing.HttpRoute, org.apache.http.protocol.HttpContext

Represents a manager of persistent client connections.

The purpose of an HTTP connection manager is to serve as a factory for new HTTP connections, manage persistent connections and synchronize access to persistent connections making sure that only one thread of execution can have access to a connection at a time.

Implementations of this interface must be thread-safe. Access to shared data must be synchronized as methods of this interface may be executed from multiple threads.

Since
4.3

Method Summary

Modifier and TypeMethod and Description
public void
closeExpiredConnections()

Closes all expired connections in the pool.

public void
closeIdleConnections(long
the idle time of connections to be closed
idletime
,
TimeUnit
the unit for the idletime
timeUnit
)

Closes idle connections in the pool.

public void
connect(HttpClientConnection
the managed connection.
conn
,
HttpRoute
the route of the connection.
route
,
int
connect timeout in milliseconds.
connectTimeout
,
HttpContext
the actual HTTP context.
context
)

Connects the underlying connection socket to the connection target in case of a direct route or to the first proxy hop in case of a route via a proxy (or multiple proxies).

public void
releaseConnection(HttpClientConnection
the managed connection to release.
conn
,
Object newState, long
the duration of time this connection is valid for reuse.
validDuration
,
TimeUnit
the time unit.
timeUnit
)

Releases the connection back to the manager making it potentially re-usable by other consumers.

public ConnectionRequest
requestConnection(HttpRoute
HTTP route of the requested connection.
route
,
Object
expected state of the connection or null if the connection is not expected to carry any state.
state
)

Returns a new ConnectionRequest, from which a HttpClientConnection can be obtained or the request can be aborted.

public void
routeComplete(HttpClientConnection
the managed connection.
conn
,
HttpRoute
the route of the connection.
route
,
HttpContext
the actual HTTP context.
context
)

Marks the connection as fully established with all its intermediate hops completed.

public void
shutdown()

Shuts down this connection manager and releases allocated resources.

public void
upgrade(HttpClientConnection
the managed connection.
conn
,
HttpRoute
the route of the connection.
route
,
HttpContext
the actual HTTP context.
context
)

Upgrades the underlying connection socket to TLS/SSL (or another layering protocol) after having executed CONNECT method to all intermediate proxy hops

Method Detail

closeExpiredConnectionsback to summary
public void closeExpiredConnections()

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.

closeIdleConnectionsback to summary
public void closeIdleConnections(long idletime, TimeUnit timeUnit)

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.

Parameters
idletime:long

the idle time of connections to be closed

timeUnit:TimeUnit

the unit for the idletime

See Also
closeExpiredConnections()
connectback to summary
public void connect(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException

Connects the underlying connection socket to the connection target in case of a direct route or to the first proxy hop in case of a route via a proxy (or multiple proxies).

Parameters
conn:HttpClientConnection

the managed connection.

route:HttpRoute

the route of the connection.

connectTimeout:int

connect timeout in milliseconds.

context:HttpContext

the actual HTTP context.

releaseConnectionback to summary
public void releaseConnection(HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit)

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.

Parameters
conn:HttpClientConnection

the managed connection to release.

validDuration:long

the duration of time this connection is valid for reuse.

timeUnit:TimeUnit

the time unit.

See Also
closeExpiredConnections()
requestConnectionback to summary
public ConnectionRequest requestConnection(HttpRoute route, Object state)

Returns a new ConnectionRequest, from which a HttpClientConnection can be obtained or the request can be aborted.

Please note that newly allocated connections can be returned in the closed state. The consumer of that connection is responsible for fully establishing the route the to the connection target by calling connect in order to connect directly to the target or to the first proxy hop, 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.

Parameters
route:HttpRoute

HTTP route of the requested connection.

state:Object

expected state of the connection or null if the connection is not expected to carry any state.

routeCompleteback to summary
public void routeComplete(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException

Marks the connection as fully established with all its intermediate hops completed.

Parameters
conn:HttpClientConnection

the managed connection.

route:HttpRoute

the route of the connection.

context:HttpContext

the actual HTTP context.

shutdownback to summary
public void shutdown()

Shuts down this connection manager and releases allocated resources. This includes closing all connections, whether they are currently used or not.

upgradeback to summary
public void upgrade(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException

Upgrades the underlying connection socket to TLS/SSL (or another layering protocol) after having executed CONNECT method to all intermediate proxy hops

Parameters
conn:HttpClientConnection

the managed connection.

route:HttpRoute

the route of the connection.

context:HttpContext

the actual HTTP context.