[jboss-cvs] JBossAS SVN: r82579 - projects/aop/trunk/aop/src/main/org/jboss/aop.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 31 20:44:35 EST 2008
Author: flavia.rainone at jboss.com
Date: 2008-12-31 20:44:34 -0500 (Wed, 31 Dec 2008)
New Revision: 82579
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/ClassInstanceAdvisor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
Log:
[JBAOP-573] The bug is fixed now. An auxiliary map holds interceptors mapped to the correspondent stack names and is now used for stack removal.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassInstanceAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassInstanceAdvisor.java 2009-01-01 01:06:36 UTC (rev 82578)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassInstanceAdvisor.java 2009-01-01 01:44:34 UTC (rev 82579)
@@ -21,17 +21,18 @@
*/
package org.jboss.aop;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
import org.jboss.aop.advice.AdviceStack;
import org.jboss.aop.advice.AspectDefinition;
import org.jboss.aop.advice.Interceptor;
-import org.jboss.aop.advice.InterceptorFactory;
import org.jboss.aop.joinpoint.Joinpoint;
import org.jboss.aop.metadata.SimpleMetaData;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
-
/**
* Holds an object instance's metadata and attached interceptors
*
@@ -47,6 +48,9 @@
protected WeakReference<Object> instanceRef;
protected transient WeakReference<Advisor> classAdvisorRef;
public boolean hasInstanceAspects = false;
+ protected Map<String,Interceptor[]> stacks = null;
+
+
/**
* aspects is a weak hash map of AspectDefinitions so that perinstance advices can be undeployed/redeployed
*/
@@ -268,21 +272,20 @@
Advised advised = (Advised) getInstance();
classAdvisor = ((ClassAdvisor) advised._getAdvisor());
}
- int interceptorsAdded = 0;
- for (InterceptorFactory factory : stack.getInterceptorFactories())
+
+ Interceptor[] interceptors = stack.createInterceptors(classAdvisor, null);
+ for (Interceptor interceptor: interceptors)
{
- if (!factory.isDeployed()) continue;
- Interceptor interceptor = factory.create(classAdvisor, null);
- if (interceptor == null)
- {
- continue;
- }
insertInterceptor(interceptor);
- interceptorsAdded ++;
}
+ if (this.stacks == null)
+ {
+ this.stacks = new HashMap<String, Interceptor[]>();
+ }
+ this.stacks.put(stackName, interceptors);
if (interceptorChainObserver != null)
{
- this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptorsAdded);
+ this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptors.length);
}
}
@@ -297,44 +300,38 @@
Advised advised = (Advised) getInstance();
classAdvisor = ((ClassAdvisor) advised._getAdvisor());
}
- int interceptorsAdded = 0;
- for (InterceptorFactory factory : stack.getInterceptorFactories())
+
+ Interceptor[] interceptors = stack.createInterceptors(classAdvisor, null);
+ for (Interceptor interceptor: interceptors)
{
- if (!factory.isDeployed()) continue;
- Interceptor interceptor = factory.create(classAdvisor, null);
- if (interceptor == null)
- {
- continue;
- }
appendInterceptor(interceptor);
- interceptorsAdded ++;
}
+ if (this.stacks == null)
+ {
+ this.stacks = new HashMap<String, Interceptor[]>();
+ }
+ this.stacks.put(stackName, interceptors);
if (interceptorChainObserver != null)
{
- this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptorsAdded);
+ this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptors.length);
}
}
public void removeInterceptorStack(String stackName)
{
- AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
- if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
-
- ClassAdvisor classAdvisor = null;
- if (getInstance() instanceof Advised)
+ Interceptor[] interceptors = stacks.remove(stackName);
+
+ if (interceptors == null)
{
- Advised advised = (Advised) getInstance();
- classAdvisor = ((ClassAdvisor) advised._getAdvisor());
+ AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
+ if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
+ return;
}
+
int interceptorsRemoved = 0;
- for (InterceptorFactory factory : stack.getInterceptorFactories())
+ for (Interceptor interceptor: interceptors)
{
- if (!factory.isDeployed()) continue;
- Interceptor interceptor = factory.create(classAdvisor, null);
- if (interceptor != null)
- {
- interceptorsRemoved += internalRemoveInterceptor(interceptor.getName());
- }
+ interceptorsRemoved += internalRemoveInterceptor(interceptor.getName());
}
if (interceptorChainObserver != null)
{
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java 2009-01-01 01:06:36 UTC (rev 82578)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java 2009-01-01 01:44:34 UTC (rev 82579)
@@ -33,6 +33,8 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
/**
* Adapts the old instance advisor api to the new generated advisor stuff.
@@ -51,6 +53,7 @@
public boolean hasInstanceAspects = false;
private InterceptorChainObserver interceptorChainObserver;
InstanceAdvisorDelegate delegate;
+ protected Map<String,Interceptor[]> stacks = null;
public GeneratedInstanceAdvisorMixin()
{
@@ -310,21 +313,20 @@
Advised advised = (Advised) inst;
classAdvisor = ((ClassAdvisor) advised._getAdvisor());
}
- int interceptorsAdded = 0;
- for (InterceptorFactory factory : stack.getInterceptorFactories())
+
+ Interceptor[] interceptors = stack.createInterceptors(classAdvisor, null);
+ for (Interceptor interceptor: interceptors)
{
- if (!factory.isDeployed()) continue;
- Interceptor interceptor = factory.create(classAdvisor, null);
- if (interceptor == null)
- {
- continue;
- }
insertInterceptor(interceptor);
- interceptorsAdded ++;
}
+ if (this.stacks == null)
+ {
+ this.stacks = new HashMap<String, Interceptor[]>();
+ }
+ this.stacks.put(stackName, interceptors);
if (interceptorChainObserver != null)
{
- this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptorsAdded);
+ this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptors.length);
}
}
@@ -340,45 +342,38 @@
Advised advised = (Advised) inst;
classAdvisor = ((ClassAdvisor) advised._getAdvisor());
}
- int interceptorsAdded = 0;
- for (InterceptorFactory factory : stack.getInterceptorFactories())
+
+ Interceptor[] interceptors = stack.createInterceptors(classAdvisor, null);
+ for (Interceptor interceptor: interceptors)
{
- if (!factory.isDeployed()) continue;
- Interceptor interceptor = factory.create(classAdvisor, null);
- if (interceptor == null)
- {
- continue;
- }
appendInterceptor(interceptor);
- interceptorsAdded ++;
}
+ if (this.stacks == null)
+ {
+ this.stacks = new HashMap<String, Interceptor[]>();
+ }
+ this.stacks.put(stackName, interceptors);
if (interceptorChainObserver != null)
{
- this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptorsAdded);
+ this.interceptorChainObserver.instanceInterceptorsAdded(this, interceptors.length);
}
}
public void removeInterceptorStack(String stackName)
{
- AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
- if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
-
- ClassAdvisor classAdvisor = null;
- Object inst = getInstance();
- if (inst instanceof Advised)
+ Interceptor[] interceptors = stacks.remove(stackName);
+
+ if (interceptors == null)
{
- Advised advised = (Advised) inst;
- classAdvisor = ((ClassAdvisor) advised._getAdvisor());
+ AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
+ if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
+ return;
}
+
int interceptorsRemoved = 0;
- for (InterceptorFactory factory : stack.getInterceptorFactories())
+ for (Interceptor interceptor: interceptors)
{
- if (!factory.isDeployed()) continue;
- Interceptor interceptor = factory.create(classAdvisor, null);
- if (interceptor != null)
- {
- interceptorsRemoved += internalRemoveInterceptor(interceptor.getName());
- }
+ interceptorsRemoved += internalRemoveInterceptor(interceptor.getName());
}
if (interceptorChainObserver != null)
{
More information about the jboss-cvs-commits
mailing list