org.apache.http.impl.conn
Class BasicHttpClientConnectionManager

java.lang.Object
  extended by org.apache.http.impl.conn.BasicHttpClientConnectionManager
All Implemented Interfaces:
Closeable, HttpClientConnectionManager

@ThreadSafe
public class BasicHttpClientConnectionManager
extends Object
implements HttpClientConnectionManager, Closeable

A connection manager for a single connection. This connection manager maintains only one active connection. Even though this class is fully thread-safe it ought to be used by one execution thread only, as only one thread a time can lease the connection at a time.

This connection manager will make an effort to reuse the connection for subsequent requests with the same route. It will, however, close the existing connection and open it for the given route, if the route of the persistent connection does not match that of the connection request. If the connection has been already been allocated IllegalStateException is thrown.

This connection manager implementation should be used inside an EJB container instead of PoolingHttpClientConnectionManager.

Since:
4.3

Constructor Summary
BasicHttpClientConnectionManager()
           
BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry)
           
BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory)
           
BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry, HttpConnectionFactory<ManagedHttpClientConnection> connFactory, SchemePortResolver schemePortResolver, DnsResolver dnsResolver)
           
 
Method Summary
 void close()
           
 void closeExpiredConnections()
          Closes all expired connections in the pool.
 void closeIdleConnections(long idletime, TimeUnit tunit)
          Closes idle connections in the pool.
 void connect(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context)
           
protected  void finalize()
           
 org.apache.http.config.ConnectionConfig getConnectionConfig()
           
 org.apache.http.config.SocketConfig getSocketConfig()
           
 void releaseConnection(HttpClientConnection conn, Object state, long keepalive, TimeUnit tunit)
          Releases a connection for use by others.
 ConnectionRequest requestConnection(HttpRoute route, Object state)
          Returns a new ClientConnectionRequest, from which a HttpClientConnection can be obtained or the request can be aborted.
 void routeComplete(HttpClientConnection conn, HttpRoute route, HttpContext context)
           
 void setConnectionConfig(org.apache.http.config.ConnectionConfig connConfig)
           
 void setSocketConfig(org.apache.http.config.SocketConfig socketConfig)
           
 void shutdown()
          Shuts down this connection manager and releases allocated resources.
 void upgrade(HttpClientConnection conn, HttpRoute route, HttpContext context)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicHttpClientConnectionManager

public BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry,
                                        HttpConnectionFactory<ManagedHttpClientConnection> connFactory,
                                        SchemePortResolver schemePortResolver,
                                        DnsResolver dnsResolver)

BasicHttpClientConnectionManager

public BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry,
                                        HttpConnectionFactory<ManagedHttpClientConnection> connFactory)

BasicHttpClientConnectionManager

public BasicHttpClientConnectionManager(org.apache.http.config.Lookup<ConnectionSocketFactory> socketFactoryRegistry)

BasicHttpClientConnectionManager

public BasicHttpClientConnectionManager()
Method Detail

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

close

public void close()
Specified by:
close in interface Closeable

getSocketConfig

public org.apache.http.config.SocketConfig getSocketConfig()

setSocketConfig

public void setSocketConfig(org.apache.http.config.SocketConfig socketConfig)

getConnectionConfig

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

setConnectionConfig

public void setConnectionConfig(org.apache.http.config.ConnectionConfig connConfig)

requestConnection

public final ConnectionRequest requestConnection(HttpRoute route,
                                                 Object state)
Description copied from interface: HttpClientConnectionManager
Returns a new ClientConnectionRequest, from which a HttpClientConnection can be obtained or the request can be aborted.

Specified by:
requestConnection in interface HttpClientConnectionManager

releaseConnection

public void releaseConnection(HttpClientConnection conn,
                              Object state,
                              long keepalive,
                              TimeUnit tunit)
Description copied from interface: HttpClientConnectionManager
Releases a connection for use by others. You may optionally specify how long the connection is valid to be reused. Values <= 0 are considered to be valid forever. If the connection is not marked as reusable, the connection will not be reused regardless of the valid duration. If the connection has been released before, the call will be ignored.

Specified by:
releaseConnection in interface HttpClientConnectionManager
Parameters:
conn - the connection to release
keepalive - the duration of time this connection is valid for reuse
tunit - the unit of time validDuration is measured in
See Also:
HttpClientConnectionManager.closeExpiredConnections()

connect

public void connect(HttpClientConnection conn,
                    HttpRoute route,
                    int connectTimeout,
                    HttpContext context)
             throws IOException
Specified by:
connect in interface HttpClientConnectionManager
Throws:
IOException

upgrade

public void upgrade(HttpClientConnection conn,
                    HttpRoute route,
                    HttpContext context)
             throws IOException
Specified by:
upgrade in interface HttpClientConnectionManager
Throws:
IOException

routeComplete

public void routeComplete(HttpClientConnection conn,
                          HttpRoute route,
                          HttpContext context)
                   throws IOException
Specified by:
routeComplete in interface HttpClientConnectionManager
Throws:
IOException

closeExpiredConnections

public void closeExpiredConnections()
Description copied from interface: HttpClientConnectionManager
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 HttpClientConnectionManager

closeIdleConnections

public void closeIdleConnections(long idletime,
                                 TimeUnit tunit)
Description copied from interface: HttpClientConnectionManager
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 HttpClientConnectionManager
Parameters:
idletime - the idle time of connections to be closed
tunit - the unit for the idletime
See Also:
HttpClientConnectionManager.closeExpiredConnections()

shutdown

public void shutdown()
Description copied from interface: HttpClientConnectionManager
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 HttpClientConnectionManager


Copyright © 1999-2013 The Apache Software Foundation. All Rights Reserved.