[jboss-cvs] JBossAS SVN: r84639 - in projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop: plugins and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 23 11:18:08 EST 2009
Author: kabir.khan at jboss.com
Date: 2009-02-23 11:18:08 -0500 (Mon, 23 Feb 2009)
New Revision: 84639
Modified:
projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/AspectManager.java
projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/Domain.java
projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/plugins/DefaultManager.java
projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/spi/Manager.java
Log:
Move interceptor stacks to new Manager
Modified: projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/AspectManager.java 2009-02-23 16:17:45 UTC (rev 84638)
+++ projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/AspectManager.java 2009-02-23 16:18:08 UTC (rev 84639)
@@ -38,7 +38,6 @@
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
import javassist.ClassPool;
import javassist.CtClass;
@@ -48,14 +47,12 @@
import org.jboss.aop.advice.AdviceBinding;
import org.jboss.aop.advice.AdviceStack;
import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.AspectFactoryWithClassLoader;
import org.jboss.aop.advice.ClassifiedBindingAndPointcutCollection;
import org.jboss.aop.advice.DynamicCFlowDefinition;
import org.jboss.aop.advice.InterceptorFactory;
import org.jboss.aop.advice.PrecedenceDef;
import org.jboss.aop.advice.PrecedenceDefEntry;
import org.jboss.aop.advice.PrecedenceSorter;
-import org.jboss.aop.advice.Scope;
import org.jboss.aop.array.ArrayBinding;
import org.jboss.aop.array.ArrayReplacement;
import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
@@ -109,8 +106,8 @@
//TOD how this gets set needs revisiting
Manager manager = null;
- /** Indicates that a call to the factory has been made, but it returned null. */
- private static final Object NULL_ASPECT = new Object();
+// /** Indicates that a call to the factory has been made, but it returned null. */
+// private static final Object NULL_ASPECT = new Object();
/** Lock to be used when lazy creating the collections */
Object lazyCollectionLock = new Object();
@@ -146,8 +143,8 @@
//protected volatile HashMap<String, AdviceStack> interceptorStacks = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
protected volatile HashMap<String, DeclareDef> declares = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
//protected volatile ConcurrentHashMap<String, DynamicCFlowDefinition> dynamicCFlows = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
- protected volatile ConcurrentHashMap<String, AspectDefinition> aspectDefinitions = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
- protected volatile ConcurrentHashMap<String, Object> perVMAspects = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
+// protected volatile ConcurrentHashMap<String, AspectDefinition> aspectDefinitions = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
+ //protected volatile ConcurrentHashMap<String, Object> perVMAspects = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
protected static AOPLock lock = new AOPLock();
@@ -1528,104 +1525,48 @@
}
}
+ @Deprecated
public Object getPerVMAspect(AspectDefinition def)
{
return getPerVMAspect(def.getName());
}
- public Object getPerVMAspect(String def)
+ protected Object createPerVmAspect(String def, AspectDefinition adef, ClassLoader scopedClassLoader)
{
- Object aspect = perVMAspects.get(def);
- if (aspect == null)
- {
- AspectDefinition adef = aspectDefinitions.get(def);
- if (adef != null && adef.getScope() == Scope.PER_VM)
- {
- synchronized (adef)
- {
- // double check but, now, in a sync block
- aspect = perVMAspects.get(def);
- if (aspect == null)
- {
- aspect = createPerVmAspect(def, adef, null);
- }
- }
- }
- }
- if (aspect == NULL_ASPECT)
- {
- return null;
- }
- return aspect;
+ return manager.createPerVmAspect(adef, scopedClassLoader);
}
-
- protected Object createPerVmAspect(String def, AspectDefinition adef, ClassLoader scopedClassLoader)
+ @Deprecated
+ public Object getPerVMAspect(String def)
{
- Object instance = null;
- synchronized (adef)
- {
- try
- {
- if (scopedClassLoader != null && adef.getFactory() instanceof AspectFactoryWithClassLoader)
- {
- //If a scoped classloader with no parent delegation redefines the class, we need to make sure that that class is pushed on the stack
- ((AspectFactoryWithClassLoader)adef.getFactory()).pushScopedClassLoader(scopedClassLoader);
- }
- instance = adef.getFactory().createPerVM();
- initPerVMAspectsMap();
- if (instance == null)
- {
- // indicates that the factory must not be called again
- // the factory has already been called and returned null
- perVMAspects.put(def, NULL_ASPECT);
- }
- else
- {
- perVMAspects.put(def, instance);
- }
- }
- finally
- {
- if (scopedClassLoader != null && adef.getFactory() instanceof AspectFactoryWithClassLoader)
- {
- ((AspectFactoryWithClassLoader)adef.getFactory()).popScopedClassLoader();
- }
- }
- }
- return instance;
+ return manager.getPerVMAspect(def);
}
+ @Deprecated
public void addAspectDefinition(AspectDefinition def)
{
- removeAspectDefinition(def.getName());
- initAspectDefintitionsMap();
- aspectDefinitions.put(def.getName(), def);
+ manager.addAspectDefinition(def);
}
+ @Deprecated
public void removeAspectDefinition(String name)
{
- internalRemoveAspectDefintion(name);
+ manager.removeAspectDefinition(name);
}
-
+
protected AspectDefinition internalRemoveAspectDefintion(String name)
{
- AspectDefinition def = aspectDefinitions.remove(name);
- if (def != null)
- {
- def.undeploy();
- if (def.getScope() == Scope.PER_VM) perVMAspects.remove(def.getName());
- }
- return def;
+ return manager.removeAspectDefinition(name);
}
+
public Map<String, AspectDefinition> getAspectDefinitions()
{
- return aspectDefinitions;
+ return manager.getAspectDefinitions();
}
public AspectDefinition getAspectDefinition(String name)
{
- return aspectDefinitions.get(name);
+ return manager.getAspectDefinition(name);
}
@Deprecated
@@ -1688,7 +1629,7 @@
public Map<String, Object> getPerVMAspects()
{
- return perVMAspects;
+ return manager.getPerVMAspects();
}
public Map<String, ClassMetaDataBinding> getClassMetaData()
@@ -1959,34 +1900,6 @@
}
}
- protected void initAspectDefintitionsMap()
- {
- if (aspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
- {
- synchronized(lazyCollectionLock)
- {
- if (aspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
- {
- aspectDefinitions = new ConcurrentHashMap<String, AspectDefinition>();
- }
- }
- }
- }
-
- protected void initPerVMAspectsMap()
- {
- if (perVMAspects == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
- {
- synchronized(lazyCollectionLock)
- {
- if (perVMAspects == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
- {
- perVMAspects = new ConcurrentHashMap<String, Object>();
- }
- }
- }
- }
-
protected void initClassMetaDataMap()
{
if (classMetaData == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
Modified: projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/Domain.java
===================================================================
--- projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/Domain.java 2009-02-23 16:17:45 UTC (rev 84638)
+++ projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/Domain.java 2009-02-23 16:18:08 UTC (rev 84639)
@@ -620,17 +620,17 @@
{
// when child first, parent bindings go in first so that they can be overridden by child.
map.putAll(parent.getPerVMAspects());
- synchronized (perVMAspects)
+ synchronized (super.getPerVMAspects())
{
- map.putAll(perVMAspects);
+ map.putAll(super.getPerVMAspects());
}
return map;
}
else
{
- synchronized (perVMAspects)
+ synchronized (super.getPerVMAspects())
{
- map.putAll(perVMAspects);
+ map.putAll(super.getPerVMAspects());
}
map.putAll(parent.getPerVMAspects());
return map;
Modified: projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/plugins/DefaultManager.java
===================================================================
--- projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/plugins/DefaultManager.java 2009-02-23 16:17:45 UTC (rev 84638)
+++ projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/plugins/DefaultManager.java 2009-02-23 16:18:08 UTC (rev 84639)
@@ -31,8 +31,10 @@
import org.jboss.aop.advice.AdviceStack;
import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.advice.AspectFactoryWithClassLoader;
import org.jboss.aop.advice.DynamicCFlowDefinition;
import org.jboss.aop.advice.InterceptorFactory;
+import org.jboss.aop.advice.Scope;
import org.jboss.aop.array.ArrayAdvisor;
import org.jboss.aop.array.ArrayBinding;
import org.jboss.aop.array.ArrayReplacement;
@@ -59,8 +61,15 @@
@SuppressWarnings("unused")
private final Configuration configuration;
+ /** Indicates that a call to the factory has been made, but it returned null. */
+ private static final Object NULL_ASPECT = new Object();
+
private final Object lazyCollectionLock = new Object();
+ private volatile Map<String, AspectDefinition> aspectDefinitions = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
+
+ private volatile Map<String, Object> perVMAspects = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
+
private volatile Map<String, CFlowStack> cflowStacks = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
private volatile Map<String, DynamicCFlowDefinition> dynamicCFlows = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP;
@@ -378,6 +387,101 @@
return adviceStacks;
}
+ public void addAspectDefinition(AspectDefinition def)
+ {
+ removeAspectDefinition(def.getName());
+ initAspectDefintitionsMap();
+ aspectDefinitions.put(def.getName(), def);
+ }
+
+ public AspectDefinition getAspectDefinition(String name)
+ {
+ return aspectDefinitions.get(name);
+ }
+
+ public AspectDefinition removeAspectDefinition(String name)
+ {
+ AspectDefinition def = aspectDefinitions.remove(name);
+ if (def != null)
+ {
+ def.undeploy();
+ if (def.getScope() == Scope.PER_VM) perVMAspects.remove(def.getName());
+ }
+ return def;
+ }
+
+ public Map<String, AspectDefinition> getAspectDefinitions()
+ {
+ return aspectDefinitions;
+ }
+
+ public Object getPerVMAspect(String name)
+ {
+ Object aspect = perVMAspects.get(name);
+ if (aspect == null)
+ {
+ AspectDefinition adef = aspectDefinitions.get(name);
+ if (adef != null && adef.getScope() == Scope.PER_VM)
+ {
+ synchronized (adef)
+ {
+ // double check but, now, in a sync block
+ aspect = perVMAspects.get(name);
+ if (aspect == null)
+ {
+ aspect = createPerVmAspect(adef, null);
+ }
+ }
+ }
+ }
+ if (aspect == NULL_ASPECT)
+ {
+ return null;
+ }
+ return aspect;
+ }
+
+ public Map<String, Object> getPerVMAspects()
+ {
+ return perVMAspects;
+ }
+
+ public Object createPerVmAspect(AspectDefinition def, ClassLoader scopedClassLoader)
+ {
+ Object instance = null;
+ synchronized (def)
+ {
+ try
+ {
+ if (scopedClassLoader != null && def.getFactory() instanceof AspectFactoryWithClassLoader)
+ {
+ //If a scoped classloader with no parent delegation redefines the class, we need to make sure that that class is pushed on the stack
+ ((AspectFactoryWithClassLoader)def.getFactory()).pushScopedClassLoader(scopedClassLoader);
+ }
+ instance = def.getFactory().createPerVM();
+ initPerVMAspectsMap();
+ if (instance == null)
+ {
+ // indicates that the factory must not be called again
+ // the factory has already been called and returned null
+ perVMAspects.put(def.getName(), NULL_ASPECT);
+ }
+ else
+ {
+ perVMAspects.put(def.getName(), instance);
+ }
+ }
+ finally
+ {
+ if (scopedClassLoader != null && def.getFactory() instanceof AspectFactoryWithClassLoader)
+ {
+ ((AspectFactoryWithClassLoader)def.getFactory()).popScopedClassLoader();
+ }
+ }
+ }
+ return instance;
+ }
+
protected void initCFlowStacksMap()
{
if (cflowStacks == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
@@ -518,4 +622,31 @@
}
}
+ protected void initAspectDefintitionsMap()
+ {
+ if (aspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
+ {
+ synchronized(lazyCollectionLock)
+ {
+ if (aspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
+ {
+ aspectDefinitions = new ConcurrentHashMap<String, AspectDefinition>();
+ }
+ }
+ }
+ }
+
+ protected void initPerVMAspectsMap()
+ {
+ if (perVMAspects == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
+ {
+ synchronized(lazyCollectionLock)
+ {
+ if (perVMAspects == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_HASHMAP)
+ {
+ perVMAspects = new ConcurrentHashMap<String, Object>();
+ }
+ }
+ }
+ }
}
Modified: projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/spi/Manager.java
===================================================================
--- projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/spi/Manager.java 2009-02-23 16:17:45 UTC (rev 84638)
+++ projects/aop/branches/createspi/aop/src/main/java/org/jboss/aop/spi/Manager.java 2009-02-23 16:18:08 UTC (rev 84639)
@@ -321,8 +321,54 @@
* @return A map of advice stacks indexed by name
*/
Map<String, AdviceStack> getAdviceStacks();
+
+ /**
+ * Add an aspect definition
+ * @param def The aspect definition to add
+ */
+ void addAspectDefinition(AspectDefinition def);
+ /**
+ * Gets an aspect definition
+ * @param name The name of the aspect defintion
+ * @return The aspect definition
+ */
+ AspectDefinition getAspectDefinition(String name);
+ /**
+ * Removes an aspect definition
+ * @param removes an aspect definition
+ */
+ AspectDefinition removeAspectDefinition(String name);
+
+ /**
+ * Gets all the aspect definitions in this manger and its parent
+ * @return a map of aspect definitions indexed by name
+ */
+ Map<String, AspectDefinition> getAspectDefinitions();
+
+ /**
+ * Gets a per vm aspect instance for this manager. If it is not yet created it will be created
+ * @param name The name of the AspectDefintion for which we want to create an aspect instance
+ * @return The aspect instance
+ */
+ Object getPerVMAspect(String name);
+
+ /**
+ *@param name The name of the AspectDefintion for which we want to create an aspect instance
+ *@param def The aspect defintion
+ *@param
+ *@return The aspect instance
+ *
+ */
+ Object createPerVmAspect(AspectDefinition def, ClassLoader loader);
+
+ /**
+ * Gets all the per vm aspect instances in this manager and its parents
+ */
+ Map<String, Object> getPerVMAspects();
+
+
// InterceptionMarkers getInterceptionMarkers(ClassLoader loader);
//
// Map<String, Pointcut> getPointcuts();
More information about the jboss-cvs-commits
mailing list