hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r602981 - in /jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http: conn/ conn/ssl/ impl/conn/ impl/conn/tsccm/
Date Mon, 10 Dec 2007 18:01:14 GMT
Author: rolandw
Date: Mon Dec 10 10:01:12 2007
New Revision: 602981

URL: http://svn.apache.org/viewvc?rev=602981&view=rev
Log:
generics in HttpConn

Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/SchemeRegistry.java
Mon Dec 10 10:01:12 2007
@@ -53,7 +53,7 @@
 public final class SchemeRegistry {
 
     /** The available schemes in this registry. */
-    private final Map registeredSchemes;
+    private final Map<String,Scheme> registeredSchemes;
 
 
     /**
@@ -61,7 +61,7 @@
      */
     public SchemeRegistry() {
         super();
-        registeredSchemes = new LinkedHashMap();
+        registeredSchemes = new LinkedHashMap<String,Scheme>();
     }
 
 
@@ -167,7 +167,7 @@
      * @return  List containing registered scheme names.
      */
     public synchronized final List getSchemeNames() {
-        return new ArrayList(registeredSchemes.keySet());
+        return new ArrayList<String>(registeredSchemes.keySet());
     }
 
 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java
Mon Dec 10 10:01:12 2007
@@ -156,7 +156,7 @@
         // 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<String> names = new LinkedList<String>();
         if(cns != null && cns.length > 0 && cns[0] != null) {
             names.add(cns[0]);
         }
@@ -180,9 +180,9 @@
         // 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<String> 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 static String[] getCNs(X509Certificate cert) {
-        LinkedList cnList = new LinkedList();
+        LinkedList<String> cnList = new LinkedList<String>();
         /*
           Sebastian Hauer's original StrictSSLProtocolSocketFactory used
           getName() and had the following comment:
@@ -292,8 +292,8 @@
      * @return Array of SubjectALT DNS names stored in the certificate.
      */
     public static String[] getDNSSubjectAlts(X509Certificate cert) {
-        LinkedList subjectAltList = new LinkedList();
-        Collection c = null;
+        LinkedList<String> subjectAltList = new LinkedList<String>();
+        Collection<List<?>> c = null;
         try {
             c = cert.getSubjectAlternativeNames();
         }
@@ -302,9 +302,9 @@
             cpe.printStackTrace();
         }
         if(c != null) {
-            Iterator it = c.iterator();
+            Iterator<List<?>> 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 @@
         return count;
     }
     
-}
\ No newline at end of file
+}

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java
Mon Dec 10 10:01:12 2007
@@ -49,17 +49,16 @@
  * @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<HttpConnection,Long> connectionToAdded;
     
-    /**
-     * 
-     */
+
     public IdleConnectionHandler() {
         super();
+        connectionToAdded = new HashMap<HttpConnection,Long>();
     }
     
     /**
@@ -110,11 +109,12 @@
             LOG.debug("Checking for connections, idleTimeout: "  + idleTimeout);
         }
         
-        Iterator connectionIter = connectionToAdded.keySet().iterator();
+        Iterator<HttpConnection> 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);

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java
Mon Dec 10 10:01:12 2007
@@ -66,7 +66,7 @@
      * and point to the pool entry for the issued connection.
      * GCed connections are detected by the missing pool entries.
      */
-    protected Set issuedConnections;
+    protected Set<BasicPoolEntryRef> issuedConnections;
 
     /** The handler for idle connections. */
     protected IdleConnectionHandler idleConnHandler;
@@ -89,8 +89,12 @@
     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. */
     private RefQueueWorker refWorker;
@@ -103,7 +107,8 @@
     /**
      * 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.
@@ -112,7 +117,7 @@
          * @param queue   the reference queue, or <code>null</code>
          */
         public ConnMgrRef(ClientConnectionManager ccmgr,
-                          ReferenceQueue queue) {
+                          ReferenceQueue<Object> queue) {
             super(ccmgr, queue);
         }
     }
@@ -127,12 +132,12 @@
 
         params = mgr.getParams();
 
-        issuedConnections = new HashSet();
+        issuedConnections = new HashSet<BasicPoolEntryRef>();
         idleConnHandler = new IdleConnectionHandler();
 
         boolean conngc = true; //@@@ check parameters to decide
         if (conngc) {
-            refQueue = new ReferenceQueue();
+            refQueue = new ReferenceQueue<Object>();
             refWorker = new RefQueueWorker(refQueue, this);
             Thread t = new Thread(refWorker); //@@@ use a thread factory
             t.setDaemon(true);
@@ -247,9 +252,9 @@
             refWorker.shutdown();
 
         // close all connections that are issued to an application
-        Iterator iter = issuedConnections.iterator();
+        Iterator<BasicPoolEntryRef> 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) {

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntry.java
Mon Dec 10 10:01:12 2007
@@ -69,7 +69,7 @@
      */
     public BasicPoolEntry(ClientConnectionOperator op,
                           HttpRoute route,
-                          ReferenceQueue queue) {
+                          ReferenceQueue<Object> queue) {
         //@@@ create connection in base? or delay creation until needed?
         super(op.createConnection(), route);
         if (route == null) {
@@ -96,7 +96,7 @@
         return super.plannedRoute;
     }
 
-    protected final WeakReference getWeakRef() {
+    protected final BasicPoolEntryRef getWeakRef() {
         return this.reference;
     }
 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/BasicPoolEntryRef.java
Mon Dec 10 10:01:12 2007
@@ -43,7 +43,7 @@
  * 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<BasicPoolEntry> {
 
     /** The planned route of the entry. */
     private final HttpRoute route;
@@ -55,7 +55,8 @@
      * @param entry   the pool entry, must not be <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);
         if (entry == null) {
             throw new IllegalArgumentException

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/ConnPoolByRoute.java
Mon Dec 10 10:01:12 2007
@@ -66,17 +66,17 @@
 
 
     /** The list of free connections */
-    private LinkedList freeConnections;
+    private LinkedList<BasicPoolEntry> freeConnections;
 
     /** The list of WaitingThreads waiting for a connection */
-    private LinkedList waitingThreads;
+    private LinkedList<WaitingThread> 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<HttpRoute,RouteSpecificPool> routeToPool;
 
 
 
@@ -113,9 +113,9 @@
     public ConnPoolByRoute(ClientConnectionManager mgr) {
         super(mgr);
 
-        freeConnections = new LinkedList();
-        waitingThreads = new LinkedList();
-        routeToPool = new HashMap();
+        freeConnections = new LinkedList<BasicPoolEntry>();
+        waitingThreads = new LinkedList<WaitingThread>();
+        routeToPool = new HashMap<HttpRoute,RouteSpecificPool>();
     }
 
 
@@ -131,7 +131,7 @@
     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 @@
                 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 @@
 
         // close all free connections
         //@@@ move this to base class?
-        Iterator iter = freeConnections.iterator();
-        while (iter.hasNext()) {
-            BasicPoolEntry entry = (BasicPoolEntry) iter.next();
-            iter.remove();
+        Iterator<BasicPoolEntry> 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<WaitingThread> iwth = waitingThreads.iterator();
+        while (iwth.hasNext()) {
+            WaitingThread waiter = iwth.next();
+            iwth.remove();
             waiter.interruptedByConnectionPool = true;
             waiter.thread.interrupt();
         }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java?rev=602981&r1=602980&r2=602981&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java
Mon Dec 10 10:01:12 2007
@@ -48,10 +48,10 @@
     private final HttpRoute route;
 
     /** The list of free entries. */
-    private LinkedList freeEntries;
+    private LinkedList<BasicPoolEntry> freeEntries;
 
     /** 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. */
     private int numEntries;
@@ -64,8 +64,8 @@
          */
     public RouteSpecificPool(HttpRoute r) {
         this.route = r;
-        this.freeEntries = new LinkedList();
-        this.waitingThreads = new LinkedList();
+        this.freeEntries = new LinkedList<BasicPoolEntry>();
+        this.waitingThreads = new LinkedList<Object>();
         this.numEntries = 0;
     }
 
@@ -115,7 +115,7 @@
         BasicPoolEntry entry = null;
 
         if (!freeEntries.isEmpty()) {
-            entry = (BasicPoolEntry) freeEntries.removeLast();
+            entry = freeEntries.removeLast();
         }
 
         return entry;



Mime
View raw message