cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1170248 - in /cxf/branches/2.4.x-fixes: ./ api/src/main/java/org/apache/cxf/wsdl/ common/common/src/main/java/org/apache/cxf/common/util/ common/common/src/main/java/org/apache/cxf/jaxb/
Date Tue, 13 Sep 2011 17:10:50 GMT
Author: dkulp
Date: Tue Sep 13 17:10:49 2011
New Revision: 1170248

URL: http://svn.apache.org/viewvc?rev=1170248&view=rev
Log:
Merged revisions 1170240 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1170240 | dkulp | 2011-09-13 13:04:41 -0400 (Tue, 13 Sep 2011) | 2 lines
  
  Enhancements to EndpointReferenceUtils to make it cache a JAXBContext to
  reduce contention and synchronization points.
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
    cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
    cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=1170248&r1=1170247&r2=1170248&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Tue Sep 13 17:10:49 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/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java?rev=1170248&r1=1170247&r2=1170248&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
(original)
+++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
Tue Sep 13 17:10:49 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/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java?rev=1170248&r1=1170247&r2=1170248&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java
(original)
+++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBContextCache.java
Tue Sep 13 17:10:49 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