summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-03-04 17:48:55 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-03-04 17:48:55 +0000
commit553a373be707a466b2fdac6eb10568572b6f10a1 (patch)
treec7be1e7c94ccea4246dbd14ade2577992e430851 /sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java
parent3d87d97115e1f859cb5d452d16ede516908a37f0 (diff)
TUSCANY-3312 - Copy JavaInterfaceFactory memory leak changes from 1.x + other related changes and some extensions to allow the cache to be reduced when contributions are unloaded in the domain node.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1296845 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java')
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java65
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java12
2 files changed, 75 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
index 77b6b619ad..5ddf7d3604 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
@@ -59,6 +59,7 @@ import javax.xml.transform.Source;
import org.apache.tuscany.sca.common.java.collection.LRUCache;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.extensibility.ClassLoaderContext;
+import org.oasisopen.sca.ServiceRuntimeException;
/**
* @version $Rev$ $Date$
@@ -403,6 +404,12 @@ public class JAXBContextCache {
}
}
}
+ public void removeCtx(K key){
+ Map<K,List<V>> map = softMap.get();
+ if (map !=null && key !=null){
+ map.remove(key);
+ }
+ }
}
/**
@@ -566,5 +573,61 @@ public class JAXBContextCache {
}
}
-}
+ public void removeJAXBContextFromPools(JAXBContext ctx){
+ if (mpool != null && ctx != null){
+ mpool.removeCtx(ctx);
+ }
+ if (upool != null && ctx !=null){
+ upool.removeCtx(ctx);
+ }
+ }
+
+ /**
+ * Removes all the cached information relating to a contribution. The
+ * contribution is identified by the contribution classloader passed in
+ * as a parameter. This is used when a contribution is removed from
+ * the runtime.
+ *
+ * @param contributionClassloader
+ */
+ public void removeJAXBContextForContribution(ClassLoader contributionClassloader){
+ if (cache != null){
+ try {
+ synchronized(cache) {
+ Set<Object> objSet = cache.keySet();
+ List<Object> toRemove = new ArrayList<Object>();
+ Iterator<Object> i = objSet.iterator();
+ while(i.hasNext()) {
+ Object obj = i.next();
+ if (obj instanceof Set){
+ Set<Class> innerSet = (Set<Class>)obj;
+ Iterator<Class> j = innerSet.iterator();
+ loop:
+ while(j.hasNext()) {
+ Class cls = j.next();
+ ClassLoader cl = cls.getClassLoader();
+ while (cl != null){
+ if (cl == contributionClassloader){
+ toRemove.add(obj);
+ break loop;
+ }
+ // take account of generated classes
+ cl = cl.getParent();
+ }
+ }
+ }
+ }
+ for (Object obj : toRemove){
+ JAXBContext ctx = cache.get(obj);
+ removeJAXBContextFromPools(ctx);
+ cache.remove(obj);
+ }
+ }
+ } catch(Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
index 1837e43c36..44c172a07a 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
@@ -66,7 +66,7 @@ import org.apache.tuscany.sca.interfacedef.util.XMLType;
*
* @version $Rev$ $Date$
*/
-// FIXME: [rfeng] We probably should turn this into a pluggable system service
+
public final class JAXBContextHelper {
private final JAXBContextCache cache;
private final static SimpleTypeMapper SIMPLE_TYPE_MAPPER = new SimpleTypeMapperImpl();
@@ -587,4 +587,14 @@ public final class JAXBContextHelper {
return name.substring(0, decap).toLowerCase() + name.substring(decap);
}
+ public void removeJAXBContextForContribution(ClassLoader contributionClassloader){
+ cache.removeJAXBContextForContribution(contributionClassloader);
+ }
+
+ /**
+ * Just for testing that the cache is being removed on stop
+ */
+ public JAXBContextCache getJAXBContextCache(){
+ return cache;
+ }
}