Minor tweaks in the connection management code

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1432452 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-01-12 15:25:59 +00:00
parent f5a8aa7ba9
commit a97d088847
3 changed files with 25 additions and 9 deletions

View File

@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.SocketClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.pool.AbstractConnPool;
@ -46,7 +45,7 @@ class CPool extends AbstractConnPool<HttpRoute, SocketClientConnection, CPoolEnt
private static AtomicLong COUNTER = new AtomicLong();
private final Log log = LogFactory.getLog(HttpClientConnectionManager.class);
private final Log log = LogFactory.getLog(CPool.class);
private final long timeToLive;
private final TimeUnit tunit;

View File

@ -33,6 +33,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpConnection;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.conn.SocketClientConnection;
import org.apache.http.protocol.HttpContext;
@ -43,6 +44,22 @@ import org.apache.http.protocol.HttpContext;
@NotThreadSafe
class CPoolProxy implements InvocationHandler {
private static final Method CLOSE_METHOD;
private static final Method SHUTDOWN_METHOD;
private static final Method IS_OPEN_METHOD;
private static final Method IS_STALE_METHOD;
static {
try {
CLOSE_METHOD = HttpConnection.class.getMethod("close");
SHUTDOWN_METHOD = HttpConnection.class.getMethod("shutdown");
IS_OPEN_METHOD = HttpConnection.class.getMethod("isOpen");
IS_STALE_METHOD = HttpConnection.class.getMethod("isStale");
} catch (NoSuchMethodException ex) {
throw new Error(ex);
}
}
private volatile CPoolEntry poolEntry;
CPoolProxy(final CPoolEntry entry) {
@ -104,16 +121,15 @@ class CPoolProxy implements InvocationHandler {
public Object invoke(
final Object proxy, final Method method, final Object[] args) throws Throwable {
String mname = method.getName();
if (mname.equals("close")) {
if (method.equals(CLOSE_METHOD)) {
close();
return null;
} else if (mname.equals("shutdown")) {
} else if (method.equals(SHUTDOWN_METHOD)) {
shutdown();
return null;
} else if (mname.equals("isOpen")) {
} else if (method.equals(IS_OPEN_METHOD)) {
return Boolean.valueOf(isOpen());
} else if (mname.equals("isStale")) {
} else if (method.equals(IS_STALE_METHOD)) {
return Boolean.valueOf(isStale());
} else {
HttpClientConnection conn = getConnection();
@ -137,7 +153,7 @@ class CPoolProxy implements InvocationHandler {
final CPoolEntry poolEntry) {
return (HttpClientConnection) Proxy.newProxyInstance(
CPoolProxy.class.getClassLoader(),
new Class<?>[] { HttpClientConnection.class, SocketClientConnection.class, HttpContext.class },
new Class<?>[] { SocketClientConnection.class, HttpContext.class },
new CPoolProxy(poolEntry));
}

View File

@ -84,7 +84,8 @@ import org.apache.http.util.Asserts;
* @since 4.3
*/
@ThreadSafe
public class PoolingHttpClientConnectionManager implements HttpClientConnectionManager, Closeable {
public class PoolingHttpClientConnectionManager
implements HttpClientConnectionManager, ConnPoolControl<HttpRoute>, Closeable {
private final Log log = LogFactory.getLog(getClass());