generics in HttpConn
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@602981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c7b26a6450
commit
87ff897181
|
@ -53,7 +53,7 @@ import org.apache.http.HttpHost;
|
||||||
public final class SchemeRegistry {
|
public final class SchemeRegistry {
|
||||||
|
|
||||||
/** The available schemes in this registry. */
|
/** The available schemes in this registry. */
|
||||||
private final Map registeredSchemes;
|
private final Map<String,Scheme> registeredSchemes;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,7 @@ public final class SchemeRegistry {
|
||||||
*/
|
*/
|
||||||
public SchemeRegistry() {
|
public SchemeRegistry() {
|
||||||
super();
|
super();
|
||||||
registeredSchemes = new LinkedHashMap();
|
registeredSchemes = new LinkedHashMap<String,Scheme>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ public final class SchemeRegistry {
|
||||||
* @return List containing registered scheme names.
|
* @return List containing registered scheme names.
|
||||||
*/
|
*/
|
||||||
public synchronized final List getSchemeNames() {
|
public synchronized final List getSchemeNames() {
|
||||||
return new ArrayList(registeredSchemes.keySet());
|
return new ArrayList<String>(registeredSchemes.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ public abstract class AbstractVerifier implements HostnameVerifier {
|
||||||
// STRICT implementations of the HostnameVerifier only use the
|
// STRICT implementations of the HostnameVerifier only use the
|
||||||
// first CN provided. All other CNs are ignored.
|
// first CN provided. All other CNs are ignored.
|
||||||
// (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way).
|
// (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way).
|
||||||
LinkedList names = new LinkedList();
|
LinkedList<String> names = new LinkedList<String>();
|
||||||
if(cns != null && cns.length > 0 && cns[0] != null) {
|
if(cns != null && cns.length > 0 && cns[0] != null) {
|
||||||
names.add(cns[0]);
|
names.add(cns[0]);
|
||||||
}
|
}
|
||||||
|
@ -180,9 +180,9 @@ public abstract class AbstractVerifier implements HostnameVerifier {
|
||||||
// establish the socket to the hostname in the certificate.
|
// establish the socket to the hostname in the certificate.
|
||||||
String hostName = host.trim().toLowerCase();
|
String hostName = host.trim().toLowerCase();
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
for(Iterator it = names.iterator(); it.hasNext();) {
|
for(Iterator<String> it = names.iterator(); it.hasNext();) {
|
||||||
// Don't trim the CN, though!
|
// Don't trim the CN, though!
|
||||||
String cn = (String) it.next();
|
String cn = it.next();
|
||||||
cn = cn.toLowerCase();
|
cn = cn.toLowerCase();
|
||||||
// Store CN in StringBuffer in case we need to report an error.
|
// Store CN in StringBuffer in case we need to report an error.
|
||||||
buf.append(" <");
|
buf.append(" <");
|
||||||
|
@ -235,7 +235,7 @@ public abstract class AbstractVerifier implements HostnameVerifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getCNs(X509Certificate cert) {
|
public static String[] getCNs(X509Certificate cert) {
|
||||||
LinkedList cnList = new LinkedList();
|
LinkedList<String> cnList = new LinkedList<String>();
|
||||||
/*
|
/*
|
||||||
Sebastian Hauer's original StrictSSLProtocolSocketFactory used
|
Sebastian Hauer's original StrictSSLProtocolSocketFactory used
|
||||||
getName() and had the following comment:
|
getName() and had the following comment:
|
||||||
|
@ -292,8 +292,8 @@ public abstract class AbstractVerifier implements HostnameVerifier {
|
||||||
* @return Array of SubjectALT DNS names stored in the certificate.
|
* @return Array of SubjectALT DNS names stored in the certificate.
|
||||||
*/
|
*/
|
||||||
public static String[] getDNSSubjectAlts(X509Certificate cert) {
|
public static String[] getDNSSubjectAlts(X509Certificate cert) {
|
||||||
LinkedList subjectAltList = new LinkedList();
|
LinkedList<String> subjectAltList = new LinkedList<String>();
|
||||||
Collection c = null;
|
Collection<List<?>> c = null;
|
||||||
try {
|
try {
|
||||||
c = cert.getSubjectAlternativeNames();
|
c = cert.getSubjectAlternativeNames();
|
||||||
}
|
}
|
||||||
|
@ -302,9 +302,9 @@ public abstract class AbstractVerifier implements HostnameVerifier {
|
||||||
cpe.printStackTrace();
|
cpe.printStackTrace();
|
||||||
}
|
}
|
||||||
if(c != null) {
|
if(c != null) {
|
||||||
Iterator it = c.iterator();
|
Iterator<List<?>> it = c.iterator();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
List list = (List) it.next();
|
List<?> list = it.next();
|
||||||
int type = ((Integer) list.get(0)).intValue();
|
int type = ((Integer) list.get(0)).intValue();
|
||||||
// If type is 2, then we've got a dNSName
|
// If type is 2, then we've got a dNSName
|
||||||
if(type == 2) {
|
if(type == 2) {
|
||||||
|
|
|
@ -50,16 +50,15 @@ import org.apache.http.HttpConnection;
|
||||||
*/
|
*/
|
||||||
public class IdleConnectionHandler {
|
public class IdleConnectionHandler {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(IdleConnectionHandler.class);
|
private final Log LOG = LogFactory.getLog(IdleConnectionHandler.class);
|
||||||
|
|
||||||
/** Holds connections and the time they were added. */
|
/** Holds connections and the time they were added. */
|
||||||
private Map connectionToAdded = new HashMap();
|
private Map<HttpConnection,Long> connectionToAdded;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public IdleConnectionHandler() {
|
public IdleConnectionHandler() {
|
||||||
super();
|
super();
|
||||||
|
connectionToAdded = new HashMap<HttpConnection,Long>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,11 +109,12 @@ public class IdleConnectionHandler {
|
||||||
LOG.debug("Checking for connections, idleTimeout: " + idleTimeout);
|
LOG.debug("Checking for connections, idleTimeout: " + idleTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator connectionIter = connectionToAdded.keySet().iterator();
|
Iterator<HttpConnection> connectionIter =
|
||||||
|
connectionToAdded.keySet().iterator();
|
||||||
|
|
||||||
while (connectionIter.hasNext()) {
|
while (connectionIter.hasNext()) {
|
||||||
HttpConnection conn = (HttpConnection) connectionIter.next();
|
HttpConnection conn = connectionIter.next();
|
||||||
Long connectionTime = (Long) connectionToAdded.get(conn);
|
Long connectionTime = connectionToAdded.get(conn);
|
||||||
if (connectionTime.longValue() <= idleTimeout) {
|
if (connectionTime.longValue() <= idleTimeout) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Closing connection, connection time: " + connectionTime);
|
LOG.debug("Closing connection, connection time: " + connectionTime);
|
||||||
|
|
|
@ -66,7 +66,7 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
* and point to the pool entry for the issued connection.
|
* and point to the pool entry for the issued connection.
|
||||||
* GCed connections are detected by the missing pool entries.
|
* GCed connections are detected by the missing pool entries.
|
||||||
*/
|
*/
|
||||||
protected Set issuedConnections;
|
protected Set<BasicPoolEntryRef> issuedConnections;
|
||||||
|
|
||||||
/** The handler for idle connections. */
|
/** The handler for idle connections. */
|
||||||
protected IdleConnectionHandler idleConnHandler;
|
protected IdleConnectionHandler idleConnHandler;
|
||||||
|
@ -89,8 +89,12 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
protected ConnMgrRef connManager;
|
protected ConnMgrRef connManager;
|
||||||
|
|
||||||
|
|
||||||
/** A reference queue to track loss of pool entries to GC. */
|
/**
|
||||||
protected ReferenceQueue refQueue;
|
* A reference queue to track loss of pool entries to GC.
|
||||||
|
* The same queue is used to track loss of the connection manager,
|
||||||
|
* so we cannot specialize the type.
|
||||||
|
*/
|
||||||
|
protected ReferenceQueue<Object> refQueue;
|
||||||
|
|
||||||
/** A worker (thread) to track loss of pool entries to GC. */
|
/** A worker (thread) to track loss of pool entries to GC. */
|
||||||
private RefQueueWorker refWorker;
|
private RefQueueWorker refWorker;
|
||||||
|
@ -103,7 +107,8 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
/**
|
/**
|
||||||
* A weak reference to the connection manager, to detect GC.
|
* A weak reference to the connection manager, to detect GC.
|
||||||
*/
|
*/
|
||||||
private static class ConnMgrRef extends WeakReference {
|
private static class ConnMgrRef
|
||||||
|
extends WeakReference<ClientConnectionManager> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new reference.
|
* Creates a new reference.
|
||||||
|
@ -112,7 +117,7 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
* @param queue the reference queue, or <code>null</code>
|
* @param queue the reference queue, or <code>null</code>
|
||||||
*/
|
*/
|
||||||
public ConnMgrRef(ClientConnectionManager ccmgr,
|
public ConnMgrRef(ClientConnectionManager ccmgr,
|
||||||
ReferenceQueue queue) {
|
ReferenceQueue<Object> queue) {
|
||||||
super(ccmgr, queue);
|
super(ccmgr, queue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,12 +132,12 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
|
|
||||||
params = mgr.getParams();
|
params = mgr.getParams();
|
||||||
|
|
||||||
issuedConnections = new HashSet();
|
issuedConnections = new HashSet<BasicPoolEntryRef>();
|
||||||
idleConnHandler = new IdleConnectionHandler();
|
idleConnHandler = new IdleConnectionHandler();
|
||||||
|
|
||||||
boolean conngc = true; //@@@ check parameters to decide
|
boolean conngc = true; //@@@ check parameters to decide
|
||||||
if (conngc) {
|
if (conngc) {
|
||||||
refQueue = new ReferenceQueue();
|
refQueue = new ReferenceQueue<Object>();
|
||||||
refWorker = new RefQueueWorker(refQueue, this);
|
refWorker = new RefQueueWorker(refQueue, this);
|
||||||
Thread t = new Thread(refWorker); //@@@ use a thread factory
|
Thread t = new Thread(refWorker); //@@@ use a thread factory
|
||||||
t.setDaemon(true);
|
t.setDaemon(true);
|
||||||
|
@ -247,9 +252,9 @@ public abstract class AbstractConnPool implements RefQueueHandler {
|
||||||
refWorker.shutdown();
|
refWorker.shutdown();
|
||||||
|
|
||||||
// close all connections that are issued to an application
|
// close all connections that are issued to an application
|
||||||
Iterator iter = issuedConnections.iterator();
|
Iterator<BasicPoolEntryRef> iter = issuedConnections.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
BasicPoolEntryRef per = (BasicPoolEntryRef) iter.next();
|
BasicPoolEntryRef per = iter.next();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
BasicPoolEntry entry = (BasicPoolEntry) per.get();
|
BasicPoolEntry entry = (BasicPoolEntry) per.get();
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class BasicPoolEntry extends AbstractPoolEntry {
|
||||||
*/
|
*/
|
||||||
public BasicPoolEntry(ClientConnectionOperator op,
|
public BasicPoolEntry(ClientConnectionOperator op,
|
||||||
HttpRoute route,
|
HttpRoute route,
|
||||||
ReferenceQueue queue) {
|
ReferenceQueue<Object> queue) {
|
||||||
//@@@ create connection in base? or delay creation until needed?
|
//@@@ create connection in base? or delay creation until needed?
|
||||||
super(op.createConnection(), route);
|
super(op.createConnection(), route);
|
||||||
if (route == null) {
|
if (route == null) {
|
||||||
|
@ -96,7 +96,7 @@ public class BasicPoolEntry extends AbstractPoolEntry {
|
||||||
return super.plannedRoute;
|
return super.plannedRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final WeakReference getWeakRef() {
|
protected final BasicPoolEntryRef getWeakRef() {
|
||||||
return this.reference;
|
return this.reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.http.conn.HttpRoute;
|
||||||
* This reference explicitly keeps the planned route, so the connection
|
* This reference explicitly keeps the planned route, so the connection
|
||||||
* can be reclaimed if it is lost to garbage collection.
|
* can be reclaimed if it is lost to garbage collection.
|
||||||
*/
|
*/
|
||||||
public class BasicPoolEntryRef extends WeakReference {
|
public class BasicPoolEntryRef extends WeakReference<BasicPoolEntry> {
|
||||||
|
|
||||||
/** The planned route of the entry. */
|
/** The planned route of the entry. */
|
||||||
private final HttpRoute route;
|
private final HttpRoute route;
|
||||||
|
@ -55,7 +55,8 @@ public class BasicPoolEntryRef extends WeakReference {
|
||||||
* @param entry the pool entry, must not be <code>null</code>
|
* @param entry the pool entry, must not be <code>null</code>
|
||||||
* @param queue the reference queue, or <code>null</code>
|
* @param queue the reference queue, or <code>null</code>
|
||||||
*/
|
*/
|
||||||
public BasicPoolEntryRef(BasicPoolEntry entry, ReferenceQueue queue) {
|
public BasicPoolEntryRef(BasicPoolEntry entry,
|
||||||
|
ReferenceQueue<Object> queue) {
|
||||||
super(entry, queue);
|
super(entry, queue);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
|
|
|
@ -66,17 +66,17 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
|
|
||||||
|
|
||||||
/** The list of free connections */
|
/** The list of free connections */
|
||||||
private LinkedList freeConnections;
|
private LinkedList<BasicPoolEntry> freeConnections;
|
||||||
|
|
||||||
/** The list of WaitingThreads waiting for a connection */
|
/** The list of WaitingThreads waiting for a connection */
|
||||||
private LinkedList waitingThreads;
|
private LinkedList<WaitingThread> waitingThreads;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of route-specific pools.
|
* A map of route-specific pools.
|
||||||
* Keys are of class {@link HttpRoute},
|
* Keys are of class {@link HttpRoute},
|
||||||
* values of class {@link RouteSpecificPool}.
|
* values of class {@link RouteSpecificPool}.
|
||||||
*/
|
*/
|
||||||
private final Map routeToPool;
|
private final Map<HttpRoute,RouteSpecificPool> routeToPool;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,9 +113,9 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
public ConnPoolByRoute(ClientConnectionManager mgr) {
|
public ConnPoolByRoute(ClientConnectionManager mgr) {
|
||||||
super(mgr);
|
super(mgr);
|
||||||
|
|
||||||
freeConnections = new LinkedList();
|
freeConnections = new LinkedList<BasicPoolEntry>();
|
||||||
waitingThreads = new LinkedList();
|
waitingThreads = new LinkedList<WaitingThread>();
|
||||||
routeToPool = new HashMap();
|
routeToPool = new HashMap<HttpRoute,RouteSpecificPool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
protected synchronized RouteSpecificPool getRoutePool(HttpRoute route,
|
protected synchronized RouteSpecificPool getRoutePool(HttpRoute route,
|
||||||
boolean create) {
|
boolean create) {
|
||||||
|
|
||||||
RouteSpecificPool rospl = (RouteSpecificPool) routeToPool.get(route);
|
RouteSpecificPool rospl = routeToPool.get(route);
|
||||||
if ((rospl == null) && create) {
|
if ((rospl == null) && create) {
|
||||||
// no pool for this route yet (or anymore)
|
// no pool for this route yet (or anymore)
|
||||||
rospl = newRouteSpecificPool(route);
|
rospl = newRouteSpecificPool(route);
|
||||||
|
@ -458,15 +458,14 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
LOG.debug("Notifying thread waiting on pool. "
|
LOG.debug("Notifying thread waiting on pool. "
|
||||||
+ rospl.getRoute());
|
+ rospl.getRoute());
|
||||||
}
|
}
|
||||||
waitingThread = (WaitingThread)
|
waitingThread = (WaitingThread) rospl.waitingThreads.removeFirst();
|
||||||
rospl.waitingThreads.removeFirst();
|
|
||||||
waitingThreads.remove(waitingThread);
|
waitingThreads.remove(waitingThread);
|
||||||
|
|
||||||
} else if (!waitingThreads.isEmpty()) {
|
} else if (!waitingThreads.isEmpty()) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Notifying thread waiting on any pool.");
|
LOG.debug("Notifying thread waiting on any pool.");
|
||||||
}
|
}
|
||||||
waitingThread = (WaitingThread) waitingThreads.removeFirst();
|
waitingThread = waitingThreads.removeFirst();
|
||||||
waitingThread.pool.waitingThreads.remove(waitingThread);
|
waitingThread.pool.waitingThreads.remove(waitingThread);
|
||||||
|
|
||||||
} else if (LOG.isDebugEnabled()) {
|
} else if (LOG.isDebugEnabled()) {
|
||||||
|
@ -503,19 +502,19 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
||||||
|
|
||||||
// close all free connections
|
// close all free connections
|
||||||
//@@@ move this to base class?
|
//@@@ move this to base class?
|
||||||
Iterator iter = freeConnections.iterator();
|
Iterator<BasicPoolEntry> ibpe = freeConnections.iterator();
|
||||||
while (iter.hasNext()) {
|
while (ibpe.hasNext()) {
|
||||||
BasicPoolEntry entry = (BasicPoolEntry) iter.next();
|
BasicPoolEntry entry = ibpe.next();
|
||||||
iter.remove();
|
ibpe.remove();
|
||||||
closeConnection(entry.getConnection());
|
closeConnection(entry.getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// interrupt all waiting threads
|
// interrupt all waiting threads
|
||||||
iter = waitingThreads.iterator();
|
Iterator<WaitingThread> iwth = waitingThreads.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iwth.hasNext()) {
|
||||||
WaitingThread waiter = (WaitingThread) iter.next();
|
WaitingThread waiter = iwth.next();
|
||||||
iter.remove();
|
iwth.remove();
|
||||||
waiter.interruptedByConnectionPool = true;
|
waiter.interruptedByConnectionPool = true;
|
||||||
waiter.thread.interrupt();
|
waiter.thread.interrupt();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ public class RouteSpecificPool {
|
||||||
private final HttpRoute route;
|
private final HttpRoute route;
|
||||||
|
|
||||||
/** The list of free entries. */
|
/** The list of free entries. */
|
||||||
private LinkedList freeEntries;
|
private LinkedList<BasicPoolEntry> freeEntries;
|
||||||
|
|
||||||
/** The list of threads waiting for this pool. */
|
/** The list of threads waiting for this pool. */
|
||||||
/*private@@@ currently still default*/ LinkedList waitingThreads;
|
/*private@@@ currently still default*/ LinkedList<Object> waitingThreads;
|
||||||
|
|
||||||
/** The number of created entries. */
|
/** The number of created entries. */
|
||||||
private int numEntries;
|
private int numEntries;
|
||||||
|
@ -64,8 +64,8 @@ public class RouteSpecificPool {
|
||||||
*/
|
*/
|
||||||
public RouteSpecificPool(HttpRoute r) {
|
public RouteSpecificPool(HttpRoute r) {
|
||||||
this.route = r;
|
this.route = r;
|
||||||
this.freeEntries = new LinkedList();
|
this.freeEntries = new LinkedList<BasicPoolEntry>();
|
||||||
this.waitingThreads = new LinkedList();
|
this.waitingThreads = new LinkedList<Object>();
|
||||||
this.numEntries = 0;
|
this.numEntries = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ public class RouteSpecificPool {
|
||||||
BasicPoolEntry entry = null;
|
BasicPoolEntry entry = null;
|
||||||
|
|
||||||
if (!freeEntries.isEmpty()) {
|
if (!freeEntries.isEmpty()) {
|
||||||
entry = (BasicPoolEntry) freeEntries.removeLast();
|
entry = freeEntries.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
|
|
Loading…
Reference in New Issue