[prev in list] [next in list] [prev in thread] [next in thread]
List: httpcomponents-commits
Subject: svn commit: r639506 - in /httpcomponents/httpclient/trunk/module-client/src:
From: olegk () apache ! org
Date: 2008-03-21 0:40:59
Message-ID: 20080321004104.757101A9832 () eris ! apache ! org
[Download RAW message or body]
Author: olegk
Date: Thu Mar 20 17:40:54 2008
New Revision: 639506
URL: http://svn.apache.org/viewvc?rev=639506&view=rev
Log:
HTTPCLIENT-734: API refinements
Modified:
httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java
httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionRequest.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/util/InetAddressUtils.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/GetConnThread.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
Modified: httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ex \
amples/org/apache/http/examples/conn/ManagerConnectDirect.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectDirect.java \
Thu Mar 20 17:40:54 2008 @@ -39,6 +39,7 @@
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.PlainSocketFactory;
import org.apache.http.conn.Scheme;
@@ -106,7 +107,8 @@
(target, null, supportedSchemes.getScheme(target).isLayered());
System.out.println("requesting connection for " + route);
- ManagedClientConnection conn = clcm.getConnection(route);
+ ClientConnectionRequest connRequest = clcm.requestConnection(route);
+ ManagedClientConnection conn = connRequest.getConnection(0, null);
try {
System.out.println("opening connection");
conn.open(route, ctx, getParams());
Modified: httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ex \
amples/org/apache/http/examples/conn/ManagerConnectProxy.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/conn/ManagerConnectProxy.java \
Thu Mar 20 17:40:54 2008 @@ -39,6 +39,7 @@
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.PlainSocketFactory;
import org.apache.http.conn.Scheme;
@@ -112,7 +113,8 @@
supportedSchemes.getScheme(target).isLayered());
System.out.println("requesting connection for " + route);
- ManagedClientConnection conn = clcm.getConnection(route);
+ ClientConnectionRequest connRequest = clcm.requestConnection(route);
+ ManagedClientConnection conn = connRequest.getConnection(0, null);
try {
System.out.println("opening connection");
conn.open(route, ctx, getParams());
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/client/methods/AbortableHttpRequest.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/AbortableHttpRequest.java \
Thu Mar 20 17:40:54 2008 @@ -31,6 +31,7 @@
package org.apache.http.client.methods;
+import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionReleaseTrigger;
/**
@@ -45,6 +46,8 @@
* @since 4.0
*/
public interface AbortableHttpRequest {
+
+ void setConnectionRequest(ClientConnectionRequest connRequest);
void setReleaseTrigger(ConnectionReleaseTrigger releaseTrigger);
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/client/methods/HttpRequestBase.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpRequestBase.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/methods/HttpRequestBase.java \
Thu Mar 20 17:40:54 2008 @@ -33,9 +33,12 @@
import java.io.IOException;
import java.net.URI;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
+import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionReleaseTrigger;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.message.BasicRequestLine;
@@ -52,12 +55,18 @@
*/
abstract class HttpRequestBase extends AbstractHttpMessage
implements HttpUriRequest, AbortableHttpRequest {
+
+ private final Lock abortLock;
+
+ private volatile boolean aborted;
private URI uri;
+ private ClientConnectionRequest connRequest;
private ConnectionReleaseTrigger releaseTrigger;
public HttpRequestBase() {
super();
+ this.abortLock = new ReentrantLock();
}
public abstract String getMethod();
@@ -88,17 +97,50 @@
this.uri = uri;
}
+ public void setConnectionRequest(final ClientConnectionRequest connRequest) {
+ if (this.aborted) {
+ return;
+ }
+ this.abortLock.lock();
+ try {
+ this.connRequest = connRequest;
+ } finally {
+ this.abortLock.unlock();
+ }
+ }
+
public void setReleaseTrigger(final ConnectionReleaseTrigger releaseTrigger) {
- this.releaseTrigger = releaseTrigger;
+ if (this.aborted) {
+ return;
+ }
+ this.abortLock.lock();
+ try {
+ this.connRequest = null;
+ this.releaseTrigger = releaseTrigger;
+ } finally {
+ this.abortLock.unlock();
+ }
}
public void abort() {
- if (this.releaseTrigger != null) {
- try {
- this.releaseTrigger.abortConnection();
- } catch (IOException ex) {
- // ignore
+ if (this.aborted) {
+ return;
+ }
+ this.aborted = true;
+ this.abortLock.lock();
+ try {
+ if (this.connRequest != null) {
+ this.connRequest.abortRequest();
+ }
+ if (this.releaseTrigger != null) {
+ try {
+ this.releaseTrigger.abortConnection();
+ } catch (IOException ex) {
+ // ignore
+ }
}
+ } finally {
+ this.abortLock.unlock();
}
}
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/conn/ClientConnectionManager.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java \
Thu Mar 20 17:40:54 2008 @@ -75,56 +75,11 @@
/**
- * Obtains a connection.
- * This method will block until a connection becomes available
- * or the connection manager is {@link #shutdown shut down}.
- *
- * @param route where the connection should point to
- *
- * @return a connection that can be used to communicate
- * along the given route
- *
- * @throws InterruptedException
- * if the calling thread is interrupted while waiting
- */
- ManagedClientConnection getConnection(HttpRoute route)
- throws InterruptedException
- ;
-
-
- /**
- * Obtains a connection within a given time.
- * This method will block until a connection becomes available,
- * the timeout expires, or the connection manager is
- * {@link #shutdown shut down}.
- * Timeouts are handled with millisecond precision
- *
- * @param route where the connection should point to
- * @param timeout the timeout, 0 or negative for no timeout
- * @param tunit the unit for the <code>timeout</code>,
- * may be <code>null</code> only if there is no timeout
- *
- * @return a connection that can be used to communicate
- * along the given route
- *
- * @throws ConnectionPoolTimeoutException
- * in case of a timeout
- * @throws InterruptedException
- * if the calling thread is interrupted while waiting
- */
- ManagedClientConnection getConnection(HttpRoute route,
- long timeout,
- TimeUnit tunit)
- throws ConnectionPoolTimeoutException, InterruptedException
- ;
-
-
- /**
* Returns a new {@link ClientConnectionRequest}, from which a
* {@link ManagedClientConnection} can be obtained, or the request can be
* aborted.
*/
- ClientConnectionRequest newConnectionRequest()
+ ClientConnectionRequest requestConnection(HttpRoute route)
;
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/conn/ClientConnectionRequest.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionRequest.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionRequest.java \
Thu Mar 20 17:40:54 2008 @@ -20,7 +20,6 @@
* before this began, an {@link InterruptedException} will
* be thrown.
*
- * @param route where the connection should point to
* @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the <code>timeout</code>,
* may be <code>null</code> only if there is no timeout
@@ -33,9 +32,8 @@
* @throws InterruptedException
* if the calling thread is interrupted while waiting
*/
- ManagedClientConnection getConnection(HttpRoute route, long timeout,
- TimeUnit unit) throws InterruptedException,
- ConnectionPoolTimeoutException;
+ ManagedClientConnection getConnection(long timeout, TimeUnit unit)
+ throws InterruptedException, ConnectionPoolTimeoutException;
/**
* Aborts the call to {@link #getConnection(HttpRoute, long, TimeUnit)},
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/util/InetAddressUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/conn/util/InetAddressUtils.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/util/InetAddressUtils.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/util/InetAddressUtils.java \
Thu Mar 20 17:40:54 2008 @@ -35,6 +35,9 @@
public class InetAddressUtils {
+ private InetAddressUtils() {
+ }
+
private static final Pattern IPV4_PATTERN =
Pattern.compile(
"^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java \
Thu Mar 20 17:40:54 2008 @@ -70,7 +70,6 @@
import org.apache.http.conn.BasicManagedEntity;
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.conn.Scheme;
import org.apache.http.conn.routing.BasicRouteDirector;
@@ -289,19 +288,18 @@
HttpRoute route = roureq.getRoute();
- ReleaseTrigger releaseTrigger = new ReleaseTrigger();
- if (orig instanceof AbortableHttpRequest) {
- ((AbortableHttpRequest) orig).setReleaseTrigger(releaseTrigger);
- }
-
// Allocate connection if needed
if (managedConn == null) {
- ClientConnectionRequest connectionRequest = \
allocateConnection();
- releaseTrigger.setClientConnectionRequest(connectionRequest);
- managedConn = connectionRequest.getConnection(route, timeout, \
TimeUnit.MILLISECONDS); + ClientConnectionRequest connRequest = \
connManager.requestConnection(route); + if (orig instanceof \
AbortableHttpRequest) { + ((AbortableHttpRequest) \
orig).setConnectionRequest(connRequest); + }
+ managedConn = connRequest.getConnection(timeout, \
TimeUnit.MILLISECONDS); }
- releaseTrigger.setConnectionReleaseTrigger(managedConn);
+ if (orig instanceof AbortableHttpRequest) {
+ ((AbortableHttpRequest) orig).setReleaseTrigger(managedConn);
+ }
// Reopen connection if needed
if (!managedConn.isOpen()) {
@@ -495,15 +493,6 @@
/**
- * Obtains a connection request, from which the connection can be retrieved.
- */
- protected ClientConnectionRequest allocateConnection() {
- return connManager.newConnectionRequest();
-
- } // allocateConnection
-
-
- /**
* Establishes the target route.
*
* @param route the route to establish
@@ -1019,70 +1008,5 @@
authState.setAuthScope(authScope);
authState.setCredentials(creds);
}
-
- /**
- * A {@link ConnectionReleaseTrigger} that delegates either a
- * {@link ClientConnectionRequest} or another ConnectionReleaseTrigger
- * for aborting.
- */
- private static class ReleaseTrigger implements ConnectionReleaseTrigger {
- private boolean aborted = false;
- private ClientConnectionRequest delegateRequest;
- private ConnectionReleaseTrigger delegateTrigger;
-
- void setConnectionReleaseTrigger(ConnectionReleaseTrigger releaseTrigger) \
throws IOException {
- synchronized(this) {
- if(aborted) {
- throw new IOException("already aborted!");
- }
- this.delegateTrigger = releaseTrigger;
- this.delegateRequest = null;
- }
- }
-
- void setClientConnectionRequest(ClientConnectionRequest connectionRequest) \
throws IOException {
- synchronized(this) {
- if(aborted) {
- throw new IOException("already aborted");
- }
- this.delegateRequest = connectionRequest;
- this.delegateTrigger = null;
- }
- }
-
-
- public void abortConnection() throws IOException {
- ConnectionReleaseTrigger releaseTrigger;
- ClientConnectionRequest connectionRequest;
- synchronized(this) {
- if(aborted)
- throw new IOException("already aborted");
- aborted = true;
- // capture references within lock
- releaseTrigger = delegateTrigger;
- connectionRequest = delegateRequest;
- }
-
- if(connectionRequest != null)
- connectionRequest.abortRequest();
-
- if(releaseTrigger != null) {
- releaseTrigger.abortConnection();
- }
- }
-
- public void releaseConnection() throws IOException {
- ConnectionReleaseTrigger releaseTrigger;
- synchronized(this) {
- releaseTrigger = delegateTrigger; // capture reference within lock
- }
-
- if(releaseTrigger != null)
- releaseTrigger.releaseConnection();
- }
- }
-
-
-
} // class DefaultClientRequestDirector
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/impl/conn/SingleClientConnManager.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/SingleClientConnManager.java \
Thu Mar 20 17:40:54 2008 @@ -178,25 +178,7 @@
}
- /**
- * Obtains a connection.
- * Maps to {@link #getConnection(HttpRoute) getConnection(HttpRoute)}
- * since this manager never blocks the caller.
- *
- * @param route where the connection should point to
- * @param timeout ignored
- * @param tunit ignored
- *
- * @return a connection that can be used to communicate
- * along the given route
- */
- public final ManagedClientConnection getConnection(HttpRoute route,
- long timeout,
- TimeUnit tunit) {
- return getConnection(route);
- }
-
- public final ClientConnectionRequest newConnectionRequest() {
+ public final ClientConnectionRequest requestConnection(final HttpRoute route) {
return new ClientConnectionRequest() {
@@ -204,7 +186,7 @@
// Nothing to abort, since requests are immediate.
}
- public ManagedClientConnection getConnection(HttpRoute route,
+ public ManagedClientConnection getConnection(
long timeout, TimeUnit tunit) {
return SingleClientConnManager.this.getConnection(route);
}
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/ma \
in/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.java \
Thu Mar 20 17:40:54 2008 @@ -147,36 +147,7 @@
}
- // non-javadoc, see interface ClientConnectionManager
- public final ManagedClientConnection getConnection(HttpRoute route)
- throws InterruptedException {
-
- while (true) {
- try {
- return getConnection(route, 0, null);
- } catch (ConnectionPoolTimeoutException e) {
- // We'll go ahead and log this, but it should never happen.
- // These exceptions are only thrown when the timeout occurs
- // and since we have no timeout, it doesn't happen.
- LOG.debug
- ("Unexpected exception while waiting for connection.", e);
- //@@@ throw RuntimeException or Error to indicate the problem?
- }
- }
- }
-
-
- // non-javadoc, see interface ClientConnectionManager
- public final ManagedClientConnection getConnection(HttpRoute route,
- long timeout,
- TimeUnit tunit)
- throws ConnectionPoolTimeoutException, InterruptedException {
-
- return newConnectionRequest().getConnection(route, timeout, tunit);
- }
-
-
- public ClientConnectionRequest newConnectionRequest() {
+ public ClientConnectionRequest requestConnection(final HttpRoute route) {
final PoolEntryRequest poolRequest = connectionPool.newPoolEntryRequest();
@@ -186,7 +157,7 @@
poolRequest.abortRequest();
}
- public ManagedClientConnection getConnection(HttpRoute route,
+ public ManagedClientConnection getConnection(
long timeout, TimeUnit tunit) throws InterruptedException,
ConnectionPoolTimeoutException {
if (route == null) {
@@ -301,21 +272,6 @@
public HttpParams getParams() {
return this.params;
}
-
-
- /* *
- * Assigns {@link HttpParams parameters} for this
- * connection manager.
- * /
- //@@@ this is basically a no-op unless we pass the params to the pool
- public void setParams(final HttpParams params) {
- if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null");
- }
- this.params = params;
- }
- */
-
} // class ThreadSafeClientConnManager
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/te \
st/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java \
Thu Mar 20 17:40:54 2008 @@ -184,6 +184,7 @@
}
private static class ConnMan2 implements ClientConnectionManager {
+
private ManagedClientConnection allocatedConnection;
private ManagedClientConnection releasedConnection;
@@ -204,12 +205,15 @@
throw new UnsupportedOperationException("just a mockup");
}
- public ClientConnectionRequest newConnectionRequest() {
+ public ClientConnectionRequest requestConnection(final HttpRoute route) {
+
return new ClientConnectionRequest() {
+
public void abortRequest() {
throw new UnsupportedOperationException("just a mockup");
}
- public ManagedClientConnection getConnection(HttpRoute route,
+
+ public ManagedClientConnection getConnection(
long timeout, TimeUnit unit)
throws InterruptedException,
ConnectionPoolTimeoutException {
@@ -267,14 +271,17 @@
throw new UnsupportedOperationException("just a mockup");
}
- public ClientConnectionRequest newConnectionRequest() {
+ public ClientConnectionRequest requestConnection(final HttpRoute route) {
+
final Thread currentThread = Thread.currentThread();
+
return new ClientConnectionRequest() {
+
public void abortRequest() {
currentThread.interrupt();
}
- public ManagedClientConnection getConnection(HttpRoute route,
+ public ManagedClientConnection getConnection(
long timeout, TimeUnit tunit)
throws InterruptedException,
ConnectionPoolTimeoutException {
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/GetConnThread.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/te \
st/java/org/apache/http/impl/conn/GetConnThread.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/GetConnThread.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/GetConnThread.java \
Thu Mar 20 17:40:54 2008 @@ -60,7 +60,7 @@
*/
public GetConnThread(ClientConnectionManager mgr,
HttpRoute route, long timeout) {
- this(mgr.newConnectionRequest(), route, timeout);
+ this(mgr.requestConnection(route), route, timeout);
}
/**
@@ -83,7 +83,7 @@
public void run() {
try {
connection = conn_request.getConnection
- (conn_route, conn_timeout, TimeUnit.MILLISECONDS);
+ (conn_timeout, TimeUnit.MILLISECONDS);
} catch (Throwable dart) {
exception = dart;
}
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/te \
st/java/org/apache/http/impl/conn/TestTSCCMNoServer.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMNoServer.java \
Thu Mar 20 17:40:54 2008 @@ -38,6 +38,7 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpVersion;
+import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.ManagedClientConnection;
@@ -73,6 +74,22 @@
}
+ private static ManagedClientConnection getConnection(
+ final ClientConnectionManager mgr,
+ final HttpRoute route,
+ long timeout,
+ TimeUnit unit) throws ConnectionPoolTimeoutException, \
InterruptedException { + ClientConnectionRequest connRequest = \
mgr.requestConnection(route); + return connRequest.getConnection(timeout, \
unit); + }
+
+ private static ManagedClientConnection getConnection(
+ final ClientConnectionManager mgr,
+ final HttpRoute route) throws ConnectionPoolTimeoutException, \
InterruptedException { + ClientConnectionRequest connRequest = \
mgr.requestConnection(route); + return connRequest.getConnection(0, null);
+ }
+
/**
* Helper to instantiate a <code>ThreadSafeClientConnManager</code>.
*
@@ -160,13 +177,14 @@
} // testConstructor
- public void testGetConnection() throws InterruptedException {
+ public void testGetConnection()
+ throws InterruptedException, ConnectionPoolTimeoutException {
ThreadSafeClientConnManager mgr = createTSCCM(null, null);
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
HttpRoute route = new HttpRoute(target, null, false);
- ManagedClientConnection conn = mgr.getConnection(route);
+ ManagedClientConnection conn = getConnection(mgr, route);
assertNotNull(conn);
assertNull(conn.getRoute());
assertFalse(conn.isOpen());
@@ -174,7 +192,7 @@
mgr.releaseConnection(conn);
try {
- conn = mgr.getConnection(null);
+ conn = getConnection(mgr, null);
fail("null route not detected");
} catch (IllegalArgumentException iax) {
// expected
@@ -187,7 +205,8 @@
// several other tests here rely on timeout behavior
- public void testMaxConnTotal() throws InterruptedException {
+ public void testMaxConnTotal()
+ throws InterruptedException, ConnectionPoolTimeoutException {
HttpParams params = createDefaultParams();
HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost(params, 1);
@@ -200,14 +219,14 @@
HttpHost target2 = new HttpHost("www.test2.invalid", 80, "http");
HttpRoute route2 = new HttpRoute(target2, null, false);
- ManagedClientConnection conn1 = mgr.getConnection(route1);
+ ManagedClientConnection conn1 = getConnection(mgr, route1);
assertNotNull(conn1);
- ManagedClientConnection conn2 = mgr.getConnection(route2);
+ ManagedClientConnection conn2 = getConnection(mgr, route2);
assertNotNull(conn2);
try {
// this should fail quickly, connection has not been released
- mgr.getConnection(route2, 100L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route2, 100L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -219,7 +238,7 @@
// there should be a connection available now
try {
- conn2 = mgr.getConnection(route2, 100L, TimeUnit.MILLISECONDS);
+ conn2 = getConnection(mgr, route2, 100L, TimeUnit.MILLISECONDS);
} catch (ConnectionPoolTimeoutException cptx) {
cptx.printStackTrace();
fail("connection should have been available: " + cptx);
@@ -248,38 +267,38 @@
// route 3, limit 3
ManagedClientConnection conn1 =
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
assertNotNull(conn1);
ManagedClientConnection conn2 =
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
assertNotNull(conn2);
ManagedClientConnection conn3 =
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
assertNotNull(conn3);
try {
// should fail quickly, connection has not been released
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
}
// route 2, limit 2
- conn1 = mgr.getConnection(route2, 10L, TimeUnit.MILLISECONDS);
- conn2 = mgr.getConnection(route2, 10L, TimeUnit.MILLISECONDS);
+ conn1 = getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
+ conn2 = getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
try {
// should fail quickly, connection has not been released
- mgr.getConnection(route2, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
}
// route 1, should use default limit of 1
- conn1 = mgr.getConnection(route1, 10L, TimeUnit.MILLISECONDS);
+ conn1 = getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
try {
// should fail quickly, connection has not been released
- mgr.getConnection(route1, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -321,11 +340,11 @@
// the first three allocations should pass
ManagedClientConnection conn1 =
- mgr.getConnection(route1, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
ManagedClientConnection conn2 =
- mgr.getConnection(route2, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
ManagedClientConnection conn3 =
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
assertNotNull(conn1);
assertNotNull(conn2);
assertNotNull(conn3);
@@ -333,19 +352,19 @@
// obtaining another connection for either of the three should fail
// this is somehow redundant with testMaxConnPerHost
try {
- mgr.getConnection(route1, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
}
try {
- mgr.getConnection(route2, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
}
try {
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -355,16 +374,16 @@
mgr.releaseConnection(conn2);
conn2 = null;
try {
- mgr.getConnection(route1, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route1, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
}
// this one succeeds
- conn2 = mgr.getConnection(route2, 10L, TimeUnit.MILLISECONDS);
+ conn2 = getConnection(mgr, route2, 10L, TimeUnit.MILLISECONDS);
assertNotNull(conn2);
try {
- mgr.getConnection(route3, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route3, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -374,14 +393,15 @@
}
- public void testDeleteClosedConnections() throws InterruptedException {
+ public void testDeleteClosedConnections()
+ throws InterruptedException, ConnectionPoolTimeoutException {
ThreadSafeClientConnManager mgr = createTSCCM(null, null);
HttpHost target = new HttpHost("www.test.invalid", 80, "http");
HttpRoute route = new HttpRoute(target, null, false);
- ManagedClientConnection conn = mgr.getConnection(route);
+ ManagedClientConnection conn = getConnection(mgr, route);
assertEquals("connectionsInPool",
mgr.getConnectionsInPool(), 1);
@@ -422,7 +442,7 @@
// on shutdown, the extra thread should get an exception
ManagedClientConnection conn =
- mgr.getConnection(route, 1L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
GetConnThread gct = new GetConnThread(mgr, route, 0L); // no timeout
gct.start();
Thread.sleep(100); // give extra thread time to block
@@ -446,7 +466,7 @@
// the manager is down, we should not be able to get a connection
try {
- conn = mgr.getConnection(route, 1L, TimeUnit.MILLISECONDS);
+ conn = getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
fail("shut-down manager does not raise exception");
} catch (IllegalStateException isx) {
// expected
@@ -467,7 +487,7 @@
// get the only connection, then start an extra thread
ManagedClientConnection conn =
- mgr.getConnection(route, 1L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 1L, TimeUnit.MILLISECONDS);
GetConnThread gct = new GetConnThread(mgr, route, 0L); // no timeout
gct.start();
Thread.sleep(100); // give extra thread time to block
@@ -486,7 +506,7 @@
// make sure the manager is still working
try {
- mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
fail("should have gotten a timeout");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -494,7 +514,7 @@
mgr.releaseConnection(conn);
// this time: no exception
- conn = mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
assertNotNull("should have gotten a connection", conn);
mgr.shutdown();
@@ -517,7 +537,7 @@
// get the only connection, then start two extra threads
ManagedClientConnection conn =
- mgr.getConnection(route1, 1L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route1, 1L, TimeUnit.MILLISECONDS);
GetConnThread gct1 = new GetConnThread(mgr, route1, 1000L);
GetConnThread gct2 = new GetConnThread(mgr, route2, 1000L);
@@ -554,8 +574,8 @@
HttpRoute route = new HttpRoute(target, null, false);
// get the only connection, then start an extra thread
- ManagedClientConnection conn = mgr.getConnection(route, 1L, \
TimeUnit.MILLISECONDS);
- ClientConnectionRequest request = mgr.newConnectionRequest();
+ ManagedClientConnection conn = getConnection(mgr, route, 1L, \
TimeUnit.MILLISECONDS); + ClientConnectionRequest request = \
mgr.requestConnection(route);
GetConnThread gct = new GetConnThread(request, route, 0L); // no timeout
gct.start();
Thread.sleep(100); // give extra thread time to block
@@ -571,7 +591,7 @@
// make sure the manager is still working
try {
- mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
fail("should have gotten a timeout");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -579,7 +599,7 @@
mgr.releaseConnection(conn);
// this time: no exception
- conn = mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
assertNotNull("should have gotten a connection", conn);
mgr.shutdown();
@@ -596,8 +616,8 @@
// get the only connection, then start an extra thread
- ManagedClientConnection conn = mgr.getConnection(route, 1L, \
TimeUnit.MILLISECONDS);
- ClientConnectionRequest request = mgr.newConnectionRequest();
+ ManagedClientConnection conn = getConnection(mgr, route, 1L, \
TimeUnit.MILLISECONDS); + ClientConnectionRequest request = \
mgr.requestConnection(route); request.abortRequest();
GetConnThread gct = new GetConnThread(request, route, 0L); // no timeout
@@ -613,7 +633,7 @@
// make sure the manager is still working
try {
- mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
fail("should have gotten a timeout");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -621,7 +641,7 @@
mgr.releaseConnection(conn);
// this time: no exception
- conn = mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
assertNotNull("should have gotten a connection", conn);
mgr.shutdown();
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/te \
st/java/org/apache/http/impl/conn/TestTSCCMWithServer.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java \
Thu Mar 20 17:40:54 2008 @@ -44,6 +44,8 @@
import org.apache.http.HttpVersion;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.SchemeRegistry;
import org.apache.http.conn.params.HttpConnectionManagerParams;
@@ -174,7 +176,22 @@
mgr.shutdown();
}
-
+ private static ManagedClientConnection getConnection(
+ final ClientConnectionManager mgr,
+ final HttpRoute route,
+ long timeout,
+ TimeUnit unit) throws ConnectionPoolTimeoutException, \
InterruptedException { + ClientConnectionRequest connRequest = \
mgr.requestConnection(route); + return connRequest.getConnection(timeout, \
unit); + }
+
+ private static ManagedClientConnection getConnection(
+ final ClientConnectionManager mgr,
+ final HttpRoute route) throws ConnectionPoolTimeoutException, \
InterruptedException { + ClientConnectionRequest connRequest = \
mgr.requestConnection(route); + return connRequest.getConnection(0, null);
+ }
+
/**
* Tests releasing and re-using a connection after a response is read.
*/
@@ -193,7 +210,7 @@
HttpRequest request =
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
- ManagedClientConnection conn = mgr.getConnection(route);
+ ManagedClientConnection conn = getConnection(mgr, route);
conn.open(route, httpContext, defaultParams);
// a new context is created for each testcase, no need to reset
@@ -212,7 +229,7 @@
// check that there is no auto-release by default
try {
// this should fail quickly, connection has not been released
- mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -221,7 +238,7 @@
// release connection without marking for re-use
// expect the next connection obtained to be closed
mgr.releaseConnection(conn);
- conn = mgr.getConnection(route);
+ conn = getConnection(mgr, route);
assertFalse("connection should have been closed", conn.isOpen());
// repeat the communication, no need to prepare the request again
@@ -242,7 +259,7 @@
// expect the next connection obtained to be open
conn.markReusable();
mgr.releaseConnection(conn);
- conn = mgr.getConnection(route);
+ conn = getConnection(mgr, route);
assertTrue("connection should have been open", conn.isOpen());
// repeat the communication, no need to prepare the request again
@@ -282,7 +299,7 @@
HttpRequest request =
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
- ManagedClientConnection conn = mgr.getConnection(route);
+ ManagedClientConnection conn = getConnection(mgr, route);
conn.open(route, httpContext, defaultParams);
// a new context is created for each testcase, no need to reset
@@ -296,7 +313,7 @@
// first check that we can't get another connection
try {
// this should fail quickly, connection has not been released
- mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
fail("ConnectionPoolTimeoutException should have been thrown");
} catch (ConnectionPoolTimeoutException e) {
// expected
@@ -315,7 +332,7 @@
Thread.sleep(1000);
assertNull("connection not garbage collected", wref.get());
- conn = mgr.getConnection(route, 10L, TimeUnit.MILLISECONDS);
+ conn = getConnection(mgr, route, 10L, TimeUnit.MILLISECONDS);
assertFalse("GCed connection not closed", conn.isOpen());
mgr.shutdown();
@@ -338,7 +355,7 @@
HttpRequest request =
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
- ManagedClientConnection conn = mgr.getConnection(route);
+ ManagedClientConnection conn = getConnection(mgr, route);
conn.open(route, httpContext, defaultParams);
// a new context is created for each testcase, no need to reset
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/te \
st/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java?rev=639506&r1=639505&r2=639506&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java \
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java \
Thu Mar 20 17:40:54 2008 @@ -39,6 +39,7 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpVersion;
+import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.PlainSocketFactory;
@@ -150,7 +151,8 @@
try {
// take out the only connection
- ManagedClientConnection conn = mgr.getConnection(ROUTE);
+ ClientConnectionRequest connRequest = mgr.requestConnection(ROUTE);
+ ManagedClientConnection conn = connRequest.getConnection(0, null);
assertNotNull(conn);
// send a thread waiting
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic