cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/4.4-forward to 961cd76
Date Sat, 07 Jun 2014 06:55:51 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4-forward e9ebe6e22 -> 961cd7657


CLOUDSTACK-6859:Management Server PermGen run out of memory after some
time due to class leak.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/961cd765
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/961cd765
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/961cd765

Branch: refs/heads/4.4-forward
Commit: 961cd7657e7dbb69d497123071db3156bd15d8e9
Parents: e9ebe6e
Author: Min Chen <min.chen@citrix.com>
Authored: Fri Jun 6 23:44:30 2014 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Fri Jun 6 23:45:53 2014 -0700

----------------------------------------------------------------------
 .../async/AsyncCallbackDispatcher.java          | 62 +++++++++++---------
 1 file changed, 35 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/961cd765/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java
----------------------------------------------------------------------
diff --git a/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java
b/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java
index 06cfcff..b9aa12b 100644
--- a/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java
+++ b/framework/ipc/src/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java
@@ -21,10 +21,11 @@ package org.apache.cloudstack.framework.async;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
 
-import net.sf.cglib.proxy.Callback;
-import net.sf.cglib.proxy.CallbackFilter;
 import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.Factory;
 import net.sf.cglib.proxy.MethodInterceptor;
 import net.sf.cglib.proxy.MethodProxy;
 
@@ -39,6 +40,7 @@ public class AsyncCallbackDispatcher<T, R> implements AsyncCompletionCallback
{
     private Object _contextObject;
     private Object _resultObject;
     private AsyncCallbackDriver _driver = new InplaceAsyncCallbackDriver();
+    private static Map<Class, Enhancer> enMap = new HashMap<Class, Enhancer>();
 
     private AsyncCallbackDispatcher(T target) {
         assert (target != null);
@@ -58,39 +60,45 @@ public class AsyncCallbackDispatcher<T, R> implements AsyncCompletionCallback
{
 
     @SuppressWarnings("unchecked")
     public T getTarget() {
-        Enhancer en = new Enhancer();
-
         Class<?> clz = _targetObject.getClass();
         String clzName = clz.getName();
         if (clzName.contains("EnhancerByCloudStack"))
             clz = clz.getSuperclass();
 
-        en.setSuperclass(clz);
-        en.setCallbacks(new Callback[] {new MethodInterceptor() {
-            @Override
-            public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy
arg3) throws Throwable {
-                _callbackMethod = arg1;
-                _callbackMethod.setAccessible(true);
-                return null;
-            }
-        }, new MethodInterceptor() {
-            @Override
-            public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy
arg3) throws Throwable {
-                return null;
-            }
-        }});
-        en.setCallbackFilter(new CallbackFilter() {
-            @Override
-            public int accept(Method method) {
-                if (method.getParameterTypes().length == 0 && method.getName().equals("finalize"))
{
-                    return 1;
-                }
-                return 0;
+
+        Enhancer en = null;
+        synchronized (enMap) {
+            en = enMap.get(clz);
+            if (en == null) {
+                en = new Enhancer();
+
+                en.setSuperclass(clz);
+                en.setCallback(new MethodInterceptor() {
+                    @Override
+                    public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy
arg3) throws Throwable {
+                        return null;
+                        }
+                    });
+                enMap.put(clz, en);
             }
-        });
+        }
 
         try {
-            return (T)en.create();
+            T t = (T)en.create();
+            Factory factory = (Factory)t;
+            factory.setCallback(0, new MethodInterceptor() {
+                @Override
+                public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy
arg3) throws Throwable {
+                    if (arg1.getParameterTypes().length == 0 && arg1.getName().equals("finalize"))
{
+                        return null;
+                    } else {
+                        _callbackMethod = arg1;
+                        _callbackMethod.setAccessible(true);
+                        return null;
+                    }
+                }
+            });
+            return t;
         } catch (Throwable e) {
             s_logger.error("Unexpected exception", e);
         }


Mime
View raw message