From b757a258cc6b63a8728b155ac07b96279fabc0e5 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Wed, 22 Feb 2017 10:59:34 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/d4science/gcube/branches/common/common-smartgears-app/2.0@144087 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 1 - distro/changelog.xml | 5 +++- pom.xml | 22 ++++++++++----- .../ApplicationManagerProvider.java | 28 ++++++++++++++----- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.classpath b/.classpath index a996918..e43402f 100644 --- a/.classpath +++ b/.classpath @@ -22,7 +22,6 @@ - diff --git a/distro/changelog.xml b/distro/changelog.xml index 5d8e834..9f1044a 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,5 +1,8 @@ - + + Chaching for proxing of AppManager objects added + + Added support for initialization using security token diff --git a/pom.xml b/pom.xml index 8cd4e3e..51dec8d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.gcube.core common-smartgears-app - 2.0.0-SNAPSHOT + 2.0.2-SNAPSHOT Smartgears Application @@ -38,13 +38,21 @@ reflections 0.9.10 - + + - com.google.guava - guava - 18.0 - - + org.javassist + javassist + 3.20.0-GA + + + + + com.google.guava + guava + 18.0 + + org.gcube.core common-smartgears diff --git a/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java b/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java index 6832994..a3af77a 100644 --- a/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java +++ b/src/main/java/org/gcube/smartgears/ApplicationManagerProvider.java @@ -1,6 +1,7 @@ package org.gcube.smartgears; import java.lang.reflect.Method; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Future; @@ -20,7 +21,9 @@ public class ApplicationManagerProvider { static Map>> appManagerMap = new HashMap>>(); - private static Map> proxyClassMap = new HashMap>(); + private static Map> proxyClassMap = Collections.synchronizedMap(new HashMap>()); + + private static Map classProxyObjetMap = Collections.synchronizedMap(new HashMap()); public static synchronized ApplicationManager get(){ final Class applicationManagerClass = retrieveManagerClass(); @@ -31,7 +34,16 @@ public class ApplicationManagerProvider { Object obj; try { Class _class = getProxyClass(applicationManagerClass); - obj = _class.newInstance(); + if(classProxyObjetMap.containsKey(_class.getCanonicalName())){ + obj = classProxyObjetMap.get(_class.getCanonicalName()); + logger.trace("getting object {} from cache ",_class.getCanonicalName()); + return applicationManagerClass.cast(obj); + } else { + obj = _class.newInstance(); + classProxyObjetMap.put(_class.getCanonicalName(), obj); + } + + } catch (Exception e) { throw new RuntimeException("error creating proxy ", e); } @@ -39,8 +51,8 @@ public class ApplicationManagerProvider { MethodHandler handler = new MethodHandler() { @Override public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable { - logger.debug("context is {}", ScopeProvider.instance.get()); - logger.debug("applicationManagerClass is {}",applicationManagerClass.getCanonicalName()); + if (ScopeProvider.instance.get()==null) throw new RuntimeException("error invoking application manager method, scope is not set in this thread"); + logger.debug("applicationManagerClass is {}",applicationManagerClass.getCanonicalName()); Future appManagerFuture = appManagerMap.get(applicationManagerClass.getCanonicalName()).get(ScopeProvider.instance.get()); logger.debug("appmanager future is null? {}", appManagerFuture==null); logger.debug("thisMethod is null? {}", thisMethod==null); @@ -53,9 +65,11 @@ public class ApplicationManagerProvider { } private static Class getProxyClass(Class applicationManagerClass){ - if (proxyClassMap.containsKey(applicationManagerClass.getCanonicalName())) - return proxyClassMap.get(applicationManagerClass.getCanonicalName()); - + if (proxyClassMap.containsKey(applicationManagerClass.getCanonicalName())){ + logger.debug("getting proxy class {} for appManager from cache ",applicationManagerClass.getCanonicalName()); + return proxyClassMap.get(applicationManagerClass.getCanonicalName()); + } + logger.debug("creating new proxy class for appManager "+applicationManagerClass.getCanonicalName()); ProxyFactory proxyfactory = new ProxyFactory(); proxyfactory.setSuperclass(applicationManagerClass); Class proxyClass=proxyfactory.createClass();