You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/02/09 18:14:24 UTC
svn commit: r505377 - in
/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http:
conn/ManagedClientConnection.java conn/RouteTracker.java
impl/conn/ThreadSafeClientConnManager.java
Author: rolandw
Date: Fri Feb 9 09:14:22 2007
New Revision: 505377
URL: http://svn.apache.org/viewvc?view=rev&rev=505377
Log:
revised route tracking in managed connection
Modified:
jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/ManagedClientConnection.java
jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/RouteTracker.java
jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/ManagedClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/ManagedClientConnection.java?view=diff&rev=505377&r1=505376&r2=505377
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/ManagedClientConnection.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/ManagedClientConnection.java Fri Feb 9 09:14:22 2007
@@ -68,6 +68,16 @@
/**
+ * Obtains the current route of this connection.
+ *
+ * @return the route established so far, or
+ * <code>null</code> if not connected
+ */
+ HttpRoute getRoute()
+ ;
+
+
+ /**
* Opens this connection according to the given route.
*
* @param route the route along which to open. It will be opened
Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/RouteTracker.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/RouteTracker.java?view=diff&rev=505377&r1=505376&r2=505377
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/RouteTracker.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/conn/RouteTracker.java Fri Feb 9 09:14:22 2007
@@ -110,7 +110,7 @@
/**
* Tracks connecting to the target.
*
- * @param secure <code>true</code> if the connection is secure,
+ * @param secure <code>true</code> if the route is secure,
* <code>false</code> otherwise
*/
public final void connectTarget(boolean secure) {
@@ -123,20 +123,26 @@
* Tracks connecting to a proxy.
*
* @param proxy the proxy connected to
+ * @param secure <code>true</code> if the route is secure,
+ * <code>false</code> otherwise
*/
- public final void connectProxy(HttpHost proxy) {
+ public final void connectProxy(HttpHost proxy, boolean secure) {
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
this.connected = true;
this.proxyHost = proxy;
+ this.secure = secure;
}
/**
* Tracks tunnelling through the proxy.
+ *
+ * @param secure <code>true</code> if the route is secure,
+ * <code>false</code> otherwise
*/
- public final void establishTunnel() {
+ public final void establishTunnel(boolean secure) {
if (this.proxyHost == null) {
throw new IllegalStateException("No tunnel without proxy.");
}
@@ -144,6 +150,7 @@
throw new IllegalStateException("No tunnel unless connected.");
}
this.tunnelled = true;
+ this.secure = secure;
}
Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java?view=diff&rev=505377&r1=505376&r2=505377
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/conn/ThreadSafeClientConnManager.java Fri Feb 9 09:14:22 2007
@@ -47,6 +47,8 @@
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ConnectionPoolTimeoutException;
+import org.apache.http.conn.HttpRoute;
+import org.apache.http.conn.RouteTracker;
import org.apache.http.conn.HostConfiguration;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.OperatedClientConnection;
@@ -817,7 +819,7 @@
*/
private synchronized void deleteConnection(TrackingPoolEntry entry) {
- HostConfiguration route = entry.route;
+ HostConfiguration route = entry.tracker.toHostConfig();
if (LOG.isDebugEnabled()) {
LOG.debug("Reclaiming connection, hostConfig=" + route);
@@ -1084,14 +1086,8 @@
/** The route for which this entry gets allocated. */
private HostConfiguration plannedRoute;
- /** The host configuration part of the tracked route. */
- private HostConfiguration route;
-
- /** The tunnel created flag part of the tracked route. */
- private boolean tunnelled;
-
- /** The layered flag part of the tracked route. */
- private boolean layered;
+ /** The tracked route, or <code>null</code> before tracking starts. */
+ private RouteTracker tracker;
/** The connection manager. */
private ThreadSafeClientConnManager manager;
@@ -1112,8 +1108,8 @@
*/
private TrackingPoolEntry(OperatedClientConnection occ) {
this.connection = occ;
- this.route = null;
- this.tunnelled = false;
+ //@@@ pass planned route to the constructor?
+ this.tracker = null;
this.manager = ThreadSafeClientConnManager.this;
this.reference = new WeakReference(this, REFERENCE_QUEUE);
}
@@ -1141,6 +1137,9 @@
throw new IllegalArgumentException
("Parameters must not be null.");
}
+ if ((this.tracker != null) && this.tracker.isConnected()) {
+ throw new IllegalStateException("Connection already open.");
+ }
// - collect the arguments
// - call the operator
@@ -1155,6 +1154,8 @@
}
final HttpHost proxy = route.getProxyHost();
+ //@@@ verify against planned route?
+
if (LOG.isDebugEnabled()) {
if (proxy == null) {
LOG.debug("Open connection to " + target);
@@ -1164,12 +1165,18 @@
}
}
+ this.tracker = new RouteTracker
+ (route.getHost(), route.getLocalAddress());
+
ThreadSafeClientConnManager.this.connectionOperator.openConnection
(this.connection,
(proxy != null) ? proxy : target,
context, params);
- this.route = route;
+ if (proxy == null)
+ this.tracker.connectTarget(this.connection.isSecure());
+ else
+ this.tracker.connectProxy(proxy, this.connection.isSecure());
} // open
@@ -1193,17 +1200,18 @@
("Parameters must not be null.");
}
- if (route.getProxyHost() == null) {
- throw new IllegalStateException("No proxy in route.");
+ //@@@ check for proxy in planned route?
+ if ((this.tracker == null) || !this.tracker.isConnected()) {
+ throw new IllegalStateException("Connection not open.");
}
- if (tunnelled) {
+ if (this.tracker.isTunnelled()) {
throw new IllegalStateException
("Connection is already tunnelled.");
}
- this.connection.update(null, route.getHost(),
+ this.connection.update(null, tracker.getTargetHost(),
secure, params);
- tunnelled = true;
+ this.tracker.establishTunnel(secure);
} // tunnelCreated
@@ -1225,13 +1233,17 @@
("Parameters must not be null.");
}
- if (!this.tunnelled) {
+ if ((this.tracker == null) || !this.tracker.isConnected()) {
+ throw new IllegalStateException("Connection not open.");
+ }
+ if (!this.tracker.isTunnelled()) {
+ //@@@ allow this?
throw new IllegalStateException
("Protocol layering without a tunnel not supported.");
}
- if (this.layered) {
+ if (this.tracker.isLayered()) {
throw new IllegalStateException
- ("Protocol already layered.");
+ ("Multiple protocol layering not supported.");
}
// - collect the arguments
@@ -1240,7 +1252,7 @@
// In this order, we can be sure that only a successful
// layering on top of the connection will be tracked.
- final HttpHost target = route.getHost();
+ final HttpHost target = tracker.getTargetHost();
if (LOG.isDebugEnabled()) {
LOG.debug("Layer protocol on connection to " + target);
@@ -1250,7 +1262,7 @@
.updateSecureConnection(this.connection, target,
context, params);
- this.layered = true;
+ this.tracker.layerProtocol(this.connection.isSecure());
} // layerProtocol
@@ -1261,9 +1273,8 @@
* in both cases. This method should be called regardless of
* whether the close or shutdown succeeds or triggers an error.
*/
- private void closing() {
- route = null;
- tunnelled = false;
+ private void closing() {
+ tracker = null;
}
} // class TrackingPoolEntry
@@ -1321,6 +1332,14 @@
this.poolEntry = null;
}
+
+ // non-javadoc, see interface ManagedHttpConnection
+ public HttpRoute getRoute() {
+
+ assertAttached();
+ return (poolEntry.tracker == null) ?
+ null : poolEntry.tracker.toRoute();
+ }
// non-javadoc, see interface ManagedHttpConnection
public void open(HostConfiguration route,