TSCCM uses pooled connection adapter
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@511479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e96c1657a7
commit
966e0fd8a6
|
@ -55,7 +55,7 @@ import org.apache.http.conn.SchemeRegistry;
|
|||
import org.apache.http.conn.SocketFactory;
|
||||
import org.apache.http.conn.PlainSocketFactory;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
//import org.apache.http.impl.conn.SimpleClientConnManager;
|
||||
//import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
|
@ -138,7 +138,7 @@ public class ClientExecuteDirect {
|
|||
|
||||
ClientConnectionManager ccm =
|
||||
new ThreadSafeClientConnManager(getParams(), supportedSchemes);
|
||||
// new SimpleClientConnManager(getParams(), supportedSchemes);
|
||||
// new SingleClientConnManager(getParams(), supportedSchemes);
|
||||
|
||||
DefaultHttpClient dhc =
|
||||
new DefaultHttpClient(getParams(), ccm, supportedSchemes);
|
||||
|
|
|
@ -57,7 +57,7 @@ import org.apache.http.conn.PlainSocketFactory;
|
|||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.HttpRoute;
|
||||
//import org.apache.http.impl.conn.SimpleClientConnManager;
|
||||
//import org.apache.http.impl.conn.SingleClientConnManager;
|
||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.RoutedRequest;
|
||||
|
@ -150,7 +150,7 @@ public class ClientExecuteProxy {
|
|||
|
||||
ClientConnectionManager ccm =
|
||||
new ThreadSafeClientConnManager(getParams(), supportedSchemes);
|
||||
// new SimpleClientConnManager(getParams(), supportedSchemes);
|
||||
// new SingleClientConnManager(getParams(), supportedSchemes);
|
||||
|
||||
DefaultHttpClient dhc =
|
||||
new DefaultHttpClient(getParams(), ccm, supportedSchemes);
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.apache.http.conn.OperatedClientConnection;
|
|||
/**
|
||||
* A pool entry for use by connection manager implementations.
|
||||
* Pool entries work in conjunction with an
|
||||
* {@link AbstractClientConnectionAdapter adapter}.
|
||||
* {@link AbstractClientConnAdapter adapter}.
|
||||
* The adapter is handed out to applications that obtain a connection.
|
||||
* The pool entry stores the underlying connection and tracks the
|
||||
* {@link HttpRoute route} established.
|
||||
|
@ -182,7 +182,7 @@ public abstract class AbstractPoolEntry {
|
|||
("Connection is already tunnelled.");
|
||||
}
|
||||
|
||||
// LOG.debug
|
||||
// LOG.debug?
|
||||
|
||||
this.connection.update(null, tracker.getTargetHost(),
|
||||
secure, params);
|
||||
|
|
|
@ -42,7 +42,8 @@ import org.apache.http.conn.ClientConnectionManager;
|
|||
|
||||
/**
|
||||
* Abstract adapter from pool {@link AbstractPoolEntry entries} to
|
||||
* {@link ManagedClientConnection managed} client connections.
|
||||
* {@link org.apache.http.conn.ManagedClientConnection managed}
|
||||
* client connections.
|
||||
* The connection in the pool entry is used to initialize the base class.
|
||||
* In addition, methods to establish a route are delegated to the
|
||||
* pool entry. {@link #shutdown shutdown} and {@link #close close}
|
||||
|
@ -69,18 +70,10 @@ public abstract class AbstractPooledConnAdapter
|
|||
*
|
||||
* @param manager the connection manager
|
||||
* @param entry the pool entry for the connection being wrapped
|
||||
* <!--
|
||||
* @ param plan the planned route, which will be used
|
||||
* to update the pool entry
|
||||
* -->
|
||||
*/
|
||||
protected AbstractPooledConnAdapter(ClientConnectionManager manager,
|
||||
AbstractPoolEntry entry
|
||||
//, HttpRoute plan
|
||||
) {
|
||||
AbstractPoolEntry entry) {
|
||||
super(manager, entry.connection);
|
||||
|
||||
//entry.plannedRoute = plan;
|
||||
this.poolEntry = entry;
|
||||
}
|
||||
|
||||
|
|
|
@ -349,7 +349,9 @@ public class ThreadSafeClientConnManager
|
|||
"connection not obtained from this manager.");
|
||||
}
|
||||
HttpConnectionAdapter hca = (HttpConnectionAdapter) conn;
|
||||
if ((hca.poolEntry != null) && (hca.poolEntry.manager != this)) {
|
||||
if ((hca.poolEntry != null) &&
|
||||
//@@@ (hca.poolEntry.manager != this) &&
|
||||
(hca.connManager != this)) {
|
||||
throw new IllegalArgumentException
|
||||
("Connection not obtained from this manager.");
|
||||
}
|
||||
|
@ -366,11 +368,9 @@ public class ThreadSafeClientConnManager
|
|||
// Consuming the response is handled outside in 4.0.
|
||||
|
||||
// make sure this connection will not be re-used
|
||||
//@@@ Can we set some kind of flag before shutting down?
|
||||
//@@@ If shutdown throws an exception, we can't be sure
|
||||
//@@@ that the connection will consider itself closed.
|
||||
// be nice and call close() rather than shutdown()?
|
||||
// I'm not in a nice mood today. -rolandw-
|
||||
// Shut down rather than close, we might have gotten here
|
||||
// because of a shutdown trigger.
|
||||
// Shutdown of the adapter also clears the tracked route.
|
||||
hca.shutdown();
|
||||
}
|
||||
} catch (IOException iox) {
|
||||
|
@ -379,7 +379,7 @@ public class ThreadSafeClientConnManager
|
|||
LOG.debug("Exception shutting down released connection.",
|
||||
iox);
|
||||
} finally {
|
||||
TrackingPoolEntry entry = hca.poolEntry;
|
||||
TrackingPoolEntry entry = (TrackingPoolEntry) hca.poolEntry;
|
||||
hca.detach();
|
||||
releasePoolEntry(entry);
|
||||
}
|
||||
|
@ -1126,6 +1126,7 @@ public class ThreadSafeClientConnManager
|
|||
private TrackingPoolEntry(OperatedClientConnection occ) {
|
||||
super(occ);
|
||||
//@@@ pass planned route to the constructor?
|
||||
//@@@ or update when the adapter is created?
|
||||
this.manager = ThreadSafeClientConnManager.this;
|
||||
this.reference = new WeakReference(this, REFERENCE_QUEUE);
|
||||
}
|
||||
|
@ -1145,12 +1146,7 @@ public class ThreadSafeClientConnManager
|
|||
* All connections given out by the manager are wrappers which
|
||||
* can be {@link #detach detach}ed to prevent further use on release.
|
||||
*/
|
||||
private class HttpConnectionAdapter
|
||||
extends AbstractClientConnAdapter {
|
||||
|
||||
/** The wrapped pool entry. */
|
||||
private TrackingPoolEntry poolEntry;
|
||||
|
||||
private class HttpConnectionAdapter extends AbstractPooledConnAdapter {
|
||||
|
||||
/**
|
||||
* Creates a new adapter.
|
||||
|
@ -1158,106 +1154,10 @@ public class ThreadSafeClientConnManager
|
|||
* @param entry the pool entry for the connection being wrapped
|
||||
*/
|
||||
protected HttpConnectionAdapter(TrackingPoolEntry entry) {
|
||||
super(ThreadSafeClientConnManager.this, entry.connection);
|
||||
poolEntry = entry;
|
||||
super(ThreadSafeClientConnManager.this, entry);
|
||||
super.markedReusable = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that this adapter is still attached.
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* if it is {@link #detach detach}ed
|
||||
*/
|
||||
protected final void assertAttached() {
|
||||
if (poolEntry == null) {
|
||||
throw new IllegalStateException("Adapter is detached.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the wrapped connection is still available.
|
||||
*
|
||||
* @return <code>true</code> if still available,
|
||||
* <code>false</code> if {@link #detach detached}
|
||||
*/
|
||||
protected boolean hasConnection() {
|
||||
return wrappedConnection != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches this adapter from the wrapped connection.
|
||||
* This adapter becomes useless.
|
||||
*/
|
||||
private void detach() {
|
||||
this.wrappedConnection = null;
|
||||
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(HttpRoute route,
|
||||
HttpContext context, HttpParams params)
|
||||
throws IOException {
|
||||
|
||||
assertAttached();
|
||||
poolEntry.open(route, context, params);
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see interface ManagedHttpConnection
|
||||
public void tunnelCreated(boolean secure, HttpParams params)
|
||||
throws IOException {
|
||||
|
||||
assertAttached();
|
||||
poolEntry.tunnelCreated(secure, params);
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see interface ManagedHttpConnection
|
||||
public void layerProtocol(HttpContext context, HttpParams params)
|
||||
throws IOException {
|
||||
|
||||
assertAttached();
|
||||
poolEntry.layerProtocol(context, params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// non-javadoc, see interface HttpConnection
|
||||
public void close() throws IOException {
|
||||
if (poolEntry != null)
|
||||
poolEntry.closing();
|
||||
|
||||
if (hasConnection()) {
|
||||
wrappedConnection.close();
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
// non-javadoc, see interface HttpConnection
|
||||
public void shutdown() throws IOException {
|
||||
if (poolEntry != null)
|
||||
poolEntry.closing();
|
||||
|
||||
if (hasConnection()) {
|
||||
wrappedConnection.shutdown();
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
} // class HttpConnectionAdapter
|
||||
}
|
||||
|
||||
} // class ThreadSafeClientConnManager
|
||||
|
||||
|
|
Loading…
Reference in New Issue