1 2 Previous Next 17 Replies Latest reply on Jun 29, 2004 4:56 PM by bill.burke Go to original post
      • 15. Re: JBoss AOP vs. AspectJ
        bill.burke

        If a particular joinpoint is "prepared" you do not have to recompile or even shutdown the JVM to add or remove an advice from a particular joinpoint. You can also add/remove interceptors on a per instance basis at runtime with a prepared joinpoint.

        How to prepare?



        This will instrument the class.

        Also, any other pointcut def will cause the class to be instrumented. Instrumented classes without advices have VERY low overhead. It is one extra method call and a boolean check. You won't even notice it.


        With JDK 5.0 you do not need a custom classloader. I've written an agent to work with the java.lang.instrument package and it works pretty well. I haven't integrated it with JBoss yet though as I have to change the run script and write some tests.

        Kevin Conner also wrote something for JDK 1.4 that modifies java.lang.Class to insert the necessary hooks for JBoss AOP.

        • 16. Does this mean AspectJ support STATEFUL aspect?
          cookman

          In the book "AspectJ in Action" published by Manning, there is an example named IndentedLogging:

          package logging;
          
          public abstract aspect IndentedLogging {
           protected int _indentationLevel = 0;
          
           protected abstract pointcut loggedOperations();
          
           before() : loggedOperations() {
           _indentationLevel++;
           }
          
           after() : loggedOperations() {
           _indentationLevel--;
           }
          
           before() : call(* java.io.PrintStream.println(..))
           && within(IndentedLogging+) {
           for (int i = 0, spaces = _indentationLevel * 4;
           i < spaces; ++i) {
           System.out.print(" ");
           }
           }
          }
          

          and
          package banking;
          
          import org.aspectj.lang.*;
          import logging.*;
          
          public aspect AuthLogging extends IndentedLogging {
           declare precedence: AuthLogging, *;
          
           public pointcut accountActivities()
           : execution(public * Account.*(..))
           || execution(public * InterAccountTransferSystem.*(..));
          
           public pointcut loggedOperations()
           : accountActivities();
          
           before() : loggedOperations() {
           Signature sig = thisJoinPointStaticPart.getSignature();
           System.out.println("<" + sig.getName() + ">");
           }
          }
          

          so, it can output in such format
          <credit>
          <debit>
          <transfer>
           <credit>
           <debit>
          <transfer>
           <credit>
           <debit>
          

          but when i try to implement it in JBoss AOP, it seems cannot remember the state of _indentationLevel.
          Does JBoss AOP support such stateful aspect?

          • 17. Re: JBoss AOP vs. AspectJ
            bill.burke

            well, you're gonna have to post the JBoss AOP example...

            JBoss AOP Aspects can hold state. An instance of the Aspect is created depending on the scope. PER_VM, PER_CLASS, PER_INSTANCE< PER_ JOINPOINT.

            Bill

            1 2 Previous Next