| Method from org.apache.commons.httpclient.MultiThreadedHttpConnectionManager Detail: |
public void closeIdleConnections(long idleTimeout) {
connectionPool.closeIdleConnections(idleTimeout);
deleteClosedConnections();
}
|
public void deleteClosedConnections() {
connectionPool.deleteClosedConnections();
}
Deletes all closed connections. Only connections currently owned by the connection
manager are processed. |
public HttpConnection getConnection(HostConfiguration hostConfiguration) {
while (true) {
try {
return getConnectionWithTimeout(hostConfiguration, 0);
} catch (ConnectionPoolTimeoutException e) {
// we'll go ahead and log this, but it should never happen. HttpExceptions
// are only thrown when the timeout occurs and since we have no timeout
// it should never happen.
LOG.debug(
"Unexpected exception while waiting for connection",
e
);
}
}
}
|
public HttpConnection getConnection(HostConfiguration hostConfiguration,
long timeout) throws HttpException {
LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)");
try {
return getConnectionWithTimeout(hostConfiguration, timeout);
} catch(ConnectionPoolTimeoutException e) {
throw new HttpException(e.getMessage());
}
} Deprecated! Use - #getConnectionWithTimeout(HostConfiguration, long)
|
public HttpConnection getConnectionWithTimeout(HostConfiguration hostConfiguration,
long timeout) throws ConnectionPoolTimeoutException {
LOG.trace("enter HttpConnectionManager.getConnectionWithTimeout(HostConfiguration, long)");
if (hostConfiguration == null) {
throw new IllegalArgumentException("hostConfiguration is null");
}
if (LOG.isDebugEnabled()) {
LOG.debug("HttpConnectionManager.getConnection: config = "
+ hostConfiguration + ", timeout = " + timeout);
}
final HttpConnection conn = doGetConnection(hostConfiguration, timeout);
// wrap the connection in an adapter so we can ensure it is used
// only once
return new HttpConnectionAdapter(conn);
}
Gets a connection or waits if one is not available. A connection is
available if one exists that is not being used or if fewer than
maxHostConnections have been created in the connectionPool, and fewer
than maxTotalConnections have been created in all connectionPools. |
public int getConnectionsInPool() {
synchronized (connectionPool) {
return connectionPool.numConnections;
}
}
Gets the total number of pooled connections. This is the total number of
connections that have been created and are still in use by this connection
manager. This value will not exceed the maximum number of connections . |
public int getConnectionsInPool(HostConfiguration hostConfiguration) {
synchronized (connectionPool) {
HostConnectionPool hostPool = connectionPool.getHostPool(hostConfiguration, false);
return (hostPool != null) ? hostPool.numConnections : 0;
}
}
Gets the total number of pooled connections for the given host configuration. This
is the total number of connections that have been created and are still in use
by this connection manager for the host configuration. This value will
not exceed the maximum number of connections per
host . |
public int getConnectionsInUse() {
return getConnectionsInPool();
} Deprecated! Use - #getConnectionsInPool()
Gets the total number of connections in use. |
public int getConnectionsInUse(HostConfiguration hostConfiguration) {
return getConnectionsInPool(hostConfiguration);
} Deprecated! Use - #getConnectionsInPool(HostConfiguration)
Gets the number of connections in use for this configuration. |
public int getMaxConnectionsPerHost() {
return this.params.getDefaultMaxConnectionsPerHost();
} Deprecated! Use - HttpConnectionManagerParams#getDefaultMaxConnectionsPerHost() ,
HttpConnectionManager#getParams() .
Gets the maximum number of connections allowed for a given
hostConfiguration. |
public int getMaxTotalConnections() {
return this.params.getMaxTotalConnections();
} Deprecated! Use - HttpConnectionManagerParams#getMaxTotalConnections() ,
HttpConnectionManager#getParams() .
Gets the maximum number of connections allowed for this connection manager. |
public HttpConnectionManagerParams getParams() {
return this.params;
}
Returns parameters associated
with this connection manager. |
public boolean isConnectionStaleCheckingEnabled() {
return this.params.isStaleCheckingEnabled();
} Deprecated! Use - HttpConnectionManagerParams#isStaleCheckingEnabled() ,
HttpConnectionManager#getParams() .
Gets the staleCheckingEnabled value to be set on HttpConnections that are created. |
public void releaseConnection(HttpConnection conn) {
LOG.trace("enter HttpConnectionManager.releaseConnection(HttpConnection)");
if (conn instanceof HttpConnectionAdapter) {
// connections given out are wrapped in an HttpConnectionAdapter
conn = ((HttpConnectionAdapter) conn).getWrappedConnection();
} else {
// this is okay, when an HttpConnectionAdapter is released
// is releases the real connection
}
// make sure that the response has been read.
SimpleHttpConnectionManager.finishLastResponse(conn);
connectionPool.freeConnection(conn);
}
Make the given HttpConnection available for use by other requests.
If another thread is blocked in getConnection() that could use this
connection, it will be woken up. |
public void setConnectionStaleCheckingEnabled(boolean connectionStaleCheckingEnabled) {
this.params.setStaleCheckingEnabled(connectionStaleCheckingEnabled);
} Deprecated! Use - HttpConnectionManagerParams#setStaleCheckingEnabled(boolean) ,
HttpConnectionManager#getParams() .
Sets the staleCheckingEnabled value to be set on HttpConnections that are created. |
public void setMaxConnectionsPerHost(int maxHostConnections) {
this.params.setDefaultMaxConnectionsPerHost(maxHostConnections);
} Deprecated! Use - HttpConnectionManagerParams#setDefaultMaxConnectionsPerHost(int) ,
HttpConnectionManager#getParams() .
Sets the maximum number of connections allowed for a given
HostConfiguration. Per RFC 2616 section 8.1.4, this value defaults to 2. |
public void setMaxTotalConnections(int maxTotalConnections) {
this.params.setMaxTotalConnections(maxTotalConnections);
} Deprecated! Use - HttpConnectionManagerParams#setMaxTotalConnections(int) ,
HttpConnectionManager#getParams() .
Sets the maximum number of connections allowed for this connection manager. |
public void setParams(HttpConnectionManagerParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
this.params = params;
}
|
public synchronized void shutdown() {
synchronized (connectionPool) {
if (!shutdown) {
shutdown = true;
connectionPool.shutdown();
}
}
}
Shuts down the connection manager and releases all resources. All connections associated
with this class will be closed and released.
The connection manager can no longer be used once shut down.
Calling this method more than once will have no effect. |
public static void shutdownAll() {
// ---------------------------------------------------------- Class Methods
synchronized (REFERENCE_TO_CONNECTION_SOURCE) {
// shutdown all connection managers
synchronized (ALL_CONNECTION_MANAGERS) {
// Don't use an iterator here. Iterators on WeakHashMap can
// get ConcurrentModificationException on garbage collection.
MultiThreadedHttpConnectionManager[]
connManagers = (MultiThreadedHttpConnectionManager[])
ALL_CONNECTION_MANAGERS.keySet().toArray(
new MultiThreadedHttpConnectionManager
[ALL_CONNECTION_MANAGERS.size()]
);
// The map may shrink after size() is called, or some entry
// may get GCed while the array is built, so expect null.
for (int i=0; i< connManagers.length; i++) {
if (connManagers[i] != null)
connManagers[i].shutdown();
}
}
// shutdown static resources
if (REFERENCE_QUEUE_THREAD != null) {
REFERENCE_QUEUE_THREAD.shutdown();
REFERENCE_QUEUE_THREAD = null;
}
REFERENCE_TO_CONNECTION_SOURCE.clear();
}
}
Shuts down and cleans up resources used by all instances of
MultiThreadedHttpConnectionManager. All static resources are released, all threads are
stopped, and #shutdown() is called on all live instances of
MultiThreadedHttpConnectionManager. |