[jboss-cvs] JBossAS SVN: r73177 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop/rebuildcallerchain and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 8 17:43:26 EDT 2008
Author: stalep
Date: 2008-05-08 17:43:25 -0400 (Thu, 08 May 2008)
New Revision: 73177
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller1.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller2.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainInterceptor.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainTestCase.java
Log:
[JBAOP-433] changed usage of the cached call list to use AM.bindings, when rebuilding the chain.
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java 2008-05-08 20:33:42 UTC (rev 73176)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java 2008-05-08 21:43:25 UTC (rev 73177)
@@ -790,16 +790,59 @@
private ArrayList<AdviceBinding> getConstructorCallerBindings(int callingIndex, String cname, long calledHash)
{
- HashMap<String, TLongObjectHashMap> calledClasses = methodCalledByConBindings[callingIndex];
- TLongObjectHashMap calledMethods = calledClasses.get(cname);
- return (ArrayList<AdviceBinding>) calledMethods.get(calledHash);
+ try
+ {
+ Constructor<?> callingConstructor = constructors[callingIndex];
+ if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
+ // FIXME ClassLoader - how do we know the class is visible from the context classloader?
+ Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+ Method calledMethod = MethodHashing.findMethodByHash(called, calledHash);
+ if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut");
+
+ ArrayList<AdviceBinding> bindings = new ArrayList<AdviceBinding>(manager.getBindings().size());
+ for(AdviceBinding ab : manager.getBindings().values())
+ {
+ if (ab.getPointcut().matchesCall(this, callingConstructor, called, calledMethod))
+ {
+ bindings.add(ab);
+ }
+ }
+
+ return bindings;
+ }
+ catch(Exception e)
+ {
+ logger.error("Error happened with methodCallConBinding",e);
+ return new ArrayList<AdviceBinding>();
+ }
}
private ArrayList<AdviceBinding> getConCalledByConBindings(int callingIndex, String cname, long calledHash)
{
- HashMap<String, TLongObjectHashMap> calledClasses = conCalledByConBindings[callingIndex];
- TLongObjectHashMap calledMethods = calledClasses.get(cname);
- return (ArrayList<AdviceBinding>) calledMethods.get(calledHash);
+ try
+ {
+ Constructor<?> callingConstructor = constructors[callingIndex];
+ if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
+ // FIXME ClassLoader - how do we know the class is visible from the context classloader?
+ Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+ Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledHash);
+ if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a caller pointcut");
+
+ ArrayList<AdviceBinding> bindings = new ArrayList<AdviceBinding>(manager.getBindings().size());
+ for(AdviceBinding ab : manager.getBindings().values())
+ {
+ if (ab.getPointcut().matchesCall(this, callingConstructor, called, calledCon))
+ {
+ bindings.add(ab);
+ }
+ }
+ return bindings;
+ }
+ catch(Exception e)
+ {
+ logger.error("Error happened for conCalledConBindings", e);
+ return new ArrayList<AdviceBinding>();
+ }
}
protected void finalizeMethodCalledByMethodInterceptorChain(MethodByMethodInfo info)
@@ -2224,10 +2267,30 @@
private ArrayList<AdviceBinding> getCallerBindings(long callingHash, String cname, long calledHash)
{
- //Called via resolveCallerMethodInfo, maps are initialised
- HashMap<String, TLongObjectHashMap> calledClasses = (HashMap<String, TLongObjectHashMap>) methodCalledByMethodBindings.get(callingHash);
- TLongObjectHashMap calledMethods = calledClasses.get(cname);
- return (ArrayList<AdviceBinding>) calledMethods.get(calledHash);
+ try
+ {
+ Method callingMethod = MethodHashing.findMethodByHash(clazz, callingHash);
+ if (callingMethod == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
+ // FIXME ClassLoader - how do we know the class is visible from the context classloader?
+ Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+ Method calledMethod = MethodHashing.findMethodByHash(called, calledHash);
+ if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut");
+
+ ArrayList<AdviceBinding> bindings = new ArrayList<AdviceBinding>(manager.getBindings().size());
+ for(AdviceBinding ab : manager.getBindings().values())
+ {
+ if (ab.getPointcut().matchesCall(ClassAdvisor.this, callingMethod, called, calledMethod))
+ {
+ bindings.add(ab);
+ }
+ }
+ return bindings;
+ }
+ catch(Exception e)
+ {
+ logger.error("Error happened when getting callerBindings",e);
+ return new ArrayList<AdviceBinding>();
+ }
}
private void bindCallerInterceptorChain(ArrayList<AdviceBinding> bindings, long callingHash, String cname, long calledHash, Method calling)
@@ -2272,10 +2335,32 @@
}
public ArrayList<AdviceBinding> getConCalledByMethodBindings(long callingHash, String cname, long calledHash)
- {
- HashMap<String, TLongObjectHashMap> calledClasses = (HashMap<String, TLongObjectHashMap>) conCalledByMethodBindings.get(callingHash);
- TLongObjectHashMap calledCons = calledClasses.get(cname);
- return (ArrayList<AdviceBinding>) calledCons.get(calledHash);
+ {
+ try
+ {
+ Method callingMethod = MethodHashing.findMethodByHash(clazz, callingHash);
+ if (callingMethod == null) throw new RuntimeException("Unable to figure out calling method of a constructor caller pointcut");
+ // FIXME ClassLoader - how do we know the class is visible from the context classloader?
+ Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+ Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledHash);
+ if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a constructor caller pointcut");
+
+ ArrayList<AdviceBinding> bindings = new ArrayList<AdviceBinding>(manager.getBindings().size());
+ for(AdviceBinding ab : manager.getBindings().values())
+ {
+ if (ab.getPointcut().matchesCall(ClassAdvisor.this, callingMethod, called, calledCon))
+ {
+ bindings.add(ab);
+ }
+ }
+ return bindings;
+ }
+ catch(Exception e)
+ {
+ logger.error("Error happened conCalledMethod bindings", e);
+ return new ArrayList<AdviceBinding>();
+ }
+
}
public void rebuildCallerInterceptors() throws Exception
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller1.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller1.java 2008-05-08 20:33:42 UTC (rev 73176)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller1.java 2008-05-08 21:43:25 UTC (rev 73177)
@@ -29,13 +29,18 @@
*/
public class Caller1
{
+ public Caller1() { }
+
+ public Caller1(boolean b){ }
+
+ public Caller1(int i) { }
public void execute() throws Exception
{
-// throw new Exception("This method should not have been called!");
}
- public void foo() {
+ public void foo()
+ {
}
}
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller2.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller2.java 2008-05-08 20:33:42 UTC (rev 73176)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/Caller2.java 2008-05-08 21:43:25 UTC (rev 73177)
@@ -29,9 +29,15 @@
*/
public class Caller2
{
+
+ public Caller2() { }
+
+ public Caller2(boolean b)
+ {
+ new Caller1(1);
+ }
public void execute() throws Exception
{
-// throw new Exception("This method should not have been called!");
}
}
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainInterceptor.java 2008-05-08 20:33:42 UTC (rev 73176)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainInterceptor.java 2008-05-08 21:43:25 UTC (rev 73177)
@@ -33,20 +33,18 @@
*/
public class RebuildCallerChainInterceptor implements Interceptor
{
- public static boolean method = false;
- //@Override
+ public static boolean call = false;
+
public String getName()
{
return this.getClass().getName();
}
- //@Override
public Object invoke(Invocation invocation) throws Throwable
{
try
{
-// System.out.println("Interceptor ignoring call...");
- method = true;
+ call = true;
return invocation.invokeNext();
}
catch(Exception e)
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainTestCase.java 2008-05-08 20:33:42 UTC (rev 73176)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildcallerchain/RebuildCallerChainTestCase.java 2008-05-08 21:43:25 UTC (rev 73177)
@@ -48,30 +48,47 @@
suite.addTestSuite(RebuildCallerChainTestCase.class);
return suite;
}
+
+ public void testRebuildCallerChainConCalledCon() throws Exception
+ {
+ try
+ {
+// new Caller2(); // concallcon wont work if the class is already loaded by the cl
+
+ AdviceBinding bindingCall = new AdviceBinding(
+ "call(org.jboss.test.aop.rebuildcallerchain.Caller1->new(int))", null);
+ bindingCall.addInterceptor(RebuildCallerChainInterceptor.class);
+ AspectManager.instance().addBinding(bindingCall);
- public void testRebuildCallerChain() throws Exception
+ RebuildCallerChainInterceptor.call = false;
+ new Caller2(true);
+ assertTrue("caller2 was not rebuilded", RebuildCallerChainInterceptor.call);
+ }
+ catch (Exception e)
+ {
+ assertFalse("Failed to rebuild chain....", true);
+ }
+ }
+
+ public void testRebuildCallerChainMethodCalledMethod() throws Exception
{
try
{
-// new Caller1().execute();
-
+ new Caller1().execute();
+
AdviceBinding bindingCall = new AdviceBinding(
"call(* org.jboss.test.aop.rebuildcallerchain.*->execute())", null);
bindingCall.addInterceptor(RebuildCallerChainInterceptor.class);
-
AspectManager.instance().addBinding(bindingCall);
- new Caller1().execute(); // loaded before addBinding => not ok
- assertTrue("caller1 was not rebuilded", RebuildCallerChainInterceptor.method);
- RebuildCallerChainInterceptor.method = false;
- new Caller2().execute(); // loaded after addBindingok => ok
- assertTrue("caller2 not ok", RebuildCallerChainInterceptor.method);
-// assertTrue("Rebuilded chain", true);
+ new Caller1().execute();
+ assertTrue("caller1 was not rebuilded", RebuildCallerChainInterceptor.call);
+ RebuildCallerChainInterceptor.call = false;
}
catch (Exception e)
{
assertFalse("Failed to rebuild chain....", true);
}
-}
+ }
}
More information about the jboss-cvs-commits
mailing list