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.
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(" "); } } }
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() + ">"); } }
<credit> <debit> <transfer> <credit> <debit> <transfer> <credit> <debit>
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