-
1. Re: Aop field interceptor to provide filtering for method ca
kabirkhan Jun 30, 2006 7:58 AM (in response to ben.wang)I think the simplest approach is to have an interceptor at the start of the chain, which manages this.
public class ReentrancyStopperInterceptor implements Interceptor { ThreadLocal done = new ThreadLocal(); private Object invoke(Invocation invocation) throws Throwable { boolean wasDone = ((Boolean)done.get()).booleanValue(); try { if (!wasDone) { done.set(Boolean.TRUE); return invocation.invokeNext(); } else { //Needs adding, and will invoke target joinpoint skipping the rest of the chain return invocation.dispatch(); } } finally { if (!wasDone) { done.set(Boolean.FALSE); } } return ret; } }
I could implement the new dispatch() method pretty quickly, and I think this interceptor should belong in the aop module.
Similar functionality _could_ be added to the woven bytecode, but I don't think it is a good idea to code use-case stuff in there. -
2. Re: Aop field interceptor to provide filtering for method ca
ben.wang Jun 30, 2006 8:35 AM (in response to ben.wang)Sounds good. But we need to consider the following calling stack:
pojo.methodA(); pojo.methodB(); ... pojo.methodB(); // so we can skip this field interception pojo.methodA(); // oops, it will fail.
So in essence, we need to have a local thread array done[] such that this will work properly. -
3. Re: Aop field interceptor to provide filtering for method ca
kabirkhan Jun 30, 2006 8:51 AM (in response to ben.wang)Hmmm, I'm not getting you, please elaborate.
BTW the interceptor I outlined was for field interception, and would be used only for a field for a particular instance. I see now that it was a bit too simple. It should really be scoped PER_JOINPOINT, so that the "done" book-keeping is only done for a particular field. Now, this is not possible with the existing InstanceAdvisor API, since per instance aspect added there apply to ALL joinpoints. However, with the new AOP 2 weaving this is possible. Take a look at
org.jboss.test.aop.dynamicgenadvisor.DynamicTester to see how this works. -
4. Re: Aop field interceptor to provide filtering for method ca
ben.wang Jul 5, 2006 2:54 AM (in response to ben.wang)Ok, what I meant more properly is the PER_JOINTPOINT scope that you proposed where we track the recursion call at the joint point scope.
Now which test specifically you were referring to? I don't see any PER_JOINTPOINT scope test. :-) -
5. Re: Aop field interceptor to provide filtering for method ca
kabirkhan Jul 5, 2006 4:36 AM (in response to ben.wang)I meant the DynamicTester. It shows how the new per instance API works :-)
-
6. Re: Aop field interceptor to provide filtering for method ca
kabirkhan Jul 5, 2006 8:18 AM (in response to ben.wang)Hi Ben,
I have added this method to the invocation object in head. I have called it invokeTarget() instead of dispatch().
http://jira.jboss.com/jira/browse/JBAOP-270