commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsi...@apache.org
Subject cvs commit: jakarta-commons/discovery/src/java/org/apache/commons/discovery ServiceCache.java Discovery.java
Date Thu, 01 Aug 2002 18:46:03 GMT
rsitze      2002/08/01 11:46:03

  Modified:    discovery/src/java/org/apache/commons/discovery
                        ServiceCache.java Discovery.java
  Log:
  Replaced remaining use of Hashtable with HashMap.  A consequence of
  this was to replace Enumerators with Iterators.  This cleans up unnecessary
  synchronization.
  
  Revision  Changes    Path
  1.3       +8 -6      jakarta-commons/discovery/src/java/org/apache/commons/discovery/ServiceCache.java
  
  Index: ServiceCache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/ServiceCache.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServiceCache.java	17 Jul 2002 22:03:06 -0000	1.2
  +++ ServiceCache.java	1 Aug 2002 18:46:03 -0000	1.3
  @@ -61,14 +61,16 @@
   
   package org.apache.commons.discovery;
   
  -import java.util.Hashtable;
  -import java.util.Enumeration;
  +import java.util.Iterator;
  +import java.util.HashMap;
   
   
   
   /**
    * Cache of previously discovered implementations of SPI's.
    * 
  + * Unsynchronized, using code must manage threading issues.
  + * 
    * @author Richard A. Sitze
    */
   public class ServiceCache
  @@ -77,7 +79,7 @@
        * Previously encountered service interfaces (spis), keyed by the
        * <code>ClassLoader</code> with which it was created.
        */
  -    private Hashtable services = new Hashtable(13);
  +    private HashMap services = new HashMap(13);
       
       /**
        * Get service keyed by classLoader.
  @@ -115,9 +117,9 @@
        * garbage collection.
        */
       public void releaseAll() {
  -        Enumeration elements = services.elements();
  -        while (elements.hasMoreElements()) {
  -            Object service = elements.nextElement();
  +        Iterator elements = services.values().iterator();
  +        while (elements.hasNext()) {
  +            Object service = elements.next();
               
               if (service instanceof Service)
                   ((Service)service).release();
  
  
  
  1.6       +13 -14    jakarta-commons/discovery/src/java/org/apache/commons/discovery/Discovery.java
  
  Index: Discovery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/discovery/src/java/org/apache/commons/discovery/Discovery.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Discovery.java	29 Jul 2002 20:38:22 -0000	1.5
  +++ Discovery.java	1 Aug 2002 18:46:03 -0000	1.6
  @@ -61,9 +61,8 @@
   
   package org.apache.commons.discovery;
   
  -import java.util.Enumeration;
  +import java.util.Iterator;
   import java.util.HashMap;
  -import java.util.Hashtable;
   import java.util.Properties;
   import java.io.InputStream;
   import java.io.IOException;
  @@ -808,13 +807,13 @@
        */
       public static void releaseAll(String groupContext) {
           synchronized (group_caches) {
  -            Hashtable service_caches = (Hashtable)group_caches.get(groupContext);
  +            HashMap service_caches = (HashMap)group_caches.get(groupContext);
   
               if (service_caches != null) {
  -                Enumeration caches = service_caches.elements();
  +                java.util.Iterator caches = service_caches.values().iterator();
   
  -                while (caches.hasMoreElements()) {
  -                    ((ServiceCache)caches.nextElement()).releaseAll();
  +                while (caches.hasNext()) {
  +                    ((ServiceCache)caches.next()).releaseAll();
                   }
   
                   service_caches.clear();
  @@ -833,7 +832,7 @@
       public static void releaseAll(String groupContext, Class spi) {
           if (spi != null) {
               synchronized (group_caches) {
  -                Hashtable service_caches = (Hashtable)group_caches.get(groupContext);
  +                HashMap service_caches = (HashMap)group_caches.get(groupContext);
   
                   if (service_caches != null) {
                       ServiceCache cache = (ServiceCache)service_caches.get(spi.getName());
  @@ -852,11 +851,11 @@
       /************************* SPI CACHE SUPPORT *************************
        * 
        * Cache by
  -     * - Group : Cache is a <code>HashMap</code> (unsynchronized, allows null
keys(required))
  -     *           keyed by groupContext (<code>String</code>).
  -     *           Each element is a <code>Hashtable</code> (unsynchronized,
no non-null).
  +     * - Group : Cache is a <code>HashMap</code> (unsynchronized, allows null
  +     *           keys(required))  keyed by groupContext (<code>String</code>).
  +     *           Each element is a <code>HashMap</code>.
        * 
  -     * - SPI : Cache is a <code>Hashtable</code>
  +     * - SPI : Cache is a <code>HashMap</code>
        *         keyed by interface (<code>Class</code>).
        *         Each element is a <code>ServiceCache</code>.
        * 
  @@ -883,7 +882,7 @@
   
           if (spi != null) {
               synchronized (group_caches) {
  -                Hashtable service_caches = (Hashtable)group_caches.get(groupContext);
  +                HashMap service_caches = (HashMap)group_caches.get(groupContext);
   
                   if (service_caches != null) {
                       ServiceCache cache = (ServiceCache)service_caches.get(spi);
  @@ -906,10 +905,10 @@
       {
           if (spi != null  &&  service != null) {
               synchronized (group_caches) {
  -                Hashtable service_caches = (Hashtable)group_caches.get(groupContext);
  +                HashMap service_caches = (HashMap)group_caches.get(groupContext);
                   
                   if (service_caches == null) {
  -                    service_caches = new Hashtable(13);
  +                    service_caches = new HashMap(13);
                       group_caches.put(groupContext, service_caches);
                   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message