diff --git a/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java b/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java index 85bcc43eb..730c3674c 100644 --- a/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java +++ b/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java @@ -53,7 +53,7 @@ import org.apache.http.HttpHost; public final class SchemeRegistry { /** The available schemes in this registry. */ - private final Map registeredSchemes; + private final Map registeredSchemes; /** @@ -61,7 +61,7 @@ public final class SchemeRegistry { */ public SchemeRegistry() { super(); - registeredSchemes = new LinkedHashMap(); + registeredSchemes = new LinkedHashMap(); } @@ -167,7 +167,7 @@ public final class SchemeRegistry { * @return List containing registered scheme names. */ public synchronized final List getSchemeNames() { - return new ArrayList(registeredSchemes.keySet()); + return new ArrayList(registeredSchemes.keySet()); } diff --git a/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java b/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java index faf9657e9..a9ca606dd 100644 --- a/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java +++ b/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java @@ -156,7 +156,7 @@ public abstract class AbstractVerifier implements HostnameVerifier { // STRICT implementations of the HostnameVerifier only use the // first CN provided. All other CNs are ignored. // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way). - LinkedList names = new LinkedList(); + LinkedList names = new LinkedList(); if(cns != null && cns.length > 0 && cns[0] != null) { names.add(cns[0]); } @@ -180,9 +180,9 @@ public abstract class AbstractVerifier implements HostnameVerifier { // establish the socket to the hostname in the certificate. String hostName = host.trim().toLowerCase(); boolean match = false; - for(Iterator it = names.iterator(); it.hasNext();) { + for(Iterator it = names.iterator(); it.hasNext();) { // Don't trim the CN, though! - String cn = (String) it.next(); + String cn = it.next(); cn = cn.toLowerCase(); // Store CN in StringBuffer in case we need to report an error. buf.append(" <"); @@ -235,7 +235,7 @@ public abstract class AbstractVerifier implements HostnameVerifier { } public static String[] getCNs(X509Certificate cert) { - LinkedList cnList = new LinkedList(); + LinkedList cnList = new LinkedList(); /* Sebastian Hauer's original StrictSSLProtocolSocketFactory used 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. */ public static String[] getDNSSubjectAlts(X509Certificate cert) { - LinkedList subjectAltList = new LinkedList(); - Collection c = null; + LinkedList subjectAltList = new LinkedList(); + Collection> c = null; try { c = cert.getSubjectAlternativeNames(); } @@ -302,9 +302,9 @@ public abstract class AbstractVerifier implements HostnameVerifier { cpe.printStackTrace(); } if(c != null) { - Iterator it = c.iterator(); + Iterator> it = c.iterator(); while(it.hasNext()) { - List list = (List) it.next(); + List list = it.next(); int type = ((Integer) list.get(0)).intValue(); // If type is 2, then we've got a dNSName if(type == 2) { @@ -337,4 +337,4 @@ public abstract class AbstractVerifier implements HostnameVerifier { return count; } -} \ No newline at end of file +} diff --git a/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java b/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java index aa621eb68..d907e1f9f 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java @@ -49,17 +49,16 @@ import org.apache.http.HttpConnection; * @since 4.0 */ 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. */ - private Map connectionToAdded = new HashMap(); + private Map connectionToAdded; - /** - * - */ + public IdleConnectionHandler() { super(); + connectionToAdded = new HashMap(); } /** @@ -110,11 +109,12 @@ public class IdleConnectionHandler { LOG.debug("Checking for connections, idleTimeout: " + idleTimeout); } - Iterator connectionIter = connectionToAdded.keySet().iterator(); + Iterator connectionIter = + connectionToAdded.keySet().iterator(); while (connectionIter.hasNext()) { - HttpConnection conn = (HttpConnection) connectionIter.next(); - Long connectionTime = (Long) connectionToAdded.get(conn); + HttpConnection conn = connectionIter.next(); + Long connectionTime = connectionToAdded.get(conn); if (connectionTime.longValue() <= idleTimeout) { if (LOG.isDebugEnabled()) { LOG.debug("Closing connection, connection time: " + connectionTime); diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java index d94b6cb94..bbb4784b7 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java @@ -66,7 +66,7 @@ public abstract class AbstractConnPool implements RefQueueHandler { * and point to the pool entry for the issued connection. * GCed connections are detected by the missing pool entries. */ - protected Set issuedConnections; + protected Set issuedConnections; /** The handler for idle connections. */ protected IdleConnectionHandler idleConnHandler; @@ -89,8 +89,12 @@ public abstract class AbstractConnPool implements RefQueueHandler { 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 refQueue; /** A worker (thread) to track loss of pool entries to GC. */ private RefQueueWorker refWorker; @@ -103,7 +107,8 @@ public abstract class AbstractConnPool implements RefQueueHandler { /** * A weak reference to the connection manager, to detect GC. */ - private static class ConnMgrRef extends WeakReference { + private static class ConnMgrRef + extends WeakReference { /** * Creates a new reference. @@ -112,7 +117,7 @@ public abstract class AbstractConnPool implements RefQueueHandler { * @param queue the reference queue, or null */ public ConnMgrRef(ClientConnectionManager ccmgr, - ReferenceQueue queue) { + ReferenceQueue queue) { super(ccmgr, queue); } } @@ -127,12 +132,12 @@ public abstract class AbstractConnPool implements RefQueueHandler { params = mgr.getParams(); - issuedConnections = new HashSet(); + issuedConnections = new HashSet(); idleConnHandler = new IdleConnectionHandler(); boolean conngc = true; //@@@ check parameters to decide if (conngc) { - refQueue = new ReferenceQueue(); + refQueue = new ReferenceQueue(); refWorker = new RefQueueWorker(refQueue, this); Thread t = new Thread(refWorker); //@@@ use a thread factory t.setDaemon(true); @@ -247,9 +252,9 @@ public abstract class AbstractConnPool implements RefQueueHandler { refWorker.shutdown(); // close all connections that are issued to an application - Iterator iter = issuedConnections.iterator(); + Iterator iter = issuedConnections.iterator(); while (iter.hasNext()) { - BasicPoolEntryRef per = (BasicPoolEntryRef) iter.next(); + BasicPoolEntryRef per = iter.next(); iter.remove(); BasicPoolEntry entry = (BasicPoolEntry) per.get(); if (entry != null) { diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java index 7d810daca..ccea83bfb 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java @@ -69,7 +69,7 @@ public class BasicPoolEntry extends AbstractPoolEntry { */ public BasicPoolEntry(ClientConnectionOperator op, HttpRoute route, - ReferenceQueue queue) { + ReferenceQueue queue) { //@@@ create connection in base? or delay creation until needed? super(op.createConnection(), route); if (route == null) { @@ -96,7 +96,7 @@ public class BasicPoolEntry extends AbstractPoolEntry { return super.plannedRoute; } - protected final WeakReference getWeakRef() { + protected final BasicPoolEntryRef getWeakRef() { return this.reference; } diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java index 9cbed58b8..2c89614bc 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java @@ -43,7 +43,7 @@ import org.apache.http.conn.HttpRoute; * This reference explicitly keeps the planned route, so the connection * can be reclaimed if it is lost to garbage collection. */ -public class BasicPoolEntryRef extends WeakReference { +public class BasicPoolEntryRef extends WeakReference { /** The planned route of the entry. */ private final HttpRoute route; @@ -55,7 +55,8 @@ public class BasicPoolEntryRef extends WeakReference { * @param entry the pool entry, must not be null * @param queue the reference queue, or null */ - public BasicPoolEntryRef(BasicPoolEntry entry, ReferenceQueue queue) { + public BasicPoolEntryRef(BasicPoolEntry entry, + ReferenceQueue queue) { super(entry, queue); if (entry == null) { throw new IllegalArgumentException diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java index 4bbcdf9d9..a6f4d501e 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java @@ -66,17 +66,17 @@ public class ConnPoolByRoute extends AbstractConnPool { /** The list of free connections */ - private LinkedList freeConnections; + private LinkedList freeConnections; /** The list of WaitingThreads waiting for a connection */ - private LinkedList waitingThreads; + private LinkedList waitingThreads; /** * A map of route-specific pools. * Keys are of class {@link HttpRoute}, * values of class {@link RouteSpecificPool}. */ - private final Map routeToPool; + private final Map routeToPool; @@ -113,9 +113,9 @@ public class ConnPoolByRoute extends AbstractConnPool { public ConnPoolByRoute(ClientConnectionManager mgr) { super(mgr); - freeConnections = new LinkedList(); - waitingThreads = new LinkedList(); - routeToPool = new HashMap(); + freeConnections = new LinkedList(); + waitingThreads = new LinkedList(); + routeToPool = new HashMap(); } @@ -131,7 +131,7 @@ public class ConnPoolByRoute extends AbstractConnPool { protected synchronized RouteSpecificPool getRoutePool(HttpRoute route, boolean create) { - RouteSpecificPool rospl = (RouteSpecificPool) routeToPool.get(route); + RouteSpecificPool rospl = routeToPool.get(route); if ((rospl == null) && create) { // no pool for this route yet (or anymore) rospl = newRouteSpecificPool(route); @@ -458,15 +458,14 @@ public class ConnPoolByRoute extends AbstractConnPool { LOG.debug("Notifying thread waiting on pool. " + rospl.getRoute()); } - waitingThread = (WaitingThread) - rospl.waitingThreads.removeFirst(); + waitingThread = (WaitingThread) rospl.waitingThreads.removeFirst(); waitingThreads.remove(waitingThread); } else if (!waitingThreads.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("Notifying thread waiting on any pool."); } - waitingThread = (WaitingThread) waitingThreads.removeFirst(); + waitingThread = waitingThreads.removeFirst(); waitingThread.pool.waitingThreads.remove(waitingThread); } else if (LOG.isDebugEnabled()) { @@ -503,19 +502,19 @@ public class ConnPoolByRoute extends AbstractConnPool { // close all free connections //@@@ move this to base class? - Iterator iter = freeConnections.iterator(); - while (iter.hasNext()) { - BasicPoolEntry entry = (BasicPoolEntry) iter.next(); - iter.remove(); + Iterator ibpe = freeConnections.iterator(); + while (ibpe.hasNext()) { + BasicPoolEntry entry = ibpe.next(); + ibpe.remove(); closeConnection(entry.getConnection()); } // interrupt all waiting threads - iter = waitingThreads.iterator(); - while (iter.hasNext()) { - WaitingThread waiter = (WaitingThread) iter.next(); - iter.remove(); + Iterator iwth = waitingThreads.iterator(); + while (iwth.hasNext()) { + WaitingThread waiter = iwth.next(); + iwth.remove(); waiter.interruptedByConnectionPool = true; waiter.thread.interrupt(); } diff --git a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java index 7e5c626fd..abfe42d55 100644 --- a/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java +++ b/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java @@ -48,10 +48,10 @@ public class RouteSpecificPool { private final HttpRoute route; /** The list of free entries. */ - private LinkedList freeEntries; + private LinkedList freeEntries; /** The list of threads waiting for this pool. */ - /*private@@@ currently still default*/ LinkedList waitingThreads; + /*private@@@ currently still default*/ LinkedList waitingThreads; /** The number of created entries. */ private int numEntries; @@ -64,8 +64,8 @@ public class RouteSpecificPool { */ public RouteSpecificPool(HttpRoute r) { this.route = r; - this.freeEntries = new LinkedList(); - this.waitingThreads = new LinkedList(); + this.freeEntries = new LinkedList(); + this.waitingThreads = new LinkedList(); this.numEntries = 0; } @@ -115,7 +115,7 @@ public class RouteSpecificPool { BasicPoolEntry entry = null; if (!freeEntries.isEmpty()) { - entry = (BasicPoolEntry) freeEntries.removeLast(); + entry = freeEntries.removeLast(); } return entry;