HTTPCLIENT-636: move TSCCM to separate package
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@558799 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3c5e2e6491
commit
d035d4d209
|
@ -47,7 +47,7 @@ import org.apache.http.conn.Scheme;
|
||||||
import org.apache.http.conn.SchemeRegistry;
|
import org.apache.http.conn.SchemeRegistry;
|
||||||
import org.apache.http.conn.SocketFactory;
|
import org.apache.http.conn.SocketFactory;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
|
|
@ -48,7 +48,7 @@ import org.apache.http.conn.SchemeRegistry;
|
||||||
import org.apache.http.conn.SocketFactory;
|
import org.apache.http.conn.SocketFactory;
|
||||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.apache.http.conn.SchemeRegistry;
|
||||||
import org.apache.http.conn.params.HttpConnectionManagerParams;
|
import org.apache.http.conn.params.HttpConnectionManagerParams;
|
||||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
|
|
|
@ -44,7 +44,7 @@ import org.apache.http.conn.PlainSocketFactory;
|
||||||
import org.apache.http.conn.Scheme;
|
import org.apache.http.conn.Scheme;
|
||||||
import org.apache.http.conn.SchemeRegistry;
|
import org.apache.http.conn.SchemeRegistry;
|
||||||
import org.apache.http.conn.SocketFactory;
|
import org.apache.http.conn.SocketFactory;
|
||||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.http.conn.Scheme;
|
||||||
import org.apache.http.conn.SchemeRegistry;
|
import org.apache.http.conn.SchemeRegistry;
|
||||||
import org.apache.http.conn.SocketFactory;
|
import org.apache.http.conn.SocketFactory;
|
||||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
import org.apache.http.impl.conn.ThreadSafeClientConnManager;
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
import org.apache.http.message.BasicHttpRequest;
|
import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* $HeadURL$
|
||||||
|
* $Revision$
|
||||||
|
* $Date$
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* 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.tsccm;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
import org.apache.http.impl.conn.AbstractPoolEntry;
|
||||||
|
import org.apache.http.impl.conn.AbstractPooledConnAdapter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A connection wrapper and callback handler.
|
||||||
|
* All connections given out by the manager are wrappers which
|
||||||
|
* can be {@link #detach detach}ed to prevent further use on release.
|
||||||
|
*/
|
||||||
|
public class TSCCMConnAdapter extends AbstractPooledConnAdapter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new adapter.
|
||||||
|
*
|
||||||
|
* @param tsccm the connection manager
|
||||||
|
* @param entry the pool entry for the connection being wrapped
|
||||||
|
*/
|
||||||
|
protected TSCCMConnAdapter(ThreadSafeClientConnManager tsccm,
|
||||||
|
AbstractPoolEntry entry) {
|
||||||
|
super(tsccm, entry);
|
||||||
|
super.markedReusable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the connection manager.
|
||||||
|
*
|
||||||
|
* @return the connection manager, or <code>null</code> if detached
|
||||||
|
*/
|
||||||
|
protected ClientConnectionManager getManager() {
|
||||||
|
return super.connManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the pool entry.
|
||||||
|
*
|
||||||
|
* @return the pool entry, or <code>null</code> if detached
|
||||||
|
*/
|
||||||
|
protected AbstractPoolEntry getPoolEntry() {
|
||||||
|
return super.poolEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// non-javadoc, see base class
|
||||||
|
protected void detach() {
|
||||||
|
// override needed only to make method visible in this package
|
||||||
|
super.detach();
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.http.impl.conn;
|
package org.apache.http.impl.conn.tsccm;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
|
@ -54,6 +54,7 @@ import org.apache.http.conn.OperatedClientConnection;
|
||||||
import org.apache.http.conn.SchemeRegistry;
|
import org.apache.http.conn.SchemeRegistry;
|
||||||
import org.apache.http.conn.params.HttpConnectionManagerParams;
|
import org.apache.http.conn.params.HttpConnectionManagerParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
|
import org.apache.http.impl.conn.*; //@@@ specify
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,7 +188,7 @@ public class ThreadSafeClientConnManager
|
||||||
|
|
||||||
final TrackingPoolEntry entry = doGetConnection(route, timeout);
|
final TrackingPoolEntry entry = doGetConnection(route, timeout);
|
||||||
|
|
||||||
return new HttpConnectionAdapter(entry);
|
return new TSCCMConnAdapter(this, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -361,15 +362,13 @@ public class ThreadSafeClientConnManager
|
||||||
*/
|
*/
|
||||||
public void releaseConnection(ManagedClientConnection conn) {
|
public void releaseConnection(ManagedClientConnection conn) {
|
||||||
|
|
||||||
if (!(conn instanceof HttpConnectionAdapter)) {
|
if (!(conn instanceof TSCCMConnAdapter)) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("Connection class mismatch, " +
|
("Connection class mismatch, " +
|
||||||
"connection not obtained from this manager.");
|
"connection not obtained from this manager.");
|
||||||
}
|
}
|
||||||
HttpConnectionAdapter hca = (HttpConnectionAdapter) conn;
|
TSCCMConnAdapter hca = (TSCCMConnAdapter) conn;
|
||||||
if ((hca.poolEntry != null) &&
|
if ((hca.getPoolEntry() != null) && (hca.getManager() != this)) {
|
||||||
//@@@ (hca.poolEntry.manager != this) &&
|
|
||||||
(hca.connManager != this)) {
|
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("Connection not obtained from this manager.");
|
("Connection not obtained from this manager.");
|
||||||
}
|
}
|
||||||
|
@ -397,7 +396,7 @@ public class ThreadSafeClientConnManager
|
||||||
LOG.debug("Exception shutting down released connection.",
|
LOG.debug("Exception shutting down released connection.",
|
||||||
iox);
|
iox);
|
||||||
} finally {
|
} finally {
|
||||||
TrackingPoolEntry entry = (TrackingPoolEntry) hca.poolEntry;
|
TrackingPoolEntry entry = (TrackingPoolEntry) hca.getPoolEntry();
|
||||||
hca.detach();
|
hca.detach();
|
||||||
releasePoolEntry(entry);
|
releasePoolEntry(entry);
|
||||||
}
|
}
|
||||||
|
@ -560,7 +559,7 @@ public class ThreadSafeClientConnManager
|
||||||
// to avoid holding the lock for too long
|
// to avoid holding the lock for too long
|
||||||
for (Iterator i = connectionsToClose.iterator(); i.hasNext();) {
|
for (Iterator i = connectionsToClose.iterator(); i.hasNext();) {
|
||||||
TrackingPoolEntry entry = (TrackingPoolEntry) i.next();
|
TrackingPoolEntry entry = (TrackingPoolEntry) i.next();
|
||||||
closeConnection(entry.connection);
|
closeConnection(entry.getConnection());
|
||||||
entry.manager.releasePoolEntry(entry);
|
entry.manager.releasePoolEntry(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -730,7 +729,7 @@ public class ThreadSafeClientConnManager
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
TrackingPoolEntry entry = (TrackingPoolEntry) iter.next();
|
TrackingPoolEntry entry = (TrackingPoolEntry) iter.next();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
closeConnection(entry.connection);
|
closeConnection(entry.getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refWorker != null)
|
if (refWorker != null)
|
||||||
|
@ -742,7 +741,7 @@ public class ThreadSafeClientConnManager
|
||||||
iter.remove();
|
iter.remove();
|
||||||
TrackingPoolEntry entry = (TrackingPoolEntry) per.get();
|
TrackingPoolEntry entry = (TrackingPoolEntry) per.get();
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
closeConnection(entry.connection);
|
closeConnection(entry.getConnection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//@@@ while the static map exists, call there to clean it up
|
//@@@ while the static map exists, call there to clean it up
|
||||||
|
@ -889,7 +888,7 @@ public class ThreadSafeClientConnManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the connection from the timeout handler
|
// remove the connection from the timeout handler
|
||||||
idleConnectionHandler.remove(entry.connection);
|
idleConnectionHandler.remove(entry.getConnection());
|
||||||
} else if (LOG.isDebugEnabled()) {
|
} else if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("There were no free connections to get, route="
|
LOG.debug("There were no free connections to get, route="
|
||||||
+ route);
|
+ route);
|
||||||
|
@ -907,7 +906,7 @@ public class ThreadSafeClientConnManager
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
TrackingPoolEntry entry =
|
TrackingPoolEntry entry =
|
||||||
(TrackingPoolEntry) iter.next();
|
(TrackingPoolEntry) iter.next();
|
||||||
if (!entry.connection.isOpen()) {
|
if (!entry.getConnection().isOpen()) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
deleteConnection(entry);
|
deleteConnection(entry);
|
||||||
}
|
}
|
||||||
|
@ -935,13 +934,13 @@ public class ThreadSafeClientConnManager
|
||||||
*/
|
*/
|
||||||
private synchronized void deleteConnection(TrackingPoolEntry entry) {
|
private synchronized void deleteConnection(TrackingPoolEntry entry) {
|
||||||
|
|
||||||
HttpRoute route = entry.plannedRoute;
|
HttpRoute route = entry.getPlannedRoute();
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Reclaiming connection, route=" + route);
|
LOG.debug("Reclaiming connection, route=" + route);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeConnection(entry.connection);
|
closeConnection(entry.getConnection());
|
||||||
|
|
||||||
RouteConnPool routePool = getRoutePool(route);
|
RouteConnPool routePool = getRoutePool(route);
|
||||||
|
|
||||||
|
@ -952,7 +951,7 @@ public class ThreadSafeClientConnManager
|
||||||
mapRoutes.remove(route);
|
mapRoutes.remove(route);
|
||||||
|
|
||||||
// remove the connection from the timeout handler
|
// remove the connection from the timeout handler
|
||||||
idleConnectionHandler.remove(entry.connection);
|
idleConnectionHandler.remove(entry.getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1029,7 +1028,7 @@ public class ThreadSafeClientConnManager
|
||||||
*/
|
*/
|
||||||
private void freeConnection(TrackingPoolEntry entry) {
|
private void freeConnection(TrackingPoolEntry entry) {
|
||||||
|
|
||||||
HttpRoute route = entry.plannedRoute;
|
HttpRoute route = entry.getPlannedRoute();
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Freeing connection, route=" + route);
|
LOG.debug("Freeing connection, route=" + route);
|
||||||
|
@ -1040,7 +1039,7 @@ public class ThreadSafeClientConnManager
|
||||||
if (isShutDown) {
|
if (isShutDown) {
|
||||||
// the connection manager has been shutdown, release the
|
// the connection manager has been shutdown, release the
|
||||||
// connection's resources and get out of here
|
// connection's resources and get out of here
|
||||||
closeConnection(entry.connection);
|
closeConnection(entry.getConnection());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1068,7 +1067,7 @@ public class ThreadSafeClientConnManager
|
||||||
}
|
}
|
||||||
|
|
||||||
// register the connection with the timeout handler
|
// register the connection with the timeout handler
|
||||||
idleConnectionHandler.add(entry.connection);
|
idleConnectionHandler.add(entry.getConnection());
|
||||||
|
|
||||||
notifyWaitingThread(routePool);
|
notifyWaitingThread(routePool);
|
||||||
}
|
}
|
||||||
|
@ -1295,7 +1294,7 @@ public class ThreadSafeClientConnManager
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("Pool entry must not be null.");
|
("Pool entry must not be null.");
|
||||||
}
|
}
|
||||||
route = entry.plannedRoute;
|
route = ((TrackingPoolEntry)entry).getPlannedRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1306,6 +1305,8 @@ public class ThreadSafeClientConnManager
|
||||||
* <code>false</code> otherwise
|
* <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
public final boolean isValid() {
|
public final boolean isValid() {
|
||||||
|
//@@@ method currently not used
|
||||||
|
//@@@ better sematics: allow explicit invalidation
|
||||||
return (super.get() != null);
|
return (super.get() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1377,10 +1378,19 @@ public class ThreadSafeClientConnManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private final OperatedClientConnection getConnection() {
|
||||||
|
return super.connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final HttpRoute getPlannedRoute() {
|
||||||
|
return super.plannedRoute;
|
||||||
|
}
|
||||||
|
|
||||||
} // class TrackingPoolEntry
|
} // class TrackingPoolEntry
|
||||||
|
|
||||||
|
|
||||||
/* *
|
/* *
|
||||||
|
* @@@ replace by separate class TSCCMConnAdapter
|
||||||
* A connection wrapper and callback handler.
|
* A connection wrapper and callback handler.
|
||||||
* All connections given out by the manager are wrappers which
|
* All connections given out by the manager are wrappers which
|
||||||
* can be {@link #detach detach}ed to prevent further use on release.
|
* can be {@link #detach detach}ed to prevent further use on release.
|
||||||
|
@ -1400,6 +1410,7 @@ public class ThreadSafeClientConnManager
|
||||||
super.markedReusable = true;
|
super.markedReusable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
} // class ThreadSafeClientConnManager
|
} // class ThreadSafeClientConnManager
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.http.conn.params.HttpConnectionManagerParams;
|
||||||
import org.apache.http.params.BasicHttpParams;
|
import org.apache.http.params.BasicHttpParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -52,6 +52,7 @@ import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.BasicHttpContext;
|
import org.apache.http.protocol.BasicHttpContext;
|
||||||
import org.apache.http.protocol.ExecutionContext;
|
import org.apache.http.protocol.ExecutionContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue