4 Replies Latest reply on Jan 22, 2007 3:08 PM by bossy

    AOP integration with JMX question

    bossy

      Hi,
      I posted this in the JMX forum first, but since nobody replyed I thougt I could try here as this is about AOP as well.

      I need to create an aspect that can be managed by JMX. The idea is to use the aspect to obtain some stats(by intercepting calls) and to use JMX console to retrieve the stats.
      I created an XMBean and I added methods wich I use as advices.
      Everything works fine( the calls are intercepted and the XMBean is registered and accessible from the JMX console) with one exception - it seems that AOP and JMX create their own instances of the class. Aop intercepts the calls I make and updates the stats, but the XMBean values of the same stats(attributes) remain the same ( null in my case).
      I tried to use separate XMBean and aspect classes, but the problem is that in order to use the XMBean methods to update my stats, I have to expose them and once I do this - they are available to the users in the JMX console.
      My question is - is it possible to do write an Ascpect XMBean and if so - where should I look for more details.
      Thanks in advance.

        • 1. Re: AOP integration with JMX question
          kabirkhan

           

          "bossy" wrote:

          My question is - is it possible to do write an Ascpect XMBean and if so - where should I look for more details.


          Not really, but it should be possible to have your plain aspect delegate onto an MBean that can be used to store/display the stats?

          • 2. Re: AOP integration with JMX question
            bossy

            Thanks,
            but could you be more specific about what you mean when you say:

            "... plain aspect delegate onto an MBean ..."


            I tried the following:
            In my aspect I make this call:
            server.invoke(statsMBean, "increaseCount", null,null);

            , which works fine, but the problem is that in order to be able to call the increaseCountmethod from my aspect I need to expose it in the -xmbean.xml, which in turn makes it available to the user in the JMX console, i.e the user can increase the count from the JMX console.


            • 3. Re: AOP integration with JMX question
              kabirkhan

              Hmm,

              What you mention is a problem with JMX, there is no "proper" way to work around this.

              One way to enforce that the values can only be set by your aspect would be to have your aspect set/clear a value in a ThreadLocal surrounding the call to invocation.invokeNext() and in the increaseCount() method of your MBean check for the exsistance of that value in the ThreadLocal. If called by the JMX console, i.e. not from the aspecy that ThreadLocal value will not exist, so it is a noop.

              Alternatively, you could use the aspect instance as a parameter to the increaseCount method, which would make it impossible to invoke via the console.

              • 4. Re: AOP integration with JMX question
                bossy

                I see.
                I'll think about these two approaches.
                Thanks.