cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1170240 - in /cxf/trunk: api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java
Date Tue, 13 Sep 2011 17:04:41 GMT
Author: dkulp
Date: Tue Sep 13 17:04:41 2011
New Revision: 1170240

URL: http://svn.apache.org/viewvc?rev=1170240&view=rev
Log:
Enhancements to EndpointReferenceUtils to make it cache a JAXBContext to
reduce contention and synchronization points.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=1170240&r1=1170239&r2=1170240&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Tue Sep 13
17:04:41 2011
@@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -32,6 +34,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -261,6 +264,8 @@ public final class EndpointReferenceUtil
     
     
     private static final Set<Class<?>> ADDRESSING_CLASSES = new HashSet<Class<?>>();
+    private static final AtomicReference<Reference<JAXBContext>> ADDRESSING_CONTEXT

+        = new AtomicReference<Reference<JAXBContext>>(new SoftReference<JAXBContext>(null));
     static {
         ADDRESSING_CLASSES.add(WSA_WSDL_OBJECT_FACTORY.getClass());
         ADDRESSING_CLASSES.add(WSAEndpointReferenceUtils.WSA_OBJECT_FACTORY.getClass());
@@ -1013,12 +1018,29 @@ public final class EndpointReferenceUtil
         return id;
     }
     
+
+    private static synchronized JAXBContext createContextForEPR() throws JAXBException {
+        Reference<JAXBContext> rctx = ADDRESSING_CONTEXT.get();
+        JAXBContext ctx = rctx.get();
+        if (ctx == null) {
+            ctx = JAXBContextCache.getCachedContextAndSchemas(ADDRESSING_CLASSES,
+                                                              null, null, null,
+                                                              true).getContext();
+            ADDRESSING_CONTEXT.set(new SoftReference<JAXBContext>(ctx));
+        }    
+        return ctx;
+    }
+    private static JAXBContext getJAXBContextForEPR() throws JAXBException {
+        Reference<JAXBContext> rctx = ADDRESSING_CONTEXT.get();
+        JAXBContext ctx = rctx.get();
+        if (ctx == null) {
+            ctx = createContextForEPR();
+        }
+        return ctx;
+    }
     public static Source convertToXML(EndpointReferenceType epr) {
         try {
-            JAXBContext jaxbContext = JAXBContextCache.getCachedContextAndSchemas(ADDRESSING_CLASSES,
-                                                                                  null, null,
null,
-                                                                                  false).getContext();
-            javax.xml.bind.Marshaller jm = jaxbContext.createMarshaller();
+            javax.xml.bind.Marshaller jm = getJAXBContextForEPR().createMarshaller();
             jm.setProperty(Marshaller.JAXB_FRAGMENT, true);
             QName qname = new QName("http://www.w3.org/2005/08/addressing", "EndpointReference");
             JAXBElement<EndpointReferenceType> 

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java?rev=1170240&r1=1170239&r2=1170240&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java Tue Sep
13 17:04:41 2011
@@ -46,6 +46,10 @@ public class CacheMap<K, V> implements M
     Map<K, V> mainDataMap = new WeakHashMap<K, V>();
     Map<K, V> extraKeyMap = new WeakIdentityHashMap<K, V>();
 
+    public CacheMap() {
+        
+    }
+    
     public void clear() {
         mainDataMap.clear();
         extraKeyMap.clear();

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java?rev=1170240&r1=1170239&r2=1170240&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java Tue Sep
13 17:04:41 2011
@@ -22,7 +22,6 @@ package org.apache.cxf.jaxb;
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.lang.ref.SoftReference;
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.util.Collection;
@@ -47,12 +46,12 @@ import org.apache.cxf.common.util.String
  */
 public final class JAXBContextCache {
     public static final class CachedContextAndSchemas {
-        private SoftReference<JAXBContext> context;
+        private WeakReference<JAXBContext> context;
         private WeakReference<Set<Class<?>>> classes;
         private Collection<DOMSource> schemas;
 
         CachedContextAndSchemas(JAXBContext context, Set<Class<?>> classes) {
-            this.context = new SoftReference<JAXBContext>(context);
+            this.context = new WeakReference<JAXBContext>(context);
             this.classes = new WeakReference<Set<Class<?>>>(classes);
         }
 



Mime
View raw message