summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/interface-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/interface-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/interface-java')
-rw-r--r--sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java9
-rw-r--r--sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java47
2 files changed, 56 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java
index 55d694d7f8..c1357af9d6 100644
--- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java
+++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java
@@ -96,4 +96,13 @@ public interface JavaInterfaceFactory {
* @return
*/
List<JavaInterfaceVisitor> getInterfaceVisitors();
+
+ /**
+ * Remove the interfaces that have been registered for
+ * the contribution identified by the contribution class
+ * loader provided
+ *
+ * @param contributionClassloader
+ */
+ void removeInterfacesForContribution(ClassLoader contributionClassloader);
}
diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
index 8229c7812d..21c21e075d 100644
--- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
+++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
@@ -21,8 +21,10 @@ package org.apache.tuscany.sca.interfacedef.java.impl;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.WeakHashMap;
import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
@@ -31,6 +33,7 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.oasisopen.sca.ServiceRuntimeException;
/**
* A factory for the Java model.
@@ -112,4 +115,48 @@ public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory {
op.setName(method.getName());
return op;
}
+
+ /**
+ * 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 removeInterfacesForContribution(ClassLoader contributionClassloader){
+ removeInterfacesFromCache(contributionClassloader, normalCache);
+ removeInterfacesFromCache(contributionClassloader, forceRemotableCache);
+ }
+
+ private void removeInterfacesFromCache(ClassLoader contributionClassloader, Map<Class<?>, JavaInterface> cache){
+ try {
+ synchronized(cache) {
+ Set<Class<?>> clsSet = cache.keySet();
+ Iterator<Class<?>> i = clsSet.iterator();
+ while (i.hasNext()) {
+ Class<?> cls = i.next();
+ if (cls.getClassLoader() == contributionClassloader) {
+ i.remove();
+ }
+ }
+ }
+ } catch(Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * For testing so we can check that the cache is being cleared
+ */
+ public Map<Class<?>, JavaInterface> getNormalCache(){
+ return normalCache;
+ }
+
+ /**
+ * For testing so we can check that the cache is being cleared
+ */
+ public Map<Class<?>, JavaInterface> getForceRemotableCache(){
+ return forceRemotableCache;
+ }
}