cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject [1/2] cxf git commit: [CXF-6826] Cache MediaTypeHeaderProvider.valueOf results (with automatic cache cleanup when reaching a threshold)
Date Fri, 11 Mar 2016 08:38:41 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 15504ab90 -> 2196b6c2c


[CXF-6826] Cache MediaTypeHeaderProvider.valueOf results (with automatic cache cleanup when
reaching a threshold)


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fa973bd7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fa973bd7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fa973bd7

Branch: refs/heads/master
Commit: fa973bd7ab43099151f83beea351b80c7140eaab
Parents: 53aed2e
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Thu Mar 10 20:39:49 2016 +0100
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Thu Mar 10 20:39:49 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/MediaTypeHeaderProvider.java | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fa973bd7/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
index 39f484e..5d297b6 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
@@ -25,6 +25,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -45,17 +46,34 @@ public class MediaTypeHeaderProvider implements HeaderDelegate<MediaType>
{
     private static final Pattern COMPLEX_PARAMETERS = 
         Pattern.compile("(([\\w-]+=\"[^\"]*\")|([\\w-]+=[\\w-/\\+]+))");
     
+    private static Map<String, MediaType> map = new ConcurrentHashMap<String, MediaType>();
+    private static final int MAX_MT_CACHE_SIZE = 
+        Integer.getInteger("org.apache.cxf.jaxrs.max_mediatype_cache_size", 200);
+
     public MediaType fromString(String mType) {
         
         return valueOf(mType);
     }
 
     public static MediaType valueOf(String mType) {
-        
         if (mType == null) {
             throw new IllegalArgumentException("Media type value can not be null");
         }
         
+        MediaType result = map.get(mType);
+        if (result == null) {
+            result = internalValueOf(mType);
+            final int size = map.size();
+            if (size >= MAX_MT_CACHE_SIZE) {
+                map.clear();
+            }
+            map.put(mType, result);
+        }
+        return result;
+    }
+
+    public static MediaType internalValueOf(String mType) {
+        
         int i = mType.indexOf('/');
         if (i == -1) {
             return handleMediaTypeWithoutSubtype(mType.trim());


Mime
View raw message