3 Replies Latest reply on Dec 19, 2004 5:50 PM by kabirkhan

    Methods via Reflection and MBean interception

    jlukiano

      I get confused when I noted that the reflection API must be be used to intercept even methods.

      "There are two issues with using the Reflection API with JBoss AOP
      Aspects applied to constructors, fields and methods are bypassed
      ..."


      On previous version of this API:
      "Aspects applied to constructors and fields are bypassed "


      Only constructors and fields were bypassed.

      To my mind, the method interception was the only that wouldn't cause bytecode transformation on the caller classes, due to the called class could have the original method renamed and replaced by a new one, that would fire the interceptions, so methods executed via Reflection would be intercepted if set up so.

      It seems that it changed on the Final release, now method interception cause transformation on the caller classes, any special reason?

      I have another doubt that may be related to Reflection. MBean services are executed via Reflection by the MBean server, aren't they? Is it possible to intercept FieldRead of a MBean? I have tried unsuccessfully.

        • 1. Re: Methods via Reflection and MBean interception
          kabirkhan

          From: http://docs.jboss.org/aop/aspect-framework/reference/en/html/reflection.html#reflection-attach-chains

          Intereptors/aspects bound to exexcution pointcuts for fields and constructors don't get invoked.


          Could you please let us know where the discrepancies are? Anyway this is correct :

          To my mind, the method interception was the only that wouldn't cause bytecode transformation on the caller classes, due to the called class could have the original method renamed and replaced by a new one, that would fire the interceptions, so methods executed via Reflection would be intercepted if set up so.


          Regarding interceptions of field reads in MBeans, I have not yet tried. I will try to take a look over the next week or so.



          • 2. Re: Methods via Reflection and MBean interception
            dimitris

            Now, I'm intruding here from another forum :)

            You can apply interceptors to MBeans (either statically or dynamically) by wrapping the MBean with an XMBean descriptor.

            Those interceptors come from the JBossMX framework (nothing to do with the AOP framework), so they are old style ones (no bytecode magic whatsoever), and they let you intercept JMX operations and attribute get/sets.

            • 3. Re: Methods via Reflection and MBean interception
              kabirkhan

              Hi there,

              You can also instrument MBeans via AOP.

              The assumption that fields of an MBean are accessed via reflection is false. For standard and XMBeans the MBean attributes are accessed by the MBean server via a set/get method (), and the set/getMethod() is what accesses the field, so instrumentation takes place normally (i.e. no reflection) on the MBean class itself. This should also be the case for dynamic MBeans unless you use reflection in your set/getAttribute() methods. I have updated the injboss example in cvs to include AOP interceptin of a standard MBean.

              Kabir