HTTPCLIENT-1538 : monitor contention in deprecated code

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1617273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-08-11 13:23:40 +00:00
parent f5bf414adc
commit caae4ef049
1 changed files with 21 additions and 4 deletions

View File

@ -28,6 +28,7 @@
package org.apache.http.impl.client;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -45,6 +46,17 @@ import org.apache.http.util.EntityUtils;
@NotThreadSafe
class CloseableHttpResponseProxy implements InvocationHandler {
private final static Constructor<?> CONSTRUCTOR;
static {
try {
CONSTRUCTOR = Proxy.getProxyClass(CloseableHttpResponseProxy.class.getClassLoader(),
new Class<?>[] { CloseableHttpResponse.class }).getConstructor(new Class[] { InvocationHandler.class });
} catch (NoSuchMethodException ex) {
throw new IllegalStateException(ex);
}
}
private final HttpResponse original;
CloseableHttpResponseProxy(final HttpResponse original) {
@ -79,10 +91,15 @@ class CloseableHttpResponseProxy implements InvocationHandler {
}
public static CloseableHttpResponse newProxy(final HttpResponse original) {
return (CloseableHttpResponse) Proxy.newProxyInstance(
CloseableHttpResponseProxy.class.getClassLoader(),
new Class<?>[] { CloseableHttpResponse.class },
new CloseableHttpResponseProxy(original));
try {
return (CloseableHttpResponse) CONSTRUCTOR.newInstance(new CloseableHttpResponseProxy(original));
} catch (InstantiationException ex) {
throw new IllegalStateException(ex);
} catch (InvocationTargetException ex) {
throw new IllegalStateException(ex);
} catch (IllegalAccessException ex) {
throw new IllegalStateException(ex);
}
}
}