Redesigned connection management code based on HttpCore 4.2 API (merged from conn-mgmt-redesign branch)
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1160635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
commit
102ed1e844
|
@ -59,12 +59,6 @@
|
|||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
|
@ -98,7 +92,7 @@
|
|||
<dependency>
|
||||
<groupId>com.ning</groupId>
|
||||
<artifactId>async-http-client</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.6.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.apache.http.conn.scheme.SchemeRegistry;
|
|||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
|
@ -52,7 +52,7 @@ import org.apache.http.util.VersionInfo;
|
|||
|
||||
public class TestHttpClient4 implements TestHttpAgent {
|
||||
|
||||
private final ThreadSafeClientConnManager mgr;
|
||||
private final PoolingClientConnectionManager mgr;
|
||||
private final DefaultHttpClient httpclient;
|
||||
|
||||
public TestHttpClient4() {
|
||||
|
@ -71,7 +71,7 @@ public class TestHttpClient4 implements TestHttpAgent {
|
|||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
|
||||
this.mgr = new ThreadSafeClientConnManager(schemeRegistry);
|
||||
this.mgr = new PoolingClientConnectionManager(schemeRegistry);
|
||||
this.httpclient = new DefaultHttpClient(this.mgr, params);
|
||||
this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
|
||||
|
||||
|
|
|
@ -27,11 +27,13 @@ package org.apache.http.client.benchmark;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.ConnectionReuseStrategy;
|
||||
import org.apache.http.HeaderIterator;
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
|
@ -41,7 +43,8 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.impl.DefaultConnectionReuseStrategy;
|
||||
import org.apache.http.impl.DefaultHttpClientConnection;
|
||||
import org.apache.http.impl.pool.BasicConnPool;
|
||||
import org.apache.http.impl.pool.BasicPoolEntry;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
|
@ -66,6 +69,7 @@ public class TestHttpCore implements TestHttpAgent {
|
|||
private final HttpProcessor httpproc;
|
||||
private final HttpRequestExecutor httpexecutor;
|
||||
private final ConnectionReuseStrategy connStrategy;
|
||||
private final BasicConnPool pool;
|
||||
|
||||
public TestHttpCore() {
|
||||
super();
|
||||
|
@ -91,6 +95,8 @@ public class TestHttpCore implements TestHttpAgent {
|
|||
|
||||
this.httpexecutor = new HttpRequestExecutor();
|
||||
this.connStrategy = new DefaultConnectionReuseStrategy();
|
||||
|
||||
this.pool = new BasicConnPool(this.params);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
@ -100,6 +106,8 @@ public class TestHttpCore implements TestHttpAgent {
|
|||
}
|
||||
|
||||
Stats execute(final URI target, final byte[] content, int n, int c) throws Exception {
|
||||
this.pool.setMaxTotal(2000);
|
||||
this.pool.setDefaultMaxPerRoute(c);
|
||||
HttpHost targetHost = new HttpHost(target.getHost(), target.getPort());
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(target.getPath());
|
||||
|
@ -143,29 +151,27 @@ public class TestHttpCore implements TestHttpAgent {
|
|||
public void run() {
|
||||
byte[] buffer = new byte[4096];
|
||||
HttpContext context = new BasicHttpContext();
|
||||
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
|
||||
try {
|
||||
while (!this.stats.isComplete()) {
|
||||
HttpRequest request;
|
||||
if (this.content == null) {
|
||||
BasicHttpRequest httpget = new BasicHttpRequest("GET", this.requestUri);
|
||||
request = httpget;
|
||||
} else {
|
||||
BasicHttpEntityEnclosingRequest httppost = new BasicHttpEntityEnclosingRequest("POST",
|
||||
this.requestUri);
|
||||
httppost.setEntity(new ByteArrayEntity(this.content));
|
||||
request = httppost;
|
||||
}
|
||||
|
||||
long contentLen = 0;
|
||||
while (!this.stats.isComplete()) {
|
||||
HttpRequest request;
|
||||
if (this.content == null) {
|
||||
BasicHttpRequest httpget = new BasicHttpRequest("GET", this.requestUri);
|
||||
request = httpget;
|
||||
} else {
|
||||
BasicHttpEntityEnclosingRequest httppost = new BasicHttpEntityEnclosingRequest("POST",
|
||||
this.requestUri);
|
||||
httppost.setEntity(new ByteArrayEntity(this.content));
|
||||
request = httppost;
|
||||
}
|
||||
|
||||
long contentLen = 0;
|
||||
boolean reusable = false;
|
||||
|
||||
Future<BasicPoolEntry> future = pool.lease(targetHost, null);
|
||||
try {
|
||||
BasicPoolEntry entry = future.get();
|
||||
try {
|
||||
if (!conn.isOpen()) {
|
||||
Socket socket = new Socket(
|
||||
this.targetHost.getHostName(),
|
||||
this.targetHost.getPort() > 0 ? this.targetHost.getPort() : 80);
|
||||
conn.bind(socket, params);
|
||||
}
|
||||
|
||||
HttpClientConnection conn = entry.getConnection();
|
||||
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
|
||||
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
|
||||
|
||||
|
@ -188,8 +194,8 @@ public class TestHttpCore implements TestHttpAgent {
|
|||
instream.close();
|
||||
}
|
||||
}
|
||||
if (!connStrategy.keepAlive(response, context)) {
|
||||
conn.close();
|
||||
if (connStrategy.keepAlive(response, context)) {
|
||||
reusable = true;
|
||||
}
|
||||
for (HeaderIterator it = request.headerIterator(); it.hasNext();) {
|
||||
it.next();
|
||||
|
@ -200,16 +206,18 @@ public class TestHttpCore implements TestHttpAgent {
|
|||
} else {
|
||||
this.stats.failure(contentLen);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
this.stats.failure(contentLen);
|
||||
} catch (HttpException ex) {
|
||||
this.stats.failure(contentLen);
|
||||
} finally {
|
||||
pool.release(entry, reusable);
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
this.stats.failure(contentLen);
|
||||
} catch (ExecutionException ex) {
|
||||
this.stats.failure(contentLen);
|
||||
} catch (IOException ex) {
|
||||
this.stats.failure(contentLen);
|
||||
} catch (HttpException ex) {
|
||||
this.stats.failure(contentLen);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
conn.shutdown();
|
||||
} catch (IOException ignore) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public class TestNingHttpClient implements TestHttpAgent {
|
|||
}
|
||||
|
||||
public String getClientName() {
|
||||
return "Ning async HTTP client 1.5.0";
|
||||
return "Ning async HTTP client 1.6.4";
|
||||
}
|
||||
|
||||
static class SimpleAsyncHandler implements AsyncHandler<Object> {
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.http.client.HttpClient;
|
|||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ import org.apache.http.util.EntityUtils;
|
|||
public class ClientEvictExpiredConnections {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
|
||||
PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
|
||||
cm.setMaxTotal(100);
|
||||
|
||||
HttpClient httpclient = new DefaultHttpClient(cm);
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
@ -46,7 +46,7 @@ public class ClientMultiThreadedExecution {
|
|||
// Create an HttpClient with the ThreadSafeClientConnManager.
|
||||
// This connection manager must be used if more than one thread will
|
||||
// be using the HttpClient.
|
||||
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
|
||||
PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
|
||||
cm.setMaxTotal(100);
|
||||
|
||||
HttpClient httpclient = new DefaultHttpClient(cm);
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.examples.conn;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.scheme.SchemeSocketFactory;
|
||||
import org.apache.http.conn.ClientConnectionRequest;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.params.SyncBasicHttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
|
||||
/**
|
||||
* How to open a direct connection using
|
||||
* {@link ClientConnectionManager ClientConnectionManager}.
|
||||
* This exemplifies the <i>opening</i> of the connection only.
|
||||
* The subsequent message exchange in this example should not
|
||||
* be used as a template.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ManagerConnectDirect {
|
||||
|
||||
/**
|
||||
* Main entry point to this example.
|
||||
*
|
||||
* @param args ignored
|
||||
*/
|
||||
public final static void main(String[] args) throws Exception {
|
||||
|
||||
HttpHost target = new HttpHost("www.apache.org", 80, "http");
|
||||
|
||||
// Register the "http" protocol scheme, it is required
|
||||
// by the default operator to look up socket factories.
|
||||
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
||||
SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||
supportedSchemes.register(new Scheme("http", 80, sf));
|
||||
|
||||
// Prepare parameters.
|
||||
// Since this example doesn't use the full core framework,
|
||||
// only few parameters are actually required.
|
||||
HttpParams params = new SyncBasicHttpParams();
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
||||
|
||||
ClientConnectionManager clcm = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
|
||||
HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
|
||||
req.addHeader("Host", target.getHostName());
|
||||
|
||||
HttpContext ctx = new BasicHttpContext();
|
||||
|
||||
System.out.println("preparing route to " + target);
|
||||
HttpRoute route = new HttpRoute
|
||||
(target, null, supportedSchemes.getScheme(target).isLayered());
|
||||
|
||||
System.out.println("requesting connection for " + route);
|
||||
ClientConnectionRequest connRequest = clcm.requestConnection(route, null);
|
||||
ManagedClientConnection conn = connRequest.getConnection(0, null);
|
||||
try {
|
||||
System.out.println("opening connection");
|
||||
conn.open(route, ctx, params);
|
||||
|
||||
System.out.println("sending request");
|
||||
conn.sendRequestHeader(req);
|
||||
// there is no request entity
|
||||
conn.flush();
|
||||
|
||||
System.out.println("receiving response header");
|
||||
HttpResponse rsp = conn.receiveResponseHeader();
|
||||
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(rsp.getStatusLine());
|
||||
Header[] headers = rsp.getAllHeaders();
|
||||
for (int i=0; i<headers.length; i++) {
|
||||
System.out.println(headers[i]);
|
||||
}
|
||||
System.out.println("----------------------------------------");
|
||||
|
||||
System.out.println("closing connection");
|
||||
conn.close();
|
||||
|
||||
} finally {
|
||||
|
||||
if (conn.isOpen()) {
|
||||
System.out.println("shutting down connection");
|
||||
try {
|
||||
conn.shutdown();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("problem during shutdown");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("releasing connection");
|
||||
clcm.releaseConnection(conn, -1, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.examples.conn;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.ClientConnectionRequest;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.params.SyncBasicHttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.BasicHttpContext;
|
||||
|
||||
/**
|
||||
* How to open a secure connection through a proxy using
|
||||
* {@link ClientConnectionManager ClientConnectionManager}.
|
||||
* This exemplifies the <i>opening</i> of the connection only.
|
||||
* The message exchange, both subsequently and for tunnelling,
|
||||
* should not be used as a template.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ManagerConnectProxy {
|
||||
|
||||
/**
|
||||
* Main entry point to this example.
|
||||
*
|
||||
* @param args ignored
|
||||
*/
|
||||
public final static void main(String[] args) throws Exception {
|
||||
|
||||
// make sure to use a proxy that supports CONNECT
|
||||
HttpHost target = new HttpHost("issues.apache.org", 443, "https");
|
||||
HttpHost proxy = new HttpHost("127.0.0.1", 8666, "http");
|
||||
|
||||
// Register the "http" and "https" protocol schemes, they are
|
||||
// required by the default operator to look up socket factories.
|
||||
SchemeRegistry supportedSchemes = new SchemeRegistry();
|
||||
supportedSchemes.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
supportedSchemes.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
|
||||
|
||||
// Prepare parameters.
|
||||
// Since this example doesn't use the full core framework,
|
||||
// only few parameters are actually required.
|
||||
HttpParams params = new SyncBasicHttpParams();
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
HttpProtocolParams.setUseExpectContinue(params, false);
|
||||
|
||||
ClientConnectionManager clcm = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
|
||||
HttpRequest req = new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1);
|
||||
req.addHeader("Host", target.getHostName());
|
||||
|
||||
HttpContext ctx = new BasicHttpContext();
|
||||
|
||||
System.out.println("preparing route to " + target + " via " + proxy);
|
||||
HttpRoute route = new HttpRoute
|
||||
(target, null, proxy,
|
||||
supportedSchemes.getScheme(target).isLayered());
|
||||
|
||||
System.out.println("requesting connection for " + route);
|
||||
ClientConnectionRequest connRequest = clcm.requestConnection(route, null);
|
||||
ManagedClientConnection conn = connRequest.getConnection(0, null);
|
||||
try {
|
||||
System.out.println("opening connection");
|
||||
conn.open(route, ctx, params);
|
||||
|
||||
String authority = target.getHostName() + ":" + target.getPort();
|
||||
HttpRequest connect = new BasicHttpRequest("CONNECT", authority, HttpVersion.HTTP_1_1);
|
||||
connect.addHeader("Host", authority);
|
||||
|
||||
System.out.println("opening tunnel to " + target);
|
||||
conn.sendRequestHeader(connect);
|
||||
// there is no request entity
|
||||
conn.flush();
|
||||
|
||||
System.out.println("receiving confirmation for tunnel");
|
||||
HttpResponse connected = conn.receiveResponseHeader();
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(connected.getStatusLine());
|
||||
Header[] headers = connected.getAllHeaders();
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
System.out.println(headers[i]);
|
||||
}
|
||||
System.out.println("----------------------------------------");
|
||||
int status = connected.getStatusLine().getStatusCode();
|
||||
if ((status < 200) || (status > 299)) {
|
||||
System.out.println("unexpected status code " + status);
|
||||
System.exit(1);
|
||||
}
|
||||
System.out.println("receiving response body (ignored)");
|
||||
conn.receiveResponseEntity(connected);
|
||||
|
||||
conn.tunnelTarget(false, params);
|
||||
|
||||
System.out.println("layering secure connection");
|
||||
conn.layerProtocol(ctx, params);
|
||||
|
||||
// finally we have the secure connection and can send the request
|
||||
|
||||
System.out.println("sending request");
|
||||
conn.sendRequestHeader(req);
|
||||
// there is no request entity
|
||||
conn.flush();
|
||||
|
||||
System.out.println("receiving response header");
|
||||
HttpResponse rsp = conn.receiveResponseHeader();
|
||||
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(rsp.getStatusLine());
|
||||
headers = rsp.getAllHeaders();
|
||||
for (int i = 0; i < headers.length; i++) {
|
||||
System.out.println(headers[i]);
|
||||
}
|
||||
System.out.println("----------------------------------------");
|
||||
|
||||
System.out.println("closing connection");
|
||||
conn.close();
|
||||
|
||||
} finally {
|
||||
|
||||
if (conn.isOpen()) {
|
||||
System.out.println("shutting down connection");
|
||||
try {
|
||||
conn.shutdown();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("problem during shutdown");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("releasing connection");
|
||||
clcm.releaseConnection(conn, -1, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ import org.apache.http.conn.ClientConnectionManager;
|
|||
import org.apache.http.conn.ClientConnectionRequest;
|
||||
import org.apache.http.conn.ConnectionReleaseTrigger;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
|
||||
/**
|
||||
* Interface representing an HTTP request that can be aborted by shutting
|
||||
|
@ -52,7 +51,6 @@ public interface AbortableHttpRequest {
|
|||
* If the request is already aborted, throws an {@link IOException}.
|
||||
*
|
||||
* @see ClientConnectionManager
|
||||
* @see ThreadSafeClientConnManager
|
||||
*/
|
||||
void setConnectionRequest(ClientConnectionRequest connRequest) throws IOException;
|
||||
|
||||
|
|
|
@ -376,8 +376,6 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
|||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder cab = new StringBuilder(50 + getHopCount()*30);
|
||||
|
||||
cab.append("HttpRoute[");
|
||||
if (this.localAddress != null) {
|
||||
cab.append(this.localAddress);
|
||||
cab.append("->");
|
||||
|
@ -395,8 +393,6 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
|||
cab.append("->");
|
||||
}
|
||||
cab.append(this.targetHost);
|
||||
cab.append(']');
|
||||
|
||||
return cab.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.http.HttpRequest;
|
|||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpConnectionMetrics;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
|
@ -66,8 +67,8 @@ import org.apache.http.protocol.HttpContext;
|
|||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public abstract class AbstractClientConnAdapter
|
||||
implements ManagedClientConnection, HttpContext {
|
||||
@NotThreadSafe
|
||||
public abstract class AbstractClientConnAdapter implements ManagedClientConnection, HttpContext {
|
||||
|
||||
/**
|
||||
* The connection manager, if any.
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.io.IOException;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.routing.RouteTracker;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
|
@ -52,8 +51,10 @@ import org.apache.http.conn.OperatedClientConnection;
|
|||
* underlying connection and the established route.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated do not use
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@Deprecated
|
||||
public abstract class AbstractPoolEntry {
|
||||
|
||||
/** The connection operator. */
|
||||
|
|
|
@ -46,7 +46,10 @@ import org.apache.http.conn.OperatedClientConnection;
|
|||
* respective method of the wrapped connection.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated do not use
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapter {
|
||||
|
||||
/** The wrapped pool entry. */
|
||||
|
|
|
@ -149,7 +149,9 @@ public class DefaultClientConnection extends SocketHttpClientConnection
|
|||
shutdown = true;
|
||||
try {
|
||||
super.shutdown();
|
||||
log.debug("Connection shut down");
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connection " + this + " shut down");
|
||||
}
|
||||
Socket sock = this.socket; // copy volatile attribute
|
||||
if (sock != null)
|
||||
sock.close();
|
||||
|
@ -162,7 +164,9 @@ public class DefaultClientConnection extends SocketHttpClientConnection
|
|||
public void close() throws IOException {
|
||||
try {
|
||||
super.close();
|
||||
log.debug("Connection closed");
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Connection " + this + " closed");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
log.debug("I/O error closing connection", ex);
|
||||
}
|
||||
|
@ -211,7 +215,7 @@ public class DefaultClientConnection extends SocketHttpClientConnection
|
|||
}
|
||||
|
||||
@Override
|
||||
protected HttpMessageParser createResponseParser(
|
||||
protected HttpMessageParser<HttpResponse> createResponseParser(
|
||||
final SessionInputBuffer buffer,
|
||||
final HttpResponseFactory responseFactory,
|
||||
final HttpParams params) {
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.http.annotation.ThreadSafe;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpMessage;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpResponseFactory;
|
||||
import org.apache.http.NoHttpResponseException;
|
||||
import org.apache.http.ProtocolException;
|
||||
|
@ -60,7 +60,7 @@ import org.apache.http.util.CharArrayBuffer;
|
|||
* @since 4.0
|
||||
*/
|
||||
@ThreadSafe // no public methods
|
||||
public class DefaultResponseParser extends AbstractMessageParser {
|
||||
public class DefaultResponseParser extends AbstractMessageParser<HttpResponse> {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class DefaultResponseParser extends AbstractMessageParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected HttpMessage parseHead(
|
||||
protected HttpResponse parseHead(
|
||||
final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
|
||||
//read out the HTTP status string
|
||||
int count = 0;
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.http.HttpConnection;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.pool.AbstractConnPool;
|
||||
|
||||
/**
|
||||
* @since 4.2
|
||||
*/
|
||||
class HttpConnPool extends AbstractConnPool<HttpRoute, OperatedClientConnection, HttpPoolEntry> {
|
||||
|
||||
private static AtomicLong COUNTER = new AtomicLong();
|
||||
|
||||
private final Log log;
|
||||
private final long timeToLive;
|
||||
private final TimeUnit tunit;
|
||||
|
||||
public HttpConnPool(final Log log,
|
||||
final int defaultMaxPerRoute, final int maxTotal,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super(defaultMaxPerRoute, maxTotal);
|
||||
this.log = log;
|
||||
this.timeToLive = timeToLive;
|
||||
this.tunit = tunit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OperatedClientConnection createConnection(final HttpRoute route) throws IOException {
|
||||
return new DefaultClientConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpPoolEntry createEntry(final HttpRoute route, final OperatedClientConnection conn) {
|
||||
String id = Long.toString(COUNTER.getAndIncrement());
|
||||
return new HttpPoolEntry(this.log, id, route, conn, this.timeToLive, this.tunit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeEntry(final HttpPoolEntry entry) {
|
||||
HttpConnection conn = entry.getConnection();
|
||||
try {
|
||||
conn.shutdown();
|
||||
} catch (IOException ex) {
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("I/O error shutting down connection", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.routing.RouteTracker;
|
||||
import org.apache.http.pool.PoolEntry;
|
||||
|
||||
/**
|
||||
* @since 4.2
|
||||
*/
|
||||
class HttpPoolEntry extends PoolEntry<HttpRoute, OperatedClientConnection> {
|
||||
|
||||
private final Log log;
|
||||
private final RouteTracker tracker;
|
||||
|
||||
public HttpPoolEntry(
|
||||
final Log log,
|
||||
final String id,
|
||||
final HttpRoute route,
|
||||
final OperatedClientConnection conn,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super(id, route, conn, timeToLive, tunit);
|
||||
this.log = log;
|
||||
this.tracker = new RouteTracker(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired(long now) {
|
||||
boolean expired = super.isExpired(now);
|
||||
if (expired && this.log.isDebugEnabled()) {
|
||||
this.log.debug("Connection " + this + " expired @ " + new Date(getExpiry()));
|
||||
}
|
||||
return expired;
|
||||
}
|
||||
|
||||
RouteTracker getTracker() {
|
||||
return this.tracker;
|
||||
}
|
||||
|
||||
HttpRoute getPlannedRoute() {
|
||||
return getRoute();
|
||||
}
|
||||
|
||||
HttpRoute getEffectiveRoute() {
|
||||
return this.tracker.toRoute();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,464 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import org.apache.http.HttpConnectionMetrics;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.routing.RouteTracker;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
@NotThreadSafe
|
||||
class ManagedClientConnectionImpl implements ManagedClientConnection {
|
||||
|
||||
private final ClientConnectionManager manager;
|
||||
private final ClientConnectionOperator operator;
|
||||
private volatile HttpPoolEntry poolEntry;
|
||||
private volatile boolean reusable;
|
||||
private volatile long duration;
|
||||
|
||||
ManagedClientConnectionImpl(
|
||||
final ClientConnectionManager manager,
|
||||
final ClientConnectionOperator operator,
|
||||
final HttpPoolEntry entry) {
|
||||
super();
|
||||
if (manager == null) {
|
||||
throw new IllegalArgumentException("Connection manager may not be null");
|
||||
}
|
||||
if (operator == null) {
|
||||
throw new IllegalArgumentException("Connection operator may not be null");
|
||||
}
|
||||
if (entry == null) {
|
||||
throw new IllegalArgumentException("HTTP pool entry may not be null");
|
||||
}
|
||||
this.manager = manager;
|
||||
this.operator = operator;
|
||||
this.poolEntry = entry;
|
||||
this.reusable = false;
|
||||
this.duration = Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
HttpPoolEntry getPoolEntry() {
|
||||
return this.poolEntry;
|
||||
}
|
||||
|
||||
HttpPoolEntry detach() {
|
||||
HttpPoolEntry local = this.poolEntry;
|
||||
this.poolEntry = null;
|
||||
return local;
|
||||
}
|
||||
|
||||
public ClientConnectionManager getManager() {
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
private OperatedClientConnection getConnection() {
|
||||
HttpPoolEntry local = this.poolEntry;
|
||||
if (local == null) {
|
||||
return null;
|
||||
}
|
||||
return local.getConnection();
|
||||
}
|
||||
|
||||
private OperatedClientConnection ensureConnection() {
|
||||
HttpPoolEntry local = this.poolEntry;
|
||||
if (local == null) {
|
||||
throw new ConnectionShutdownException();
|
||||
}
|
||||
return local.getConnection();
|
||||
}
|
||||
|
||||
private HttpPoolEntry ensurePoolEntry() {
|
||||
HttpPoolEntry local = this.poolEntry;
|
||||
if (local == null) {
|
||||
throw new ConnectionShutdownException();
|
||||
}
|
||||
return local;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
OperatedClientConnection conn = getConnection();
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() throws IOException {
|
||||
OperatedClientConnection conn = getConnection();
|
||||
if (conn != null) {
|
||||
conn.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
OperatedClientConnection conn = getConnection();
|
||||
if (conn != null) {
|
||||
return conn.isOpen();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isStale() {
|
||||
OperatedClientConnection conn = getConnection();
|
||||
if (conn != null) {
|
||||
return conn.isStale();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSocketTimeout(int timeout) {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
conn.setSocketTimeout(timeout);
|
||||
}
|
||||
|
||||
public int getSocketTimeout() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getSocketTimeout();
|
||||
}
|
||||
|
||||
public HttpConnectionMetrics getMetrics() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getMetrics();
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
conn.flush();
|
||||
}
|
||||
|
||||
public boolean isResponseAvailable(int timeout) throws IOException {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.isResponseAvailable(timeout);
|
||||
}
|
||||
|
||||
public void receiveResponseEntity(
|
||||
final HttpResponse response) throws HttpException, IOException {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
conn.receiveResponseEntity(response);
|
||||
}
|
||||
|
||||
public HttpResponse receiveResponseHeader() throws HttpException, IOException {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.receiveResponseHeader();
|
||||
}
|
||||
|
||||
public void sendRequestEntity(
|
||||
final HttpEntityEnclosingRequest request) throws HttpException, IOException {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
conn.sendRequestEntity(request);
|
||||
}
|
||||
|
||||
public void sendRequestHeader(
|
||||
final HttpRequest request) throws HttpException, IOException {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
conn.sendRequestHeader(request);
|
||||
}
|
||||
|
||||
public InetAddress getLocalAddress() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getLocalAddress();
|
||||
}
|
||||
|
||||
public int getLocalPort() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getLocalPort();
|
||||
}
|
||||
|
||||
public InetAddress getRemoteAddress() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getRemoteAddress();
|
||||
}
|
||||
|
||||
public int getRemotePort() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.getRemotePort();
|
||||
}
|
||||
|
||||
public boolean isSecure() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
return conn.isSecure();
|
||||
}
|
||||
|
||||
public SSLSession getSSLSession() {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
SSLSession result = null;
|
||||
Socket sock = conn.getSocket();
|
||||
if (sock instanceof SSLSocket) {
|
||||
result = ((SSLSocket)sock).getSession();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object getAttribute(final String id) {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
if (conn instanceof HttpContext) {
|
||||
return ((HttpContext) conn).getAttribute(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object removeAttribute(final String id) {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
if (conn instanceof HttpContext) {
|
||||
return ((HttpContext) conn).removeAttribute(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAttribute(final String id, final Object obj) {
|
||||
OperatedClientConnection conn = ensureConnection();
|
||||
if (conn instanceof HttpContext) {
|
||||
((HttpContext) conn).setAttribute(id, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public HttpRoute getRoute() {
|
||||
HttpPoolEntry local = ensurePoolEntry();
|
||||
return local.getEffectiveRoute();
|
||||
}
|
||||
|
||||
public void open(
|
||||
final HttpRoute route,
|
||||
final HttpContext context,
|
||||
final HttpParams params) throws IOException {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("Route may not be null");
|
||||
}
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
}
|
||||
OperatedClientConnection conn;
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new ConnectionShutdownException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
if (tracker.isConnected()) {
|
||||
throw new IllegalStateException("Connection already open");
|
||||
}
|
||||
conn = this.poolEntry.getConnection();
|
||||
}
|
||||
|
||||
HttpHost proxy = route.getProxyHost();
|
||||
this.operator.openConnection(
|
||||
conn,
|
||||
(proxy != null) ? proxy : route.getTargetHost(),
|
||||
route.getLocalAddress(),
|
||||
context, params);
|
||||
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
if (proxy == null) {
|
||||
tracker.connectTarget(conn.isSecure());
|
||||
} else {
|
||||
tracker.connectProxy(proxy, conn.isSecure());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tunnelTarget(
|
||||
boolean secure, final HttpParams params) throws IOException {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
}
|
||||
HttpHost target;
|
||||
OperatedClientConnection conn;
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new ConnectionShutdownException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
if (!tracker.isConnected()) {
|
||||
throw new IllegalStateException("Connection not open");
|
||||
}
|
||||
if (tracker.isTunnelled()) {
|
||||
throw new IllegalStateException("Connection is already tunnelled");
|
||||
}
|
||||
target = tracker.getTargetHost();
|
||||
conn = this.poolEntry.getConnection();
|
||||
}
|
||||
|
||||
conn.update(null, target, secure, params);
|
||||
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
tracker.tunnelTarget(secure);
|
||||
}
|
||||
}
|
||||
|
||||
public void tunnelProxy(
|
||||
final HttpHost next, boolean secure, final HttpParams params) throws IOException {
|
||||
if (next == null) {
|
||||
throw new IllegalArgumentException("Next proxy amy not be null");
|
||||
}
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
}
|
||||
OperatedClientConnection conn;
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new ConnectionShutdownException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
if (!tracker.isConnected()) {
|
||||
throw new IllegalStateException("Connection not open");
|
||||
}
|
||||
conn = this.poolEntry.getConnection();
|
||||
}
|
||||
|
||||
conn.update(null, next, secure, params);
|
||||
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
tracker.tunnelProxy(next, secure);
|
||||
}
|
||||
}
|
||||
|
||||
public void layerProtocol(
|
||||
final HttpContext context, final HttpParams params) throws IOException {
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("HTTP parameters may not be null");
|
||||
}
|
||||
HttpHost target;
|
||||
OperatedClientConnection conn;
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new ConnectionShutdownException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
if (!tracker.isConnected()) {
|
||||
throw new IllegalStateException("Connection not open");
|
||||
}
|
||||
if (!tracker.isTunnelled()) {
|
||||
throw new IllegalStateException("Protocol layering without a tunnel not supported");
|
||||
}
|
||||
if (tracker.isLayered()) {
|
||||
throw new IllegalStateException("Multiple protocol layering not supported");
|
||||
}
|
||||
target = tracker.getTargetHost();
|
||||
conn = this.poolEntry.getConnection();
|
||||
}
|
||||
this.operator.updateSecureConnection(conn, target, context, params);
|
||||
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
throw new InterruptedIOException();
|
||||
}
|
||||
RouteTracker tracker = this.poolEntry.getTracker();
|
||||
tracker.layerProtocol(conn.isSecure());
|
||||
}
|
||||
}
|
||||
|
||||
public Object getState() {
|
||||
HttpPoolEntry local = ensurePoolEntry();
|
||||
return local.getState();
|
||||
}
|
||||
|
||||
public void setState(final Object state) {
|
||||
HttpPoolEntry local = ensurePoolEntry();
|
||||
local.setState(state);
|
||||
}
|
||||
|
||||
public void markReusable() {
|
||||
this.reusable = true;
|
||||
}
|
||||
|
||||
public void unmarkReusable() {
|
||||
this.reusable = false;
|
||||
}
|
||||
|
||||
public boolean isMarkedReusable() {
|
||||
return this.reusable;
|
||||
}
|
||||
|
||||
public void setIdleDuration(long duration, TimeUnit unit) {
|
||||
if(duration > 0) {
|
||||
this.duration = unit.toMillis(duration);
|
||||
} else {
|
||||
this.duration = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void releaseConnection() {
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
return;
|
||||
}
|
||||
this.manager.releaseConnection(this, this.duration, TimeUnit.MILLISECONDS);
|
||||
this.poolEntry = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void abortConnection() {
|
||||
synchronized (this) {
|
||||
if (this.poolEntry == null) {
|
||||
return;
|
||||
}
|
||||
this.reusable = false;
|
||||
OperatedClientConnection conn = this.poolEntry.getConnection();
|
||||
try {
|
||||
conn.shutdown();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
this.manager.releaseConnection(this, this.duration, TimeUnit.MILLISECONDS);
|
||||
this.poolEntry = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
import org.apache.http.conn.ClientConnectionRequest;
|
||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.pool.ConnPoolControl;
|
||||
import org.apache.http.pool.PoolStats;
|
||||
import org.apache.http.impl.conn.DefaultClientConnectionOperator;
|
||||
import org.apache.http.impl.conn.SchemeRegistryFactory;
|
||||
|
||||
/**
|
||||
* Manages a pool of {@link OperatedClientConnection client connections} and
|
||||
* is able to service connection requests from multiple execution threads.
|
||||
* Connections are pooled on a per route basis. A request for a route which
|
||||
* already the manager has persistent connections for available in the pool
|
||||
* will be services by leasing a connection from the pool rather than
|
||||
* creating a brand new connection.
|
||||
* <p>
|
||||
* PoolingConnectionManager maintains a maximum limit of connection on
|
||||
* a per route basis and in total. Per default this implementation will
|
||||
* create no more than than 2 concurrent connections per given route
|
||||
* and no more 20 connections in total. For many real-world applications
|
||||
* these limits may prove too constraining, especially if they use HTTP
|
||||
* as a transport protocol for their services. Connection limits, however,
|
||||
* can be adjusted using HTTP parameters.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@ThreadSafe
|
||||
public class PoolingClientConnectionManager implements ClientConnectionManager, ConnPoolControl<HttpRoute> {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
private final SchemeRegistry schemeRegistry;
|
||||
|
||||
private final HttpConnPool pool;
|
||||
|
||||
private final ClientConnectionOperator operator;
|
||||
|
||||
public PoolingClientConnectionManager(final SchemeRegistry schreg) {
|
||||
this(schreg, -1, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public PoolingClientConnectionManager() {
|
||||
this(SchemeRegistryFactory.createDefault());
|
||||
}
|
||||
|
||||
public PoolingClientConnectionManager(
|
||||
final SchemeRegistry schemeRegistry,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super();
|
||||
if (schemeRegistry == null) {
|
||||
throw new IllegalArgumentException("Scheme registry may not be null");
|
||||
}
|
||||
this.schemeRegistry = schemeRegistry;
|
||||
this.operator = createConnectionOperator(schemeRegistry);
|
||||
this.pool = new HttpConnPool(this.log, 2, 20, timeToLive, tunit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
shutdown();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for creating the connection operator.
|
||||
* It is called by the constructor.
|
||||
* Derived classes can override this method to change the
|
||||
* instantiation of the operator.
|
||||
* The default implementation here instantiates
|
||||
* {@link DefaultClientConnectionOperator DefaultClientConnectionOperator}.
|
||||
*
|
||||
* @param schreg the scheme registry.
|
||||
*
|
||||
* @return the connection operator to use
|
||||
*/
|
||||
protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg) {
|
||||
return new DefaultClientConnectionOperator(schreg);
|
||||
}
|
||||
|
||||
public SchemeRegistry getSchemeRegistry() {
|
||||
return this.schemeRegistry;
|
||||
}
|
||||
|
||||
private String format(final HttpRoute route, final Object state) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[route: ").append(route).append("]");
|
||||
if (state != null) {
|
||||
buf.append("[state: ").append(state).append("]");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private String formatStats(final HttpRoute route) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
PoolStats totals = this.pool.getTotalStats();
|
||||
PoolStats stats = this.pool.getStats(route);
|
||||
buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
|
||||
buf.append("route allocated: ").append(stats.getLeased() + stats.getAvailable());
|
||||
buf.append(" of ").append(stats.getMax()).append("; ");
|
||||
buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
|
||||
buf.append(" of ").append(totals.getMax()).append("]");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private String format(final HttpPoolEntry entry) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[id: ").append(entry.getId()).append("]");
|
||||
buf.append("[route: ").append(entry.getRoute()).append("]");
|
||||
Object state = entry.getState();
|
||||
if (state != null) {
|
||||
buf.append("[state: ").append(state).append("]");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public ClientConnectionRequest requestConnection(
|
||||
final HttpRoute route,
|
||||
final Object state) {
|
||||
if (route == null) {
|
||||
throw new IllegalArgumentException("HTTP route may not be null");
|
||||
}
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Connection request: " + format(route, state) + formatStats(route));
|
||||
}
|
||||
final Future<HttpPoolEntry> future = this.pool.lease(route, state);
|
||||
|
||||
return new ClientConnectionRequest() {
|
||||
|
||||
public void abortRequest() {
|
||||
future.cancel(true);
|
||||
}
|
||||
|
||||
public ManagedClientConnection getConnection(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
return leaseConnection(future, timeout, tunit);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
ManagedClientConnection leaseConnection(
|
||||
final Future<HttpPoolEntry> future,
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
HttpPoolEntry entry;
|
||||
try {
|
||||
entry = future.get(timeout, tunit);
|
||||
if (entry == null || future.isCancelled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
if (entry.getConnection() == null) {
|
||||
throw new IllegalStateException("Pool entry with no connection");
|
||||
}
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Connection leased: " + format(entry) + formatStats(entry.getRoute()));
|
||||
}
|
||||
return new ManagedClientConnectionImpl(this, this.operator, entry);
|
||||
} catch (ExecutionException ex) {
|
||||
Throwable cause = ex.getCause();
|
||||
if (cause == null) {
|
||||
cause = ex;
|
||||
}
|
||||
this.log.error("Unexpected exception leasing connection from pool", cause);
|
||||
// Should never happen
|
||||
throw new InterruptedException();
|
||||
} catch (TimeoutException ex) {
|
||||
throw new ConnectionPoolTimeoutException("Timeout waiting for connection");
|
||||
}
|
||||
}
|
||||
|
||||
public void releaseConnection(
|
||||
final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
|
||||
|
||||
if (!(conn instanceof ManagedClientConnectionImpl)) {
|
||||
throw new IllegalArgumentException
|
||||
("Connection class mismatch, " +
|
||||
"connection not obtained from this manager.");
|
||||
}
|
||||
ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
|
||||
if (managedConn.getManager() != this) {
|
||||
throw new IllegalStateException("Connection not obtained from this manager.");
|
||||
}
|
||||
|
||||
synchronized (managedConn) {
|
||||
HttpPoolEntry entry = managedConn.detach();
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
|
||||
try {
|
||||
managedConn.shutdown();
|
||||
} catch (IOException iox) {
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("I/O exception shutting down released connection", iox);
|
||||
}
|
||||
}
|
||||
}
|
||||
entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
|
||||
if (this.log.isDebugEnabled()) {
|
||||
String s;
|
||||
if (keepalive > 0) {
|
||||
s = "for " + keepalive + " " + tunit;
|
||||
} else {
|
||||
s = "indefinitely";
|
||||
}
|
||||
this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
|
||||
}
|
||||
} finally {
|
||||
this.pool.release(entry, managedConn.isMarkedReusable());
|
||||
}
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown(long waitMs) throws IOException {
|
||||
this.log.debug("Connection manager is shutting down");
|
||||
this.pool.shutdown(waitMs);
|
||||
this.log.debug("Connection manager shut down");
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
try {
|
||||
shutdown(2000);
|
||||
} catch (IOException ex) {
|
||||
this.log.error("I/O exception while shutting down connection pool", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
|
||||
}
|
||||
pool.closeIdle(idleTimeout, tunit);
|
||||
}
|
||||
|
||||
public void closeExpiredConnections() {
|
||||
this.log.debug("Closing expired connections");
|
||||
this.pool.closeExpired();
|
||||
}
|
||||
|
||||
public void setMaxTotal(int max) {
|
||||
this.pool.setMaxTotal(max);
|
||||
}
|
||||
|
||||
public void setDefaultMaxPerRoute(int max) {
|
||||
this.pool.setDefaultMaxPerRoute(max);
|
||||
}
|
||||
|
||||
public void setMaxPerRoute(final HttpRoute route, int max) {
|
||||
this.pool.setMaxPerRoute(route, max);
|
||||
}
|
||||
|
||||
public PoolStats getTotalStats() {
|
||||
return this.pool.getTotalStats();
|
||||
}
|
||||
|
||||
public PoolStats getStats(final HttpRoute route) {
|
||||
return this.pool.getStats(route);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -57,8 +57,11 @@ import org.apache.http.params.HttpParams;
|
|||
* already been allocated {@link IllegalStateException} is thrown.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link SingleConnectionManager}
|
||||
*/
|
||||
@ThreadSafe
|
||||
@Deprecated
|
||||
public class SingleClientConnManager implements ClientConnectionManager {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
|
|
@ -53,6 +53,8 @@ import org.apache.http.impl.conn.IdleConnectionHandler;
|
|||
* Don't use <code>synchronized</code> for that purpose!
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link org.apache.http.pool.AbstractConnPool}
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
|
|
|
@ -29,7 +29,6 @@ package org.apache.http.impl.conn.tsccm;
|
|||
import java.lang.ref.ReferenceQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
|
@ -39,8 +38,10 @@ import org.apache.http.impl.conn.AbstractPoolEntry;
|
|||
* Basic implementation of a connection pool entry.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link org.apache.http.pool.PoolEntry}
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@Deprecated
|
||||
public class BasicPoolEntry extends AbstractPoolEntry {
|
||||
|
||||
private final long created;
|
||||
|
|
|
@ -26,24 +26,21 @@
|
|||
|
||||
package org.apache.http.impl.conn.tsccm;
|
||||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
import org.apache.http.annotation.Immutable;
|
||||
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A weak reference to a {@link BasicPoolEntry BasicPoolEntry}.
|
||||
* This reference explicitly keeps the planned route, so the connection
|
||||
* can be reclaimed if it is lost to garbage collection.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated do not use
|
||||
*/
|
||||
@Immutable
|
||||
@Deprecated
|
||||
public class BasicPoolEntryRef extends WeakReference<BasicPoolEntry> {
|
||||
|
||||
/** The planned route of the entry. */
|
||||
|
|
|
@ -36,7 +36,10 @@ import org.apache.http.impl.conn.AbstractPooledConnAdapter;
|
|||
* can be {@link #detach detach}ed to prevent further use on release.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated do not use
|
||||
*/
|
||||
@Deprecated
|
||||
public class BasicPooledConnAdapter extends AbstractPooledConnAdapter {
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,6 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.annotation.ThreadSafe;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
|
@ -63,10 +62,11 @@ import org.apache.http.params.HttpParams;
|
|||
* not via <code>synchronized</code> methods.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link org.apache.http.pool.AbstractConnPool}
|
||||
*/
|
||||
@ThreadSafe
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ConnPoolByRoute extends AbstractConnPool { //TODO: remove dependency on AbstractConnPool
|
||||
@Deprecated
|
||||
public class ConnPoolByRoute extends AbstractConnPool {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package org.apache.http.impl.conn.tsccm;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
|
@ -34,7 +35,10 @@ import org.apache.http.conn.ConnectionPoolTimeoutException;
|
|||
* Encapsulates a request for a {@link BasicPoolEntry}.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link Future}
|
||||
*/
|
||||
@Deprecated
|
||||
public interface PoolEntryRequest {
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,8 +31,6 @@ import java.util.ListIterator;
|
|||
import java.util.Queue;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.conn.OperatedClientConnection;
|
||||
|
@ -47,8 +45,10 @@ import org.apache.http.util.LangUtils;
|
|||
* containing pool takes care of synchronization.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link org.apache.http.pool.AbstractConnPool}
|
||||
*/
|
||||
@NotThreadSafe // e.g. numEntries, freeEntries,
|
||||
@Deprecated
|
||||
public class RouteSpecificPool {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.apache.http.conn.ManagedClientConnection;
|
|||
import org.apache.http.conn.OperatedClientConnection;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.impl.conn.DefaultClientConnectionOperator;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.impl.conn.SchemeRegistryFactory;
|
||||
|
||||
/**
|
||||
|
@ -62,8 +63,11 @@ import org.apache.http.impl.conn.SchemeRegistryFactory;
|
|||
* can be adjusted using HTTP parameters.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated use {@link PoolingClientConnectionManager}
|
||||
*/
|
||||
@ThreadSafe
|
||||
@Deprecated
|
||||
public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
||||
|
||||
private final Log log;
|
||||
|
|
|
@ -30,8 +30,6 @@ package org.apache.http.impl.conn.tsccm;
|
|||
import java.util.Date;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
/**
|
||||
* Represents a thread waiting for a connection.
|
||||
* This class implements throwaway objects. It is instantiated whenever
|
||||
|
@ -44,8 +42,10 @@ import org.apache.http.annotation.NotThreadSafe;
|
|||
*
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated do not use
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@Deprecated
|
||||
public class WaitingThread {
|
||||
|
||||
/** The condition on which the thread is waiting. */
|
||||
|
|
|
@ -26,17 +26,16 @@
|
|||
|
||||
package org.apache.http.impl.conn.tsccm;
|
||||
|
||||
import org.apache.http.annotation.NotThreadSafe;
|
||||
|
||||
// TODO - only called from ConnPoolByRoute currently; consider adding it as nested class
|
||||
/**
|
||||
* A simple class that can interrupt a {@link WaitingThread}.
|
||||
*
|
||||
* Must be called with the pool lock held.
|
||||
*
|
||||
* @since 4.0
|
||||
*
|
||||
* @deprecated do not use
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@Deprecated
|
||||
public class WaitingThreadAborter {
|
||||
|
||||
private WaitingThread waitingThread;
|
||||
|
|
|
@ -89,7 +89,7 @@ public class TestURLEncodedUtils {
|
|||
|
||||
@Test
|
||||
public void testParseEntity () throws Exception {
|
||||
final StringEntity entity = new StringEntity("Name1=Value1", null);
|
||||
final StringEntity entity = new StringEntity("Name1=Value1");
|
||||
|
||||
entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
|
||||
final List <NameValuePair> result = URLEncodedUtils.parse(entity);
|
||||
|
@ -142,7 +142,7 @@ public class TestURLEncodedUtils {
|
|||
|
||||
@Test
|
||||
public void testIsEncoded () throws Exception {
|
||||
final StringEntity entity = new StringEntity("...", null);
|
||||
final StringEntity entity = new StringEntity("...");
|
||||
|
||||
entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
|
||||
Assert.assertTrue(URLEncodedUtils.isEncoded(entity));
|
||||
|
|
|
@ -40,12 +40,12 @@ import org.apache.http.HttpResponse;
|
|||
import org.apache.http.MalformedChunkCodingException;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.entity.BasicHttpEntity;
|
||||
import org.apache.http.impl.DefaultHttpServerConnection;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.localserver.ServerTestBase;
|
||||
import org.apache.http.pool.PoolStats;
|
||||
import org.apache.http.protocol.ExecutionContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
|
@ -55,20 +55,15 @@ import org.junit.Test;
|
|||
|
||||
public class TestConnectionAutoRelease extends ServerTestBase {
|
||||
|
||||
private ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg) {
|
||||
if (schreg == null)
|
||||
schreg = supportedSchemes;
|
||||
return new ThreadSafeClientConnManager(schreg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseOnEntityConsumeContent() throws Exception {
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
// Zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
PoolStats stats = mgr.getTotalStats();
|
||||
Assert.assertEquals(0, stats.getAvailable());
|
||||
|
||||
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||
|
||||
|
@ -90,7 +85,8 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
EntityUtils.consume(e);
|
||||
|
||||
// Expect one connection in the pool
|
||||
Assert.assertEquals(1, mgr.getConnectionsInPool());
|
||||
stats = mgr.getTotalStats();
|
||||
Assert.assertEquals(1, stats.getAvailable());
|
||||
|
||||
// Make sure one connection is available
|
||||
connreq = mgr.requestConnection(new HttpRoute(target), null);
|
||||
|
@ -103,12 +99,13 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
|
||||
@Test
|
||||
public void testReleaseOnEntityWriteTo() throws Exception {
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
// Zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
PoolStats stats = mgr.getTotalStats();
|
||||
Assert.assertEquals(0, stats.getAvailable());
|
||||
|
||||
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||
|
||||
|
@ -131,7 +128,8 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
e.writeTo(outsteam);
|
||||
|
||||
// Expect one connection in the pool
|
||||
Assert.assertEquals(1, mgr.getConnectionsInPool());
|
||||
stats = mgr.getTotalStats();
|
||||
Assert.assertEquals(1, stats.getAvailable());
|
||||
|
||||
// Make sure one connection is available
|
||||
connreq = mgr.requestConnection(new HttpRoute(target), null);
|
||||
|
@ -144,12 +142,13 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
|
||||
@Test
|
||||
public void testReleaseOnAbort() throws Exception {
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
// Zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
PoolStats stats = mgr.getTotalStats();
|
||||
Assert.assertEquals(0, stats.getAvailable());
|
||||
|
||||
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||
|
||||
|
@ -171,7 +170,7 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
httpget.abort();
|
||||
|
||||
// Expect zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
|
||||
// Make sure one connection is available
|
||||
connreq = mgr.requestConnection(new HttpRoute(target), null);
|
||||
|
@ -217,12 +216,12 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
|
||||
});
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
// Zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
|
||||
DefaultHttpClient client = new DefaultHttpClient(mgr);
|
||||
|
||||
|
@ -250,7 +249,7 @@ public class TestConnectionAutoRelease extends ServerTestBase {
|
|||
}
|
||||
|
||||
// Expect zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
|
||||
// Make sure one connection is available
|
||||
connreq = mgr.requestConnection(new HttpRoute(target), null);
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.apache.http.conn.scheme.Scheme;
|
|||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.scheme.SchemeSocketFactory;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.localserver.LocalTestServer;
|
||||
import org.apache.http.localserver.RandomHandler;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
|
@ -99,7 +99,7 @@ public class TestConnectionReuse {
|
|||
SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||
supportedSchemes.register(new Scheme("http", 80, sf));
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
|
||||
mgr.setMaxTotal(5);
|
||||
mgr.setDefaultMaxPerRoute(5);
|
||||
|
||||
|
@ -130,7 +130,7 @@ public class TestConnectionReuse {
|
|||
}
|
||||
|
||||
// Expect some connection in the pool
|
||||
Assert.assertTrue(mgr.getConnectionsInPool() > 0);
|
||||
Assert.assertTrue(mgr.getTotalStats().getAvailable() > 0);
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class TestConnectionReuse {
|
|||
SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||
supportedSchemes.register(new Scheme("http", 80, sf));
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
|
||||
mgr.setMaxTotal(5);
|
||||
mgr.setDefaultMaxPerRoute(5);
|
||||
|
||||
|
@ -201,7 +201,7 @@ public class TestConnectionReuse {
|
|||
}
|
||||
|
||||
// Expect zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ public class TestConnectionReuse {
|
|||
SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||
supportedSchemes.register(new Scheme("http", 80, sf));
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
|
||||
mgr.setMaxTotal(5);
|
||||
mgr.setDefaultMaxPerRoute(5);
|
||||
|
||||
|
@ -262,7 +262,7 @@ public class TestConnectionReuse {
|
|||
}
|
||||
|
||||
// Expect zero connections in the pool
|
||||
Assert.assertEquals(0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ public class TestConnectionReuse {
|
|||
SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
|
||||
supportedSchemes.register(new Scheme("http", 80, sf));
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
|
||||
mgr.setMaxTotal(1);
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
|
||||
|
@ -303,13 +303,13 @@ public class TestConnectionReuse {
|
|||
HttpResponse response = client.execute(target, new HttpGet("/random/2000"));
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
Assert.assertEquals(1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
|
||||
|
||||
response = client.execute(target, new HttpGet("/random/2000"));
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
Assert.assertEquals(1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, localServer.getAcceptedConnectionCount());
|
||||
|
||||
// Now sleep for 1.1 seconds and let the timeout do its work
|
||||
|
@ -317,7 +317,7 @@ public class TestConnectionReuse {
|
|||
response = client.execute(target, new HttpGet("/random/2000"));
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
Assert.assertEquals(1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(2, localServer.getAcceptedConnectionCount());
|
||||
|
||||
// Do another request just under the 1 second limit & make
|
||||
|
@ -326,7 +326,7 @@ public class TestConnectionReuse {
|
|||
response = client.execute(target, new HttpGet("/random/2000"));
|
||||
EntityUtils.consume(response.getEntity());
|
||||
|
||||
Assert.assertEquals(1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(2, localServer.getAcceptedConnectionCount());
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ import org.apache.http.conn.scheme.Scheme;
|
|||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.localserver.ServerTestBase;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.protocol.HttpRequestHandler;
|
||||
|
@ -188,7 +188,7 @@ public class TestContentCodings extends ServerTestBase {
|
|||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
|
||||
cm.setMaxTotal(clients);
|
||||
|
||||
final HttpClient httpClient = new DefaultHttpClient(cm);
|
||||
|
|
|
@ -60,8 +60,7 @@ import org.apache.http.conn.scheme.SchemeRegistry;
|
|||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.conn.ClientConnAdapterMockup;
|
||||
import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.localserver.BasicServerTestBase;
|
||||
import org.apache.http.localserver.LocalTestServer;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
|
@ -141,7 +140,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
|||
SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
SingleClientConnManager conMan = new SingleClientConnManager(registry);
|
||||
PoolingClientConnectionManager conMan = new PoolingClientConnectionManager(registry);
|
||||
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
||||
final CountDownLatch getLatch = new CountDownLatch(1);
|
||||
final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
||||
|
@ -182,7 +181,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
|||
SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
SingleClientConnManager conMan = new SingleClientConnManager(registry);
|
||||
PoolingClientConnectionManager conMan = new PoolingClientConnectionManager(registry);
|
||||
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
|
||||
final CountDownLatch getLatch = new CountDownLatch(1);
|
||||
final CountDownLatch startLatch = new CountDownLatch(1);
|
||||
|
@ -283,35 +282,6 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
|||
Assert.assertSame(conMan.allocatedConnection, conMan.releasedConnection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestFailureReleasesConnection() throws Exception {
|
||||
this.localServer.register("*", new ThrowingService());
|
||||
|
||||
SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
ConnMan3 conMan = new ConnMan3(registry);
|
||||
DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
|
||||
HttpGet httpget = new HttpGet("/a");
|
||||
|
||||
try {
|
||||
client.execute(getServerHttp(), httpget);
|
||||
Assert.fail("expected IOException");
|
||||
} catch (IOException expected) {}
|
||||
|
||||
Assert.assertNotNull(conMan.allocatedConnection);
|
||||
Assert.assertSame(conMan.allocatedConnection, conMan.releasedConnection);
|
||||
}
|
||||
|
||||
private static class ThrowingService implements HttpRequestHandler {
|
||||
public void handle(
|
||||
final HttpRequest request,
|
||||
final HttpResponse response,
|
||||
final HttpContext context) throws HttpException, IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class BasicService implements HttpRequestHandler {
|
||||
public void handle(final HttpRequest request,
|
||||
final HttpResponse response,
|
||||
|
@ -340,7 +310,7 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
private static class ConnMan4 extends ThreadSafeClientConnManager {
|
||||
private static class ConnMan4 extends PoolingClientConnectionManager {
|
||||
private final CountDownLatch connLatch;
|
||||
private final CountDownLatch awaitLatch;
|
||||
|
||||
|
@ -387,29 +357,6 @@ public class TestDefaultClientRequestDirector extends BasicServerTestBase {
|
|||
}
|
||||
|
||||
|
||||
private static class ConnMan3 extends SingleClientConnManager {
|
||||
private ManagedClientConnection allocatedConnection;
|
||||
private ManagedClientConnection releasedConnection;
|
||||
|
||||
public ConnMan3(SchemeRegistry schreg) {
|
||||
super(schreg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManagedClientConnection getConnection(HttpRoute route, Object state) {
|
||||
allocatedConnection = super.getConnection(route, state);
|
||||
return allocatedConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {
|
||||
releasedConnection = conn;
|
||||
super.releaseConnection(conn, validDuration, timeUnit);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static class ConnMan2 implements ClientConnectionManager {
|
||||
|
||||
private ManagedClientConnection allocatedConnection;
|
||||
|
|
|
@ -38,8 +38,7 @@ import org.apache.http.conn.ConnectTimeoutException;
|
|||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.scheme.SchemeSocketFactory;
|
||||
import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
@ -49,26 +48,16 @@ import org.junit.Test;
|
|||
public class TestRequestRetryHandler {
|
||||
|
||||
@Test(expected=UnknownHostException.class)
|
||||
public void testUseRetryHandlerInConnectionTimeOutWithThreadSafeClientConnManager()
|
||||
public void testUseRetryHandlerInConnectionTimeOut()
|
||||
throws Exception {
|
||||
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory()));
|
||||
ClientConnectionManager connManager = new ThreadSafeClientConnManager(schemeRegistry);
|
||||
ClientConnectionManager connManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||
|
||||
assertOnRetry(connManager);
|
||||
}
|
||||
|
||||
@Test(expected=UnknownHostException.class)
|
||||
public void testUseRetryHandlerInConnectionTimeOutWithSingleClientConnManager()
|
||||
throws Exception {
|
||||
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, new OppsieSchemeSocketFactory()));
|
||||
ClientConnectionManager connManager = new SingleClientConnManager(schemeRegistry);
|
||||
assertOnRetry(connManager);
|
||||
}
|
||||
|
||||
protected void assertOnRetry(ClientConnectionManager connManager) throws Exception {
|
||||
DefaultHttpClient client = new DefaultHttpClient(connManager);
|
||||
TestHttpRequestRetryHandler testRetryHandler = new TestHttpRequestRetryHandler();
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.http.client.UserTokenHandler;
|
|||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.localserver.ServerTestBase;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
|
@ -85,7 +85,7 @@ public class TestStatefulConnManagement extends ServerTestBase {
|
|||
HttpParams params = new BasicHttpParams();
|
||||
HttpConnectionParams.setConnectionTimeout(params, 10);
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(supportedSchemes);
|
||||
mgr.setMaxTotal(workerCount);
|
||||
mgr.setDefaultMaxPerRoute(workerCount);
|
||||
|
||||
|
@ -207,7 +207,7 @@ public class TestStatefulConnManagement extends ServerTestBase {
|
|||
this.localServer.register("*", new SimpleService());
|
||||
|
||||
// We build a client with 2 max active // connections, and 2 max per route.
|
||||
ThreadSafeClientConnManager connMngr = new ThreadSafeClientConnManager(supportedSchemes);
|
||||
PoolingClientConnectionManager connMngr = new PoolingClientConnectionManager(supportedSchemes);
|
||||
connMngr.setMaxTotal(maxConn);
|
||||
connMngr.setDefaultMaxPerRoute(maxConn);
|
||||
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.conn.ClientConnectionOperator;
|
||||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
import org.apache.http.conn.params.ConnPerRoute;
|
||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.impl.conn.tsccm.BasicPoolEntry;
|
||||
import org.apache.http.impl.conn.tsccm.ConnPoolByRoute;
|
||||
import org.apache.http.impl.conn.tsccm.PoolEntryRequest;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ConnPoolBench {
|
||||
|
||||
private final static HttpRoute ROUTE = new HttpRoute(new HttpHost("localhost"));
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
int c = 200;
|
||||
long reps = 100000;
|
||||
oldPool(c, reps);
|
||||
newPool(c, reps);
|
||||
}
|
||||
|
||||
public static void newPool(int c, long reps) throws Exception {
|
||||
Log log = LogFactory.getLog(ConnPoolBench.class);
|
||||
|
||||
HttpConnPool pool = new HttpConnPool(log, c, c * 10, -1, TimeUnit.MILLISECONDS);
|
||||
|
||||
WorkerThread1[] workers = new WorkerThread1[c];
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i] = new WorkerThread1(pool, reps);
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].join();
|
||||
}
|
||||
long finish = System.currentTimeMillis();
|
||||
float totalTimeSec = (float) (finish - start) / 1000;
|
||||
System.out.print("Concurrency level:\t");
|
||||
System.out.println(c);
|
||||
System.out.print("Total operations:\t");
|
||||
System.out.println(c * reps);
|
||||
System.out.print("Time taken for tests:\t");
|
||||
System.out.print(totalTimeSec);
|
||||
System.out.println(" seconds");
|
||||
}
|
||||
|
||||
static void oldPool(int c, long reps) throws Exception {
|
||||
ClientConnectionOperator operator = new DefaultClientConnectionOperator(
|
||||
SchemeRegistryFactory.createDefault());
|
||||
ConnPerRoute connPerRoute = new ConnPerRouteBean(c);
|
||||
ConnPoolByRoute pool = new ConnPoolByRoute(operator, connPerRoute, c * 10);
|
||||
|
||||
WorkerThread2[] workers = new WorkerThread2[c];
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i] = new WorkerThread2(pool, reps);
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].start();
|
||||
}
|
||||
for (int i = 0; i < workers.length; i++) {
|
||||
workers[i].join();
|
||||
}
|
||||
long finish = System.currentTimeMillis();
|
||||
float totalTimeSec = (float) (finish - start) / 1000;
|
||||
System.out.print("Concurrency level:\t");
|
||||
System.out.println(c);
|
||||
System.out.print("Total operations:\t");
|
||||
System.out.println(c * reps);
|
||||
System.out.print("Time taken for tests:\t");
|
||||
System.out.print(totalTimeSec);
|
||||
System.out.println(" seconds");
|
||||
}
|
||||
|
||||
static class WorkerThread1 extends Thread {
|
||||
|
||||
private final HttpConnPool pool;
|
||||
private final long reps;
|
||||
|
||||
WorkerThread1(final HttpConnPool pool, final long reps) {
|
||||
super();
|
||||
this.pool = pool;
|
||||
this.reps = reps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (long c = 0; c < this.reps; c++) {
|
||||
Future<HttpPoolEntry> future = this.pool.lease(ROUTE, null);
|
||||
try {
|
||||
HttpPoolEntry entry = future.get(-1, TimeUnit.MILLISECONDS);
|
||||
this.pool.release(entry, true);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TimeoutException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class WorkerThread2 extends Thread {
|
||||
|
||||
private final ConnPoolByRoute pool;
|
||||
private final long reps;
|
||||
|
||||
WorkerThread2(final ConnPoolByRoute pool, final long reps) {
|
||||
super();
|
||||
this.pool = pool;
|
||||
this.reps = reps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (long c = 0; c < this.reps; c++) {
|
||||
PoolEntryRequest request = this.pool.requestPoolEntry(ROUTE, null);
|
||||
BasicPoolEntry entry;
|
||||
try {
|
||||
entry = request.getPoolEntry(-1, TimeUnit.MILLISECONDS);
|
||||
this.pool.freeEntry(entry, true, -1, TimeUnit.MILLISECONDS);
|
||||
} catch (ConnectionPoolTimeoutException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -111,10 +111,9 @@ public class ExecReqThread extends GetConnThread {
|
|||
|
||||
doConsumeResponse();
|
||||
|
||||
} catch (Throwable dart) {
|
||||
dart.printStackTrace(System.out);
|
||||
} catch (Exception ex) {
|
||||
if (exception != null)
|
||||
exception = dart;
|
||||
exception = ex;
|
||||
|
||||
} finally {
|
||||
conn_manager.releaseConnection(connection, -1, null);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class GetConnThread extends Thread {
|
|||
protected final ClientConnectionRequest conn_request;
|
||||
|
||||
protected volatile ManagedClientConnection connection;
|
||||
protected volatile Throwable exception;
|
||||
protected volatile Exception exception;
|
||||
|
||||
/**
|
||||
* Creates a new thread for requesting a connection from the given manager.
|
||||
|
@ -81,8 +81,8 @@ public class GetConnThread extends Thread {
|
|||
try {
|
||||
connection = conn_request.getConnection
|
||||
(conn_timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (Throwable dart) {
|
||||
exception = dart;
|
||||
} catch (Exception ex) {
|
||||
exception = ex;
|
||||
}
|
||||
// terminate
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class TestDefaultResponseParser {
|
|||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
|
||||
HttpMessageParser parser = new DefaultResponseParser(
|
||||
HttpMessageParser<HttpResponse> parser = new DefaultResponseParser(
|
||||
inbuffer,
|
||||
BasicLineParser.DEFAULT,
|
||||
new DefaultHttpResponseFactory(),
|
||||
|
@ -91,7 +91,7 @@ public class TestDefaultResponseParser {
|
|||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
|
||||
HttpMessageParser parser = new DefaultResponseParser(
|
||||
HttpMessageParser<HttpResponse> parser = new DefaultResponseParser(
|
||||
inbuffer,
|
||||
BasicLineParser.DEFAULT,
|
||||
new DefaultHttpResponseFactory(),
|
||||
|
@ -110,7 +110,7 @@ public class TestDefaultResponseParser {
|
|||
public void testResponseParsingNoResponse() throws Exception {
|
||||
HttpParams params = new BasicHttpParams();
|
||||
SessionInputBuffer inbuffer = new SessionInputBufferMockup("", "US-ASCII", params);
|
||||
HttpMessageParser parser = new DefaultResponseParser(
|
||||
HttpMessageParser<HttpResponse> parser = new DefaultResponseParser(
|
||||
inbuffer,
|
||||
BasicLineParser.DEFAULT,
|
||||
new DefaultHttpResponseFactory(),
|
||||
|
@ -127,7 +127,7 @@ public class TestDefaultResponseParser {
|
|||
"a lot more garbage\r\n";
|
||||
HttpParams params = new BasicHttpParams();
|
||||
SessionInputBuffer inbuffer = new SessionInputBufferMockup(s, "US-ASCII", params);
|
||||
HttpMessageParser parser = new DefaultResponseParser(
|
||||
HttpMessageParser<HttpResponse> parser = new DefaultResponseParser(
|
||||
inbuffer,
|
||||
BasicLineParser.DEFAULT,
|
||||
new DefaultHttpResponseFactory(),
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.apache.http.conn.scheme.PlainSocketFactory;
|
|||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.localserver.LocalTestServer;
|
||||
import org.apache.http.localserver.ServerTestBase;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
|
@ -69,7 +68,7 @@ public class TestIdleConnectionEviction extends ServerTestBase {
|
|||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
|
||||
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
|
||||
cm.setDefaultMaxPerRoute(10);
|
||||
cm.setMaxTotal(50);
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.http.util.EntityUtils;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@Deprecated
|
||||
public class TestSCMWithServer extends ServerTestBase {
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,10 +36,6 @@ import org.apache.http.conn.ClientConnectionRequest;
|
|||
import org.apache.http.conn.ConnectionPoolTimeoutException;
|
||||
import org.apache.http.conn.ManagedClientConnection;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
|
@ -68,21 +64,6 @@ public class TestTSCCMNoServer {
|
|||
return connRequest.getConnection(0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to instantiate a <code>ThreadSafeClientConnManager</code>.
|
||||
*
|
||||
* @param schreg the scheme registry, or
|
||||
* <code>null</code> to use defaults
|
||||
*
|
||||
* @return a connection manager to test
|
||||
*/
|
||||
public ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg) {
|
||||
if (schreg == null)
|
||||
schreg = createSchemeRegistry();
|
||||
return new ThreadSafeClientConnManager(schreg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates default parameters.
|
||||
*
|
||||
|
@ -97,37 +78,15 @@ public class TestTSCCMNoServer {
|
|||
return params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a default scheme registry.
|
||||
*
|
||||
* @return the default scheme registry
|
||||
*/
|
||||
public SchemeRegistry createSchemeRegistry() {
|
||||
|
||||
SchemeRegistry schreg = new SchemeRegistry();
|
||||
schreg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
return schreg;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
SchemeRegistry schreg = createSchemeRegistry();
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(schreg);
|
||||
Assert.assertNotNull(mgr);
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testIllegalConstructor() {
|
||||
new ThreadSafeClientConnManager(null);
|
||||
new PoolingClientConnectionManager(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testGetConnection()
|
||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
|
||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||
HttpRoute route = new HttpRoute(target, null, false);
|
||||
|
@ -152,7 +111,7 @@ public class TestTSCCMNoServer {
|
|||
public void testMaxConnTotal()
|
||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(2);
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
|
||||
|
@ -198,11 +157,11 @@ public class TestTSCCMNoServer {
|
|||
HttpHost target3 = new HttpHost("www.test3.invalid", 80, "http");
|
||||
HttpRoute route3 = new HttpRoute(target3, null, false);
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(100);
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
mgr.setMaxForRoute(route2, 2);
|
||||
mgr.setMaxForRoute(route3, 3);
|
||||
mgr.setMaxPerRoute(route2, 2);
|
||||
mgr.setMaxPerRoute(route3, 3);
|
||||
|
||||
// route 3, limit 3
|
||||
ManagedClientConnection conn1 =
|
||||
|
@ -264,7 +223,7 @@ public class TestTSCCMNoServer {
|
|||
@Test
|
||||
public void testReleaseConnection() throws Exception {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(3);
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
|
||||
|
@ -333,31 +292,26 @@ public class TestTSCCMNoServer {
|
|||
public void testDeleteClosedConnections()
|
||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
|
||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||
HttpRoute route = new HttpRoute(target, null, false);
|
||||
|
||||
ManagedClientConnection conn = getConnection(mgr, route);
|
||||
|
||||
Assert.assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 1);
|
||||
Assert.assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(route), 1);
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getLeased());
|
||||
conn.markReusable();
|
||||
mgr.releaseConnection(conn, -1, null);
|
||||
|
||||
Assert.assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 1);
|
||||
Assert.assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(route), 1);
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getAvailable());
|
||||
|
||||
// this implicitly deletes them
|
||||
mgr.closeIdleConnections(0L, TimeUnit.MILLISECONDS);
|
||||
|
||||
Assert.assertEquals("connectionsInPool",
|
||||
mgr.getConnectionsInPool(), 0);
|
||||
Assert.assertEquals("connectionsInPool(host)",
|
||||
mgr.getConnectionsInPool(route), 0);
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(0, mgr.getStats(route).getAvailable());
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
@ -366,7 +320,7 @@ public class TestTSCCMNoServer {
|
|||
public void testShutdown() throws Exception {
|
||||
// 3.x: TestHttpConnectionManager.testShutdown
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
mgr.setDefaultMaxPerRoute(1);
|
||||
|
||||
|
@ -397,7 +351,7 @@ public class TestTSCCMNoServer {
|
|||
Assert.assertNotNull("thread should have gotten an exception",
|
||||
gct.getException());
|
||||
Assert.assertSame("thread got wrong exception",
|
||||
IllegalStateException.class, gct.getException().getClass());
|
||||
InterruptedException.class, gct.getException().getClass());
|
||||
|
||||
// the manager is down, we should not be able to get a connection
|
||||
try {
|
||||
|
@ -412,7 +366,7 @@ public class TestTSCCMNoServer {
|
|||
public void testInterruptThread() throws Exception {
|
||||
// 3.x: TestHttpConnectionManager.testWaitingThreadInterrupted
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||
|
@ -457,7 +411,7 @@ public class TestTSCCMNoServer {
|
|||
public void testReusePreference() throws Exception {
|
||||
// 3.x: TestHttpConnectionManager.testHostReusePreference
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
HttpHost target1 = new HttpHost("www.test1.invalid", 80, "http");
|
||||
|
@ -496,7 +450,7 @@ public class TestTSCCMNoServer {
|
|||
|
||||
@Test
|
||||
public void testAbortAfterRequestStarts() throws Exception {
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||
|
@ -536,7 +490,7 @@ public class TestTSCCMNoServer {
|
|||
|
||||
@Test
|
||||
public void testAbortBeforeRequestStarts() throws Exception {
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
package org.apache.http.impl.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
@ -55,7 +54,6 @@ import org.apache.http.conn.scheme.PlainSocketFactory;
|
|||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.scheme.SchemeSocketFactory;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.localserver.ServerTestBase;
|
||||
import org.apache.http.message.BasicHttpRequest;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -72,25 +70,6 @@ import org.junit.Test;
|
|||
*/
|
||||
public class TestTSCCMWithServer extends ServerTestBase {
|
||||
|
||||
/**
|
||||
* Helper to instantiate a <code>ThreadSafeClientConnManager</code>.
|
||||
*
|
||||
* @param schreg the scheme registry, or
|
||||
* <code>null</code> to use defaults
|
||||
*
|
||||
* @return a connection manager to test
|
||||
*/
|
||||
public ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg) {
|
||||
return createTSCCM(schreg, -1, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public ThreadSafeClientConnManager createTSCCM(SchemeRegistry schreg,
|
||||
long connTTL, TimeUnit connTTLTimeUnit) {
|
||||
if (schreg == null)
|
||||
schreg = supportedSchemes;
|
||||
return new ThreadSafeClientConnManager(schreg, connTTL, connTTLTimeUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests executing several requests in parallel.
|
||||
*/
|
||||
|
@ -100,7 +79,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
|
||||
final int COUNT = 8; // adjust to execute more requests
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(COUNT/2);
|
||||
mgr.setDefaultMaxPerRoute(COUNT/2);
|
||||
|
||||
|
@ -173,7 +152,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
@Test
|
||||
public void testReleaseConnection() throws Exception {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
|
@ -259,7 +238,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
@Test
|
||||
public void testReleaseConnectionWithTimeLimits() throws Exception {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
|
@ -361,7 +340,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
@Test
|
||||
public void testCloseExpiredIdleConnections() throws Exception {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
|
@ -370,27 +349,28 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
ManagedClientConnection conn = getConnection(mgr, route);
|
||||
conn.open(route, httpContext, defaultParams);
|
||||
|
||||
Assert.assertEquals("connectionsInPool", 1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 1, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getLeased());
|
||||
conn.markReusable();
|
||||
mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS);
|
||||
|
||||
// Released, still active.
|
||||
Assert.assertEquals("connectionsInPool", 1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 1, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getAvailable());
|
||||
|
||||
mgr.closeExpiredConnections();
|
||||
|
||||
// Time has not expired yet.
|
||||
Assert.assertEquals("connectionsInPool", 1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 1, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getAvailable());
|
||||
|
||||
Thread.sleep(150);
|
||||
|
||||
mgr.closeExpiredConnections();
|
||||
|
||||
// Time expired now, connections are destroyed.
|
||||
Assert.assertEquals("connectionsInPool", 0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 0, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(0, mgr.getStats(route).getAvailable());
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
@ -398,7 +378,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
@Test
|
||||
public void testCloseExpiredTTLConnections() throws Exception {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null, 100, TimeUnit.MILLISECONDS);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(
|
||||
SchemeRegistryFactory.createDefault(), 100, TimeUnit.MILLISECONDS);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
|
@ -407,28 +388,29 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
ManagedClientConnection conn = getConnection(mgr, route);
|
||||
conn.open(route, httpContext, defaultParams);
|
||||
|
||||
Assert.assertEquals("connectionsInPool", 1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 1, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getLeased());
|
||||
// Release, let remain idle for forever
|
||||
conn.markReusable();
|
||||
mgr.releaseConnection(conn, -1, TimeUnit.MILLISECONDS);
|
||||
|
||||
// Released, still active.
|
||||
Assert.assertEquals("connectionsInPool", 1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 1, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getAvailable());
|
||||
|
||||
mgr.closeExpiredConnections();
|
||||
|
||||
// Time has not expired yet.
|
||||
Assert.assertEquals("connectionsInPool", 1, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 1, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(1, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(1, mgr.getStats(route).getAvailable());
|
||||
|
||||
Thread.sleep(150);
|
||||
|
||||
mgr.closeExpiredConnections();
|
||||
|
||||
// TTL expired now, connections are destroyed.
|
||||
Assert.assertEquals("connectionsInPool", 0, mgr.getConnectionsInPool());
|
||||
Assert.assertEquals("connectionsInPool(host)", 0, mgr.getConnectionsInPool(route));
|
||||
Assert.assertEquals(0, mgr.getTotalStats().getAvailable());
|
||||
Assert.assertEquals(0, mgr.getStats(route).getAvailable());
|
||||
|
||||
mgr.shutdown();
|
||||
}
|
||||
|
@ -440,7 +422,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
@Test
|
||||
public void testReleaseConnectionOnAbort() throws Exception {
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager();
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
|
@ -473,8 +455,8 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
}
|
||||
|
||||
// abort the connection
|
||||
Assert.assertTrue(conn instanceof AbstractClientConnAdapter);
|
||||
((AbstractClientConnAdapter) conn).abortConnection();
|
||||
Assert.assertTrue(conn instanceof ManagedClientConnection);
|
||||
((ManagedClientConnection) conn).abortConnection();
|
||||
|
||||
// the connection is expected to be released back to the manager
|
||||
conn = getConnection(mgr, route, 5L, TimeUnit.SECONDS);
|
||||
|
@ -484,56 +466,6 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
mgr.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests GC of an unreferenced connection manager.
|
||||
*/
|
||||
@Test
|
||||
public void testConnectionManagerGC() throws Exception {
|
||||
// 3.x: TestHttpConnectionManager.testDroppedThread
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(null);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
final HttpRoute route = new HttpRoute(target, null, false);
|
||||
final int rsplen = 8;
|
||||
final String uri = "/random/" + rsplen;
|
||||
|
||||
HttpRequest request =
|
||||
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
|
||||
|
||||
ManagedClientConnection conn = getConnection(mgr, route);
|
||||
conn.open(route, httpContext, defaultParams);
|
||||
|
||||
// a new context is created for each testcase, no need to reset
|
||||
HttpResponse response = Helper.execute(request, conn, target,
|
||||
httpExecutor, httpProcessor, defaultParams, httpContext);
|
||||
EntityUtils.toByteArray(response.getEntity());
|
||||
|
||||
// release connection after marking it for re-use
|
||||
conn.markReusable();
|
||||
mgr.releaseConnection(conn, -1, null);
|
||||
|
||||
// We now have a manager with an open connection in its pool.
|
||||
// We drop all potential hard reference to the manager and check
|
||||
// whether it is GCed. Internal references might prevent that
|
||||
// if set up incorrectly.
|
||||
// Note that we still keep references to the connection wrapper
|
||||
// we got from the manager, directly as well as in the request
|
||||
// and in the context. The manager will be GCed only if the
|
||||
// connection wrapper is truly detached.
|
||||
WeakReference<ThreadSafeClientConnManager> wref =
|
||||
new WeakReference<ThreadSafeClientConnManager>(mgr);
|
||||
mgr = null;
|
||||
|
||||
// Java does not guarantee that this will trigger the GC, but
|
||||
// it does in the test environment. GC is asynchronous, so we
|
||||
// need to give the garbage collector some time afterwards.
|
||||
System.gc();
|
||||
Thread.sleep(1000);
|
||||
|
||||
Assert.assertNull("TSCCM not garbage collected", wref.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbortDuringConnecting() throws Exception {
|
||||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||
|
@ -543,14 +475,13 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(scheme);
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(registry);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(registry);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
final HttpRoute route = new HttpRoute(target, null, false);
|
||||
|
||||
final ManagedClientConnection conn = getConnection(mgr, route);
|
||||
Assert.assertTrue(conn instanceof AbstractClientConnAdapter);
|
||||
|
||||
final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
|
||||
Thread abortingThread = new Thread(new Runnable() {
|
||||
|
@ -595,14 +526,13 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(scheme);
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(registry);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(registry);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
final HttpRoute route = new HttpRoute(target, null, false);
|
||||
|
||||
final ManagedClientConnection conn = getConnection(mgr, route);
|
||||
Assert.assertTrue(conn instanceof AbstractClientConnAdapter);
|
||||
|
||||
final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
|
||||
Thread abortingThread = new Thread(new Runnable() {
|
||||
|
@ -649,14 +579,13 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
SchemeRegistry registry = new SchemeRegistry();
|
||||
registry.register(scheme);
|
||||
|
||||
ThreadSafeClientConnManager mgr = createTSCCM(registry);
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(registry);
|
||||
mgr.setMaxTotal(1);
|
||||
|
||||
final HttpHost target = getServerHttp();
|
||||
final HttpRoute route = new HttpRoute(target, null, false);
|
||||
|
||||
final ManagedClientConnection conn = getConnection(mgr, route);
|
||||
Assert.assertTrue(conn instanceof AbstractClientConnAdapter);
|
||||
|
||||
final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
|
||||
Thread abortingThread = new Thread(new Runnable() {
|
||||
|
@ -704,7 +633,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
final CountDownLatch connectLatch = new CountDownLatch(1);
|
||||
final AtomicReference<StallingOperator> operatorRef = new AtomicReference<StallingOperator>();
|
||||
|
||||
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(supportedSchemes) {
|
||||
PoolingClientConnectionManager mgr = new PoolingClientConnectionManager() {
|
||||
@Override
|
||||
protected ClientConnectionOperator createConnectionOperator(
|
||||
SchemeRegistry schreg) {
|
||||
|
@ -719,7 +648,6 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
final HttpRoute route = new HttpRoute(target, null, false);
|
||||
|
||||
final ManagedClientConnection conn = getConnection(mgr, route);
|
||||
Assert.assertTrue(conn instanceof AbstractClientConnAdapter);
|
||||
|
||||
final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
|
||||
Thread abortingThread = new Thread(new Runnable() {
|
||||
|
@ -739,7 +667,6 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
conn.open(route, httpContext, defaultParams);
|
||||
Assert.fail("expected exception");
|
||||
} catch(IOException iox) {
|
||||
Assert.assertEquals("Request aborted", iox.getMessage());
|
||||
}
|
||||
|
||||
abortingThread.join(5000);
|
||||
|
@ -782,7 +709,7 @@ public class TestTSCCMWithServer extends ServerTestBase {
|
|||
void latch() {
|
||||
waitLatch.countDown();
|
||||
try {
|
||||
if (!continueLatch.await(1, TimeUnit.SECONDS))
|
||||
if (!continueLatch.await(60, TimeUnit.SECONDS))
|
||||
throw new RuntimeException("waited too long!");
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.concurrent.locks.Lock;
|
|||
/**
|
||||
* Thread to await something.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AwaitThread extends Thread {
|
||||
|
||||
protected final WaitingThread wait_object;
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.mockito.Mock;
|
|||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Deprecated
|
||||
public class TestConnPoolByRoute extends ServerTestBase {
|
||||
|
||||
private ConnPoolByRoute impl;
|
||||
|
@ -201,7 +202,6 @@ public class TestConnPoolByRoute extends ServerTestBase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void deprecatedConstructorIsStillSupported() {
|
||||
new ConnPoolByRoute(new DefaultClientConnectionOperator(supportedSchemes),
|
||||
new BasicHttpParams());
|
||||
|
@ -310,8 +310,7 @@ public class TestConnPoolByRoute extends ServerTestBase {
|
|||
useMockOperator();
|
||||
BasicPoolEntry entry = impl.requestPoolEntry(route, new Object()).getPoolEntry(-1, TimeUnit.MILLISECONDS);
|
||||
impl.freeEntry(entry, true, Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
Thread.sleep(1);
|
||||
impl.closeIdleConnections(3, TimeUnit.MILLISECONDS);
|
||||
impl.closeIdleConnections(3, TimeUnit.SECONDS);
|
||||
verify(mockConnection, never()).close();
|
||||
}
|
||||
|
||||
|
@ -369,9 +368,9 @@ public class TestConnPoolByRoute extends ServerTestBase {
|
|||
}
|
||||
});
|
||||
t.start();
|
||||
Thread.sleep(5);
|
||||
Thread.sleep(100);
|
||||
impl.freeEntry(entry, true, 1000, TimeUnit.MILLISECONDS);
|
||||
Thread.sleep(5);
|
||||
Thread.sleep(100);
|
||||
assertTrue(f.flag);
|
||||
}
|
||||
|
||||
|
@ -393,9 +392,9 @@ public class TestConnPoolByRoute extends ServerTestBase {
|
|||
}
|
||||
});
|
||||
t.start();
|
||||
Thread.sleep(5);
|
||||
Thread.sleep(100);
|
||||
impl.freeEntry(entry, true, 1000, TimeUnit.MILLISECONDS);
|
||||
Thread.sleep(5);
|
||||
Thread.sleep(100);
|
||||
assertTrue(f.flag);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.junit.Test;
|
|||
* satisfying the condition.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public class TestSpuriousWakeup {
|
||||
|
||||
public final static
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.junit.Test;
|
|||
/**
|
||||
* Tests for <code>WaitingThread</code>.
|
||||
*/
|
||||
@Deprecated
|
||||
public class TestWaitingThread {
|
||||
|
||||
public final static
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -68,7 +68,7 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<httpcore.version>4.1.1</httpcore.version>
|
||||
<httpcore.version>4.2-alpha1</httpcore.version>
|
||||
<commons-logging.version>1.1.1</commons-logging.version>
|
||||
<commons-codec.version>1.4</commons-codec.version>
|
||||
<ehcache.version>2.2.0</ehcache.version>
|
||||
|
|
Loading…
Reference in New Issue