6 Replies Latest reply on Jul 5, 2006 8:18 AM by kabirkhan

    Aop field interceptor to provide filtering for method call s

      Kabir,

      This is the issue that we discussed in Vegas:
      http://jira.jboss.com/jira/browse/JBCACHE-110

      Basically what I am looking for from PojoCache point of view is that, say, if while I am doing all field interception, but if it is from certain method call stack, then I don't care about it. So either aop not to intercept it or I have some knowledge that I can skip it.

      Is it possible for AOP to provide such funcationality?

        • 1. Re: Aop field interceptor to provide filtering for method ca
          kabirkhan

          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

            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

              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

                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

                  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

                    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