cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r893388 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/
Date Wed, 23 Dec 2009 03:20:07 GMT
Author: dkulp
Date: Wed Dec 23 03:20:06 2009
New Revision: 893388

URL: http://svn.apache.org/viewvc?rev=893388&view=rev
Log:
[CXF-2286, CXF-1816] Use weak references for ASMHelper stuff to make
sure classes are not held onto strongly.

Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=893388&r1=893387&r2=893388&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java Wed Dec
23 03:20:06 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.common.util;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.Method;
@@ -36,8 +37,8 @@
     protected static final Map<Class<?>, String> PRIMITIVE_MAP = new HashMap<Class<?>,
String>();
     protected static final Map<Class<?>, String> NONPRIMITIVE_MAP = new HashMap<Class<?>,
String>();
     
-    protected static final Map<Class<?>, TypeHelperClassLoader> LOADER_MAP 
-        = new WeakIdentityHashMap<Class<?>, TypeHelperClassLoader>();
+    protected static final Map<Class<?>, WeakReference<TypeHelperClassLoader>>
LOADER_MAP 
+        = new WeakIdentityHashMap<Class<?>, WeakReference<TypeHelperClassLoader>>();
     
     protected static boolean oldASM;
     
@@ -191,10 +192,13 @@
     }
     
     private static synchronized TypeHelperClassLoader getTypeHelperClassLoader(Class<?>
l) {
-        TypeHelperClassLoader ret = LOADER_MAP.get(l);
-        if (ret == null) {
+        WeakReference<TypeHelperClassLoader> ref = LOADER_MAP.get(l);
+        TypeHelperClassLoader ret;
+        if (ref == null || ref.get() == null) {
             ret = new TypeHelperClassLoader(l.getClassLoader());
-            LOADER_MAP.put(l, ret);
+            LOADER_MAP.put(l, new WeakReference<TypeHelperClassLoader>(ret));
+        } else {
+            ret = ref.get();
         }
         return ret;
     }

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=893388&r1=893387&r2=893388&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Wed
Dec 23 03:20:06 2009
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
@@ -48,7 +49,6 @@
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementDecl;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLStreamReader;
@@ -59,8 +59,6 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
-import org.xml.sax.SAXException;
-
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.CacheMap;
@@ -109,15 +107,15 @@
                                                                                XMLStreamWriter.class};
 
     private static final class CachedContextAndSchemas {
-        private JAXBContext context;
+        private WeakReference<JAXBContext> context;
         private Collection<DOMSource> schemas;
 
         CachedContextAndSchemas(JAXBContext context) {
-            this.context = context;
+            this.context = new WeakReference<JAXBContext>(context);
         }
 
         public JAXBContext getContext() {
-            return context;
+            return context.get();
         }
 
         public Collection<DOMSource> getSchemas() {
@@ -149,11 +147,7 @@
                 BUILT_IN_SCHEMAS.put("http://www.w3.org/2005/02/addressing/wsdl", dr);
                 resolver.unresolve();
             }
-        } catch (IOException e) {
-            //IGNORE
-        } catch (ParserConfigurationException e) {
-            //IGNORE
-        } catch (SAXException e) {
+        } catch (Exception e) {
             //IGNORE
         }
         try {
@@ -166,11 +160,7 @@
                 BUILT_IN_SCHEMAS.put("http://www.w3.org/2005/08/addressing", dr);
                 resolver.unresolve();
             }
-        } catch (IOException e) {
-            //IGNORE
-        } catch (ParserConfigurationException e) {
-            //IGNORE
-        } catch (SAXException e) {
+        } catch (Exception e) {
             //IGNORE
         }
         try {
@@ -183,11 +173,7 @@
                 BUILT_IN_SCHEMAS.put("http://schemas.xmlsoap.org/ws/2005/02/rm", dr);
                 resolver.unresolve();
             }
-        } catch (IOException e) {
-            //IGNORE
-        } catch (ParserConfigurationException e) {
-            //IGNORE
-        } catch (SAXException e) {
+        } catch (Exception e) {
             //IGNORE
         }
         try {
@@ -200,15 +186,10 @@
                 BUILT_IN_SCHEMAS.put("http://schemas.xmlsoap.org/ws/2005/02/rm", dr);
                 resolver.unresolve();
             }
-        } catch (IOException e) {
-            //IGNORE
-        } catch (ParserConfigurationException e) {
-            //IGNORE
-        } catch (SAXException e) {
+        } catch (Exception e) {
             //IGNORE
         }
     }
-    
 
     Class[] extraClass;
 
@@ -362,7 +343,7 @@
             } else {
                 synchronized (JAXBCONTEXT_CACHE) {
                     JAXBCONTEXT_CACHE.put(contextClasses, cachedContextAndSchemas);
-                }                
+                } 
             }
         }
         ctx = cachedContextAndSchemas.getContext();
@@ -489,6 +470,7 @@
         }
 
         JAXBUtils.scanPackages(classes, OBJECT_FACTORY_CACHE);
+        //JAXBUtils.scanPackages(classes, new HashMap<Package, CachedClass>());
         addWsAddressingTypes(classes);
 
         for (Class<?> clz : classes) {
@@ -516,9 +498,12 @@
                 cachedContextAndSchemas = JAXBCONTEXT_CACHE.get(classes);
             }
         }
-        if (cachedContextAndSchemas == null) {
-            JAXBContext ctx = createContext(classes, map);
-            cachedContextAndSchemas = new CachedContextAndSchemas(ctx);
+        if (cachedContextAndSchemas != null) {
+            context = cachedContextAndSchemas.getContext();
+        }
+        if (context == null) {
+            context = createContext(classes, map);
+            cachedContextAndSchemas = new CachedContextAndSchemas(context);
             synchronized (JAXBCONTEXT_CACHE) {
                 if (typeRefs.isEmpty()) {
                     JAXBCONTEXT_CACHE.put(classes, cachedContextAndSchemas);

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java?rev=893388&r1=893387&r2=893388&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletContextResourceResolver.java
Wed Dec 23 03:20:06 2009
@@ -60,7 +60,11 @@
         try {
             if (entryName != null) {
                 InitialContext ic = new InitialContext();
-                obj = ic.lookup(entryName);
+                try {
+                    obj = ic.lookup(entryName);
+                } finally {
+                    ic.close();
+                }
             }
         } catch (NamingException e) {
             //do nothing



Mime
View raw message