2 Replies Latest reply on Jan 4, 2005 12:19 PM by Kabir Khan

    How to get the PER_VM instance?

    James Huang Newbie

      Hello,

      I wonder if there are any API methods to get the aspect instances like the ?aspectOf()? method of AspectJ?

      In particular, I?d like to get the PER_VM instance of a specific aspect class (which implements the Interceptor interface.)

      Thanks.

        • 1. Re: How to get the PER_VM instance?
          James Huang Newbie

           

          "Hjames" wrote:
          Hello,

          I wonder if there are any API methods to get the aspect instances like the "aspectOf()" method of AspectJ?

          In particular, I'd like to get the PER_VM instance of a specific aspect class (which implements the Interceptor interface.)

          Thanks.


          • 2. Re: How to get the PER_VM instance?
            Kabir Khan Master

            Yep,

            To get the PER_VM instance, you would do:

            MyAspect myAspect = (MyAspect) AspectManager.instance().getPerVMAspect("org.blah.MyAspect");
            


            Note that all instrumented classes implement the org.jboss.aop.Advised interface. So for other scopes you would cast an instance to Advised.

            Advised has the following two methods:
            InstanceAdvisor _getInstanceAdvisor();
             Advisor _getAdvisor();
            

            Advisor allows you to get PER_CLASS scoped aspect instances via the getPerClassAspect() method. (It takes the aspect class name as its parameter)

            InstanceAdvisor allows you to get PER_INSTANCE scoped aspect instances via the getPerInstanceAspect() method. (It takes the aspect class name as its parameter)

            Kabir