wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r819207 - in /incubator/wink/trunk/wink-common/src: main/java/org/apache/wink/common/internal/registry/ProvidersRegistry.java test/java/org/apache/wink/common/internal/registry/ProvidersRegistryTest.java
Date Sat, 26 Sep 2009 20:47:22 GMT
Author: bluk
Date: Sat Sep 26 20:47:21 2009
New Revision: 819207

URL: http://svn.apache.org/viewvc?rev=819207&view=rev
Log:
Change ProvidersRegistry to use SoftConcurrentMap

The performance difference between the SoftConcurrentMap
and ConcurrentHashMap seems negligible after the
removal of the locks in SoftConcurrentMap and
I would like to use the same caching mechanisms.

Thanks to Doug Larson for taking the profile.

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/ProvidersRegistry.java
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/ProvidersRegistryTest.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/ProvidersRegistry.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/ProvidersRegistry.java?rev=819207&r1=819206&r2=819207&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/ProvidersRegistry.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/ProvidersRegistry.java
Sat Sep 26 20:47:21 2009
@@ -20,7 +20,6 @@
 package org.apache.wink.common.internal.registry;
 
 import java.lang.annotation.Annotation;
-import java.lang.ref.SoftReference;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -36,8 +35,6 @@
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Produces;
@@ -56,6 +53,7 @@
 import org.apache.wink.common.internal.utils.AnnotationUtils;
 import org.apache.wink.common.internal.utils.GenericsUtils;
 import org.apache.wink.common.internal.utils.MediaTypeUtils;
+import org.apache.wink.common.internal.utils.SoftConcurrentMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -504,17 +502,17 @@
 
     private abstract class MediaTypeMap<T> {
 
-        private volatile Map<MediaType, Set<ObjectFactory<T>>>        
                              data           =
-                                                                                        
                               new HashMap<MediaType, Set<ObjectFactory<T>>>();
+        private volatile Map<MediaType, Set<ObjectFactory<T>>>        
                                 data           =
+                                                                                        
                                  new HashMap<MediaType, Set<ObjectFactory<T>>>();
         @SuppressWarnings("unchecked")
-        private volatile Entry<MediaType, Set<ObjectFactory<T>>>[]    
                              entrySet       =
-                                                                                        
                               data
-                                                                                        
                                   .entrySet()
-                                                                                        
                                   .toArray(new Entry[0]);
-        private final Class<?>                                                    
                  rawType;
+        private volatile Entry<MediaType, Set<ObjectFactory<T>>>[]    
                                 entrySet       =
+                                                                                        
                                  data
+                                                                                        
                                      .entrySet()
+                                                                                        
                                      .toArray(new Entry[0]);
+        private final Class<?>                                                    
                     rawType;
 
-        private final Map<Class<?>, SoftReference<ConcurrentMap<MediaType,
List<ObjectFactory<T>>>>> providersCache =
-                                                                                        
                               new ConcurrentHashMap<Class<?>, SoftReference<ConcurrentMap<MediaType,
List<ObjectFactory<T>>>>>(); ;
+        private final SoftConcurrentMap<Class<?>, SoftConcurrentMap<MediaType,
List<ObjectFactory<T>>>> providersCache =
+                                                                                        
                                  new SoftConcurrentMap<Class<?>, SoftConcurrentMap<MediaType,
List<ObjectFactory<T>>>>(); ;
 
         public MediaTypeMap(Class<?> rawType) {
             super();
@@ -543,22 +541,17 @@
                 .debug("Getting providers by media type by calling getProvidersByMediaType({},
{})",
                        mediaType,
                        cls);
-            SoftReference<ConcurrentMap<MediaType, List<ObjectFactory<T>>>>
mediaTypeToProvidersCacheRef =
+            SoftConcurrentMap<MediaType, List<ObjectFactory<T>>> mediaTypeToProvidersCache
=
                 providersCache.get(cls);
-            ConcurrentMap<MediaType, List<ObjectFactory<T>>> mediaTypeToProvidersCache
= null;
-            if (mediaTypeToProvidersCacheRef != null) {
-                mediaTypeToProvidersCache = mediaTypeToProvidersCacheRef.get();
-            }
             if (mediaTypeToProvidersCache == null) {
                 logger
                     .debug("MediaType to providers cache for class {} does not exist so creating",
                            cls);
                 mediaTypeToProvidersCache =
-                    new ConcurrentHashMap<MediaType, List<ObjectFactory<T>>>();
-                providersCache
-                    .put(cls,
-                         new SoftReference<ConcurrentMap<MediaType, List<ObjectFactory<T>>>>(
-                                                                                        
    mediaTypeToProvidersCache));
+                    new SoftConcurrentMap<MediaType, List<ObjectFactory<T>>>();
+                providersCache.put(cls,
+
+                mediaTypeToProvidersCache);
             }
 
             List<ObjectFactory<T>> list = mediaTypeToProvidersCache.get(mediaType);

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/ProvidersRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/ProvidersRegistryTest.java?rev=819207&r1=819206&r2=819207&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/ProvidersRegistryTest.java
(original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/registry/ProvidersRegistryTest.java
Sat Sep 26 20:47:21 2009
@@ -20,12 +20,12 @@
 package org.apache.wink.common.internal.registry;
 
 import java.lang.reflect.Field;
-import java.util.concurrent.ConcurrentHashMap;
 
 import junit.framework.TestCase;
 
 import org.apache.wink.common.internal.application.ApplicationValidator;
 import org.apache.wink.common.internal.lifecycle.LifecycleManagersRegistry;
+import org.apache.wink.common.internal.utils.SoftConcurrentMap;
 
 public class ProvidersRegistryTest extends TestCase {
     
@@ -55,7 +55,7 @@
         field2.setAccessible(true);
         Object providersCache = field2.get(messageBodyReaders);
         
-        assertTrue(providersCache instanceof ConcurrentHashMap);    
+        assertTrue(providersCache instanceof SoftConcurrentMap);    
     }
     
     // TODO:  perhaps future tests should be added to actually exercise the providersCache
code, but it would be an involved,



Mime
View raw message