You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2009/11/02 17:44:01 UTC
svn commit: r831966 -
/tuscany/branches/sca-java-1.5.2/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java
Author: slaws
Date: Mon Nov 2 16:44:00 2009
New Revision: 831966
URL: http://svn.apache.org/viewvc?rev=831966&view=rev
Log:
TUSCANY-3312 - correct the fix for SCAProxy that previously relied on hash codes and is not correct. Change to relying on a weak reference inside to weak hash table to ensure that the proxy, and hence the class that it references, will be removed when the proxy is no longer required.
Modified:
tuscany/branches/sca-java-1.5.2/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java
Modified: tuscany/branches/sca-java-1.5.2/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.5.2/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java?rev=831966&r1=831965&r2=831966&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.5.2/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java (original)
+++ tuscany/branches/sca-java-1.5.2/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/SCAProxy.java Mon Nov 2 16:44:00 2009
@@ -18,6 +18,7 @@
*/
package org.apache.tuscany.sca.core.invocation;
+import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;
@@ -33,7 +34,7 @@
// This is a cache containing the proxy class constructor for each business interface.
// This improves performance compared to calling Proxy.newProxyInstance()
// every time that a proxy is needed.
- private static WeakHashMap cache = new WeakHashMap<String, Object>();
+ private static WeakHashMap cache = new WeakHashMap<Class, WeakReference<Constructor>>();
public static Object newProxyInstance(ClassLoader classloader, Class aclass[], InvocationHandler invocationhandler)
throws IllegalArgumentException
@@ -42,15 +43,18 @@
if(invocationhandler == null)
throw new NullPointerException();
// Lookup cached constructor. aclass[0] is the reference's business interface.
- Constructor proxyCTOR;
+ Constructor proxyCTOR = null;
synchronized(cache) {
- proxyCTOR = (Constructor) cache.get(aclass[0].hashCode());
+ WeakReference<Constructor> ref = (WeakReference<Constructor>) cache.get(aclass[0]);
+ if (ref != null){
+ proxyCTOR = ref.get();
+ }
}
if(proxyCTOR == null) {
Class proxyClass = getProxyClass(classloader, aclass);
proxyCTOR = proxyClass.getConstructor(constructorParams);
synchronized(cache){
- cache.put(aclass[0].hashCode(),proxyCTOR);
+ cache.put(aclass[0],new WeakReference<Constructor>(proxyCTOR));
}
}
return proxyCTOR.newInstance(new Object[] { invocationhandler });