diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/interface-java/src/main')
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; + } } |