summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-09-26 17:15:02 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-09-26 17:15:02 +0000
commit796d66fd656292561c7cde90d6aa4807e8fbb5c8 (patch)
treef72ca93dde72ee6218f016d8b264f8711a398dff /java
parent81137dd2153f6f2ab0a8bc48b4f9b2f866a97996 (diff)
Add a cache for JavaInterface introspection
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@699416 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
index b1efd6e197..1454851fb1 100644
--- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
+++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
@@ -19,7 +19,10 @@
package org.apache.tuscany.sca.interfacedef.java.impl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
@@ -36,6 +39,7 @@ public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory {
private List<JavaInterfaceVisitor> visitors = new ArrayList<JavaInterfaceVisitor>();
private JavaInterfaceIntrospectorImpl introspector;
+ private Map<Class<?>, JavaInterface> cache = Collections.synchronizedMap(new WeakHashMap<Class<?>, JavaInterface>());
public JavaInterfaceFactoryImpl() {
introspector = new JavaInterfaceIntrospectorImpl(this);
@@ -46,9 +50,16 @@ public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory {
}
public JavaInterface createJavaInterface(Class<?> interfaceClass) throws InvalidInterfaceException {
- JavaInterface javaInterface = createJavaInterface();
- introspector.introspectInterface(javaInterface, interfaceClass);
- return javaInterface;
+ // TODO: Review if the sharing of JavaInterface is ok
+ synchronized (interfaceClass) {
+ JavaInterface javaInterface = cache.get(interfaceClass);
+ if (javaInterface == null) {
+ javaInterface = createJavaInterface();
+ introspector.introspectInterface(javaInterface, interfaceClass);
+ cache.put(interfaceClass, javaInterface);
+ }
+ return javaInterface;
+ }
}
public void createJavaInterface(JavaInterface javaInterface, Class<?> interfaceClass) throws InvalidInterfaceException {