[jboss-cvs] JBossAS SVN: r68498 - in projects/aop/branches/joinpoint_graph/aop/src: main/org/jboss/aop/instrument and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 21 05:55:16 EST 2007
Author: flavia.rainone at jboss.com
Date: 2007-12-21 05:55:16 -0500 (Fri, 21 Dec 2007)
New Revision: 68498
Modified:
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/test/aop/dynamicgenadvisor/DynamicTester.java
Log:
[JBAOP-480] Sync mechanism is now being used on all the spots it should be.
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/Advisor.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -835,6 +835,26 @@
}
}
+ protected void lockWriteChain(MethodInterceptors methodInterceptors)
+ {
+ Object[] methodMatchInfos = methodInterceptors.infos.getValues();
+ for (int i = 0; i < methodMatchInfos.length; i++)
+ {
+ MethodMatchInfo methodMatchInfo = (MethodMatchInfo) methodMatchInfos[i];
+ methodMatchInfo.getInfo().getInterceptorChainReadWriteLock().writeLock().lock();
+ }
+ }
+
+ protected void unlockWriteChain(MethodInterceptors methodInterceptors)
+ {
+ Object[] methodMatchInfos = methodInterceptors.infos.getValues();
+ for (int i = 0; i < methodMatchInfos.length; i++)
+ {
+ MethodMatchInfo methodMatchInfo = (MethodMatchInfo) methodMatchInfos[i];
+ methodMatchInfo.getInfo().getInterceptorChainReadWriteLock().writeLock().unlock();
+ }
+ }
+
protected void resetChain(MethodInterceptors methodInterceptors)
{
Object[] methodMatchInfos = methodInterceptors.infos.getValues();
@@ -1024,6 +1044,22 @@
}
}
+ protected void lockWriteChain(JoinPointInfo[] infos)
+ {
+ for (int i = 0; i < infos.length; i++)
+ {
+ infos[i].getInterceptorChainReadWriteLock().writeLock().lock();
+ }
+ }
+
+ protected void unlockWriteChain(JoinPointInfo[] infos)
+ {
+ for (int i = 0; i < infos.length; i++)
+ {
+ infos[i].getInterceptorChainReadWriteLock().writeLock().unlock();
+ }
+ }
+
protected void resetChain(JoinPointInfo[] infos)
{
for (int i = 0; i < infos.length; i++)
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/ClassAdvisor.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -623,31 +623,47 @@
{
logger.debug("Updating chains for " + clazz + " " + ((clazz != null) ? clazz.getClassLoader() : null ));
}
- logger.debug("Updating chains for " + clazz + " " + ((clazz != null) ? clazz.getClassLoader() : null ));
- resetChain(methodInfos);
- resetChain(fieldReadInfos);
- resetChain(fieldWriteInfos);
- resetChain(constructorInfos);
- resetChain(constructionInfos);
-
- synchronized (manager.getBindings())
+
+ lockWriteChain(methodInfos);
+ lockWriteChain(fieldReadInfos);
+ lockWriteChain(fieldWriteInfos);
+ lockWriteChain(constructorInfos);
+ lockWriteChain(constructionInfos);
+ try
{
- Iterator it = manager.getBindings().values().iterator();
- while (it.hasNext())
+ resetChain(methodInfos);
+ resetChain(fieldReadInfos);
+ resetChain(fieldWriteInfos);
+ resetChain(constructorInfos);
+ resetChain(constructionInfos);
+
+ synchronized (manager.getBindings())
{
- AdviceBinding binding = (AdviceBinding) it.next();
- if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("iterate binding " + binding.getName() + " " + binding.getPointcut().getExpr());
- resolveMethodPointcut(binding);
- resolveFieldPointcut(fieldReadInfos, binding, false);
- resolveFieldPointcut(fieldWriteInfos, binding, true);
- resolveConstructorPointcut(binding);
- resolveConstructionPointcut(binding);
+ Iterator it = manager.getBindings().values().iterator();
+ while (it.hasNext())
+ {
+ AdviceBinding binding = (AdviceBinding) it.next();
+ if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("iterate binding " + binding.getName() + " " + binding.getPointcut().getExpr());
+ resolveMethodPointcut(binding);
+ resolveFieldPointcut(fieldReadInfos, binding, false);
+ resolveFieldPointcut(fieldWriteInfos, binding, true);
+ resolveConstructorPointcut(binding);
+ resolveConstructionPointcut(binding);
+ }
}
+
+ finalizeChains();
+ populateInterceptorsFromInfos();
}
-
- finalizeChains();
- populateInterceptorsFromInfos();
-
+ finally
+ {
+ unlockWriteChain(methodInfos);
+ unlockWriteChain(fieldReadInfos);
+ unlockWriteChain(fieldWriteInfos);
+ unlockWriteChain(constructorInfos);
+ unlockWriteChain(constructionInfos);
+ }
+
doesHaveAspects = adviceBindings.size() > 0;
// Notify observer about this change
if (this.interceptorChainObserver != null)
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -1069,9 +1069,17 @@
protected Object rebindJoinPointWithInstanceInformation(JoinPointInfo info)
{
- JoinPointGenerator generator = getJoinPointGenerator(info);
- generator.rebindJoinpoint(info);
- return generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+ info.getInterceptorChainReadWriteLock().readLock().lock();
+ try
+ {
+ JoinPointGenerator generator = getJoinPointGenerator(info);
+ generator.rebindJoinpoint(info);
+ return generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+ }
+ finally
+ {
+ info.getInterceptorChainReadWriteLock().readLock().unlock();
+ }
}
/**
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -46,8 +46,8 @@
{
static final long serialVersionUID = -3057976129116723527L;
- protected ArrayList insertedInterceptors = null;
- protected ArrayList appendedInterceptors = null;
+ protected ArrayList<Interceptor> insertedInterceptors = null;
+ protected ArrayList<Interceptor> appendedInterceptors = null;
protected WeakReference instanceRef;
public boolean hasInstanceAspects = false;
private InterceptorChainObserver interceptorChainObserver;
@@ -198,7 +198,7 @@
public void appendInterceptor(Interceptor interceptor)
{
- ArrayList newList = new ArrayList();
+ ArrayList<Interceptor> newList = new ArrayList<Interceptor>();
if (appendedInterceptors != null)
{
newList.addAll(appendedInterceptors);
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/JoinPointInfo.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -245,8 +245,8 @@
return adviceString;
}
- public final ReentrantReadWriteLock.ReadLock getInterceptorChainReadLock()
+ public final ReentrantReadWriteLock getInterceptorChainReadWriteLock()
{
- return this.interceptorChainLock.readLock();
+ return this.interceptorChainLock;
}
}
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -64,7 +64,8 @@
private static final String CHECK_VERSION = "checkVersion";
private static final String ADVICES_UPDATED = "advicesUpdated";
private static final String INSTANCE_ADVISOR_MIXIN = "instanceAdvisorMixin";
-
+ private static final String PARENT = "parent";
+
//method names in advisor or GeneratedClassAdvisor
private static final String CREATE_INSTANCE_ADVISOR = "createInstanceAdvisor";
private static final String INITIALISE_CALLERS = "initialiseCallers";
@@ -76,7 +77,9 @@
private static final String INITIALISE_INFOS_FOR_INSTANCE = "initialiseInfosForInstance";
public static final String GET_CLASS_ADVISOR = "_getClassAdvisor";
private static final String DO_REBUILD_FOR_INSTANCE = "doRebuildForInstance";
-
+ private static final String LOCK_WRITE_CHAINS = "lockWriteInterceptorChains";
+ private static final String UNLOCK_WRITE_CHAINS = "unlockWriteInterceptorChains";
+
private static final String DECLARING_CLASS = "this.getClass().getDeclaringClass()";
@@ -336,15 +339,41 @@
genInstanceAdvisor);
genInstanceAdvisor.addMethod(advicesUpdated);
+ // method that enables the write locks on all interceptor chains
+ CtMethod lockWriteChains = CtNewMethod.make(
+ Modifier.PROTECTED,
+ CtClass.voidType,
+ LOCK_WRITE_CHAINS,
+ EMPTY_SIG,
+ EMPTY_EXCEPTIONS,
+ null,
+ genInstanceAdvisor);
+ genInstanceAdvisor.addMethod(lockWriteChains);
+
+ // method that disables the write locks on all interceptor chains
+ CtMethod unlockWriteChains = CtNewMethod.make(
+ Modifier.PROTECTED,
+ CtClass.voidType,
+ UNLOCK_WRITE_CHAINS,
+ EMPTY_SIG,
+ EMPTY_EXCEPTIONS,
+ null,
+ genInstanceAdvisor);
+ genInstanceAdvisor.addMethod(unlockWriteChains);
+
implementInstanceAdvisorMethods();
-
+
String drfiBody =
"{" +
- " internalRebuildInterceptors(); " +
- " if (" + INSTANCE_ADVISOR_MIXIN + ".hasInterceptors())" +
+ LOCK_WRITE_CHAINS + "();" +
+ " try" +
" {" +
- " " + ADVICES_UPDATED + "();" +
- " }" +
+ " internalRebuildInterceptors(); " +
+ " if (" + INSTANCE_ADVISOR_MIXIN + ".hasInterceptors())" +
+ " {" +
+ " " + ADVICES_UPDATED + "();" +
+ " }" +
+ " } finally { " + UNLOCK_WRITE_CHAINS + "();}" +
"}";
CtMethod doRebuildForInstance = CtNewMethod.make(
Modifier.PROTECTED,
@@ -355,11 +384,14 @@
drfiBody,
genInstanceAdvisor);
genInstanceAdvisor.addMethod(doRebuildForInstance);
-
+
+ CtField parentField = new CtField(this.getGenadvisor(), PARENT, genInstanceAdvisor);
+ genInstanceAdvisor.addField(parentField, "null");
String body =
"{" +
" super($2);" +
" " + INSTANCE_ADVISOR_MIXIN + " = new org.jboss.aop.GeneratedInstanceAdvisorMixin($1, $2);" +
+ " " + PARENT + " = $2;" +
"}";
CtConstructor ctor = CtNewConstructor.make(new CtClass[]{forName("java.lang.Object"), genadvisor}, new CtClass[0], body, genInstanceAdvisor);
genInstanceAdvisor.addConstructor(ctor);
@@ -479,8 +511,11 @@
String ret = (instanceAdvisorMethods[i].getReturnType().equals(CtClass.voidType)) ? "" : "return ";
StringBuffer delegatingBody = new StringBuffer();
delegatingBody.append("{");
+ boolean changeInterceptorChainsOperation = false;
if (name.startsWith("insertInterceptor") || name.startsWith("removeInterceptor") || name.startsWith("appendInterceptor"))
{
+ changeInterceptorChainsOperation = true;
+ delegatingBody.append(LOCK_WRITE_CHAINS).append("();").append("try {");
delegatingBody.append(ADVICES_UPDATED + "();");
}
if (!instanceAdvisorMethods[i].getReturnType().equals(CtClass.voidType))
@@ -488,7 +523,11 @@
delegatingBody.append("return ");
}
delegatingBody.append(INSTANCE_ADVISOR_MIXIN + "." + instanceAdvisorMethods[i].getName() + "($$);}");
-
+ if (changeInterceptorChainsOperation)
+ {
+ delegatingBody.append(" finally {").append(UNLOCK_WRITE_CHAINS).append("();}}");
+ }
+
CtMethod m = CtNewMethod.make(
Modifier.PUBLIC,
instanceAdvisorMethods[i].getReturnType(),
@@ -618,6 +657,8 @@
StringBuffer advicesUpdatedCode = new StringBuffer();
StringBuffer initialiseInfosForInstanceCode = new StringBuffer();
+ StringBuffer lockWriteChainsCode = new StringBuffer();
+ StringBuffer unlockWriteChainsCode = new StringBuffer();
initialiseInfosForInstanceCode.append("java.util.Collection fieldReadCol = new java.util.ArrayList();");
initialiseInfosForInstanceCode.append("java.util.Collection fieldWriteCol = new java.util.ArrayList();");
//initialiseInfosForInstanceCode.append("methodInfos = new org.jboss.aop.MethodInterceptors($0);");
@@ -650,6 +691,8 @@
{
String code = infoName + " = super.copyInfoFromClassAdvisor(((" + genadvisor.getName() + ")" + clazz.getName() + "." + GET_CLASS_ADVISOR + "())." + infoName + ");";
initialiseInfosForInstanceCode.append(code);
+ lockWriteChainsCode.append(infoName).append(".getInterceptorChainReadWriteLock().writeLock().lock();");
+ unlockWriteChainsCode.append(infoName).append(".getInterceptorChainReadWriteLock().writeLock().unlock();");
}
if (infoClassName.equals(FieldInfo.class.getName()))
{
@@ -679,6 +722,11 @@
CtMethod advicesUpdated = genInstanceAdvisor.getDeclaredMethod(ADVICES_UPDATED);
advicesUpdated.insertAfter(advicesUpdatedCode.toString());
+
+ CtMethod lockWriteChains = genInstanceAdvisor.getDeclaredMethod(LOCK_WRITE_CHAINS);
+ lockWriteChains.insertAfter(lockWriteChainsCode.toString());
+ CtMethod unlockWriteChains = genInstanceAdvisor.getDeclaredMethod(UNLOCK_WRITE_CHAINS);
+ unlockWriteChains.insertAfter(unlockWriteChainsCode.toString());
}
private String addAdvicesUpdatedForJoinpointField(String infoName) throws NotFoundException, CannotCompileException
@@ -713,12 +761,15 @@
CHECK_VERSION + "();" +
"if (" + updatedAdvicesFieldName + ")" +
"{ " +
- " " + JoinPointInfo.class.getName() + " copy = " + names.getInfoFieldName() + ".copy();" +
- " copy.setInterceptors( " + INSTANCE_ADVISOR_MIXIN + ".getWrappers(copy.getInterceptors()) );" +
- " " + updatedAdvicesFieldName + " = false;" +
- " " + names.getJoinPointField().getName() + " = null;" +
-// " " + names.getInfoFieldName() + ".setInterceptors(copy.getInterceptors());" + //We need a way to make this "transient"
- " super.rebindJoinPointWithInstanceInformation(copy);" +
+ " " + names.getInfoFieldName() + ".getInterceptorChainReadWriteLock().writeLock().lock();" +
+ " try" +
+ " {" +
+ " " + names.getInfoFieldName() + ".setInterceptors( " + INSTANCE_ADVISOR_MIXIN + ".getWrappers(" + PARENT + "." + names.getInfoFieldName() + ".getInterceptors()) );" +
+ " " + names.getJoinPointField().getName() + " = null;" +
+ " " + updatedAdvicesFieldName + " = false;" +
+ " super.rebindJoinPointWithInstanceInformation(" + names.getInfoFieldName() + ");" +
+ " } finally {" +
+ " " + names.getInfoFieldName() + ".getInterceptorChainReadWriteLock().writeLock().unlock();}" +
"}";
instanceAdvisorMethod.insertBefore(code);
genInstanceAdvisor.addMethod(instanceAdvisorMethod);
@@ -802,12 +853,12 @@
// TODO remove this code and put it somewhere common to all ga transformers.
static String generateInterceptorChainLockCode(String infoName)
{
- return infoName + ".getInterceptorChainReadLock().lock();";
+ return infoName + ".getInterceptorChainReadWriteLock().readLock().lock();";
}
static String generateInterceptorChainUnlockCode(String infoName)
{
- return infoName + ".getInterceptorChainReadLock().unlock();";
+ return infoName + ".getInterceptorChainReadWriteLock().readLock().unlock();";
}
private void addCodeToInitialiseMethod(CtClass clazz, String code, String methodName) throws NotFoundException
@@ -953,4 +1004,4 @@
return infoName;
}
}
-}
+}
\ No newline at end of file
Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -270,7 +270,7 @@
//Attempt to get the cached information so we don't have to recreate the class every time we rebind the joinpoint
String infoAdviceString = info.getAdviceString();
- GeneratedClassInfo generatedClass = (GeneratedClassInfo)generatedJoinPointClassCache.get(infoAdviceString);
+ GeneratedClassInfo generatedClass = (GeneratedClassInfo) generatedJoinPointClassCache.get(infoAdviceString);
Class clazz = null;
if (generatedClass != null)
{
Modified: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/test/aop/dynamicgenadvisor/DynamicTester.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/test/aop/dynamicgenadvisor/DynamicTester.java 2007-12-21 10:49:55 UTC (rev 68497)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/test/aop/dynamicgenadvisor/DynamicTester.java 2007-12-21 10:55:16 UTC (rev 68498)
@@ -653,54 +653,58 @@
POJO pojo1 = new POJO();
AdviceBinding bindingTopA = new AdviceBinding("execution(* org.jboss.test.aop.dynamicgenadvisor.*POJO->someMethod*(..))", null);
String nameTopA = bindingTopA.getName();
- AspectDefinition myAspect = AspectManager.instance().getAspectDefinition("org.jboss.test.aop.dynamicgenadvisor.MyAspect");
- bindingTopA.addInterceptorFactory(new AdviceFactory(myAspect, "intercept"));
- AspectManager.instance().addBinding(bindingTopA);
-
- Interceptions.clear();
- pojo1.someMethod(123);
- assertEquals(1, Interceptions.size());
- assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(0));
-
- System.out.println("---- Adding more interceptors");
-
- InstanceAdvisor pojoIa1 = ((Advised)pojo1)._getInstanceAdvisor();
- pojoIa1.insertInterceptor(new MyInterceptor());
-
- Interceptions.clear();
- pojo1.someMethod(123);
- assertEquals(2, Interceptions.size());
- assertEquals(Interceptions.getMethodName("MyInterceptor", "POJO", "someMethod"), Interceptions.get(0));
- assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(1));
+ try
+ {
+ AspectDefinition myAspect = AspectManager.instance().getAspectDefinition("org.jboss.test.aop.dynamicgenadvisor.MyAspect");
+ bindingTopA.addInterceptorFactory(new AdviceFactory(myAspect, "intercept"));
+ AspectManager.instance().addBinding(bindingTopA);
- pojoIa1.appendInterceptor(new YourInterceptor());
-
- Interceptions.clear();
- pojo1.someMethod(123);
- assertEquals(3, Interceptions.size());
- assertEquals(Interceptions.getMethodName("MyInterceptor", "POJO", "someMethod"), Interceptions.get(0));
- assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(1));
- assertEquals(Interceptions.getMethodName("YourInterceptor", "POJO", "someMethod"), Interceptions.get(2));
+ Interceptions.clear();
+ pojo1.someMethod(123);
+ assertEquals(1, Interceptions.size());
+ assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(0));
- System.out.println("Testing SubPOJO");
- SubPOJO sub1 = new SubPOJO();
- Interceptions.clear();
- sub1.someMethod(123);
- assertEquals(1, Interceptions.size());
- assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(0));
-
- InstanceAdvisor subPojoIa1 = ((Advised)sub1)._getInstanceAdvisor();
- subPojoIa1.insertInterceptor(new MyInterceptor());
- subPojoIa1.appendInterceptor(new YourInterceptor());
-
- Interceptions.clear();
- sub1.someMethod(123);
- assertEquals(3, Interceptions.size());
- assertEquals(Interceptions.getMethodName("MyInterceptor", "POJO", "someMethod"), Interceptions.get(0));
- assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(1));
- assertEquals(Interceptions.getMethodName("YourInterceptor", "POJO", "someMethod"), Interceptions.get(2));
-
- AspectManager.instance().removeBinding(nameTopA);
+ System.out.println("---- Adding more interceptors");
+
+ InstanceAdvisor pojoIa1 = ((Advised)pojo1)._getInstanceAdvisor();
+ pojoIa1.insertInterceptor(new MyInterceptor());
+
+ Interceptions.clear();
+ pojo1.someMethod(123);
+ assertEquals(2, Interceptions.size());
+ assertEquals(Interceptions.getMethodName("MyInterceptor", "POJO", "someMethod"), Interceptions.get(0));
+ assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(1));
+
+ pojoIa1.appendInterceptor(new YourInterceptor());
+
+ Interceptions.clear();
+ pojo1.someMethod(123);
+ assertEquals(Interceptions.getMethodName("MyInterceptor", "POJO", "someMethod"), Interceptions.get(0));
+ assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(1));
+ assertEquals(Interceptions.getMethodName("YourInterceptor", "POJO", "someMethod"), Interceptions.get(2));
+
+ System.out.println("Testing SubPOJO");
+ SubPOJO sub1 = new SubPOJO();
+ Interceptions.clear();
+ sub1.someMethod(123);
+ assertEquals(1, Interceptions.size());
+ assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(0));
+
+ InstanceAdvisor subPojoIa1 = ((Advised)sub1)._getInstanceAdvisor();
+ subPojoIa1.insertInterceptor(new MyInterceptor());
+ subPojoIa1.appendInterceptor(new YourInterceptor());
+
+ Interceptions.clear();
+ sub1.someMethod(123);
+ assertEquals(3, Interceptions.size());
+ assertEquals(Interceptions.getMethodName("MyInterceptor", "POJO", "someMethod"), Interceptions.get(0));
+ assertEquals(Interceptions.getMethodName("MyAspect", "POJO", "someMethod"), Interceptions.get(1));
+ assertEquals(Interceptions.getMethodName("YourInterceptor", "POJO", "someMethod"), Interceptions.get(2));
+ }
+ finally
+ {
+ AspectManager.instance().removeBinding(nameTopA);
+ }
}
public void testAddAnnotation() throws Exception
More information about the jboss-cvs-commits
mailing list