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:
parent
f5a8aa7ba9
commit
a97d088847
|
@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.http.annotation.ThreadSafe;
|
import org.apache.http.annotation.ThreadSafe;
|
||||||
import org.apache.http.conn.HttpClientConnectionManager;
|
|
||||||
import org.apache.http.conn.SocketClientConnection;
|
import org.apache.http.conn.SocketClientConnection;
|
||||||
import org.apache.http.conn.routing.HttpRoute;
|
import org.apache.http.conn.routing.HttpRoute;
|
||||||
import org.apache.http.pool.AbstractConnPool;
|
import org.apache.http.pool.AbstractConnPool;
|
||||||
|
@ -46,7 +45,7 @@ class CPool extends AbstractConnPool<HttpRoute, SocketClientConnection, CPoolEnt
|
||||||
|
|
||||||
private static AtomicLong COUNTER = new AtomicLong();
|
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 long timeToLive;
|
||||||
private final TimeUnit tunit;
|
private final TimeUnit tunit;
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
import org.apache.http.HttpClientConnection;
|
import org.apache.http.HttpClientConnection;
|
||||||
|
import org.apache.http.HttpConnection;
|
||||||
import org.apache.http.annotation.NotThreadSafe;
|
import org.apache.http.annotation.NotThreadSafe;
|
||||||
import org.apache.http.conn.SocketClientConnection;
|
import org.apache.http.conn.SocketClientConnection;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
@ -43,6 +44,22 @@ import org.apache.http.protocol.HttpContext;
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
class CPoolProxy implements InvocationHandler {
|
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;
|
private volatile CPoolEntry poolEntry;
|
||||||
|
|
||||||
CPoolProxy(final CPoolEntry entry) {
|
CPoolProxy(final CPoolEntry entry) {
|
||||||
|
@ -104,16 +121,15 @@ class CPoolProxy implements InvocationHandler {
|
||||||
|
|
||||||
public Object invoke(
|
public Object invoke(
|
||||||
final Object proxy, final Method method, final Object[] args) throws Throwable {
|
final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||||
String mname = method.getName();
|
if (method.equals(CLOSE_METHOD)) {
|
||||||
if (mname.equals("close")) {
|
|
||||||
close();
|
close();
|
||||||
return null;
|
return null;
|
||||||
} else if (mname.equals("shutdown")) {
|
} else if (method.equals(SHUTDOWN_METHOD)) {
|
||||||
shutdown();
|
shutdown();
|
||||||
return null;
|
return null;
|
||||||
} else if (mname.equals("isOpen")) {
|
} else if (method.equals(IS_OPEN_METHOD)) {
|
||||||
return Boolean.valueOf(isOpen());
|
return Boolean.valueOf(isOpen());
|
||||||
} else if (mname.equals("isStale")) {
|
} else if (method.equals(IS_STALE_METHOD)) {
|
||||||
return Boolean.valueOf(isStale());
|
return Boolean.valueOf(isStale());
|
||||||
} else {
|
} else {
|
||||||
HttpClientConnection conn = getConnection();
|
HttpClientConnection conn = getConnection();
|
||||||
|
@ -137,7 +153,7 @@ class CPoolProxy implements InvocationHandler {
|
||||||
final CPoolEntry poolEntry) {
|
final CPoolEntry poolEntry) {
|
||||||
return (HttpClientConnection) Proxy.newProxyInstance(
|
return (HttpClientConnection) Proxy.newProxyInstance(
|
||||||
CPoolProxy.class.getClassLoader(),
|
CPoolProxy.class.getClassLoader(),
|
||||||
new Class<?>[] { HttpClientConnection.class, SocketClientConnection.class, HttpContext.class },
|
new Class<?>[] { SocketClientConnection.class, HttpContext.class },
|
||||||
new CPoolProxy(poolEntry));
|
new CPoolProxy(poolEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,8 @@ import org.apache.http.util.Asserts;
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
public class PoolingHttpClientConnectionManager implements HttpClientConnectionManager, Closeable {
|
public class PoolingHttpClientConnectionManager
|
||||||
|
implements HttpClientConnectionManager, ConnPoolControl<HttpRoute>, Closeable {
|
||||||
|
|
||||||
private final Log log = LogFactory.getLog(getClass());
|
private final Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue