Advices Invocation in JBoss AOP
This topic has not yet been written. The content below is from the topic description.
When intercepting a joinpoint, one can write after and after-throwing advices to perform an interception after the joinpoint execution. However, the execution of these advices is not assured. If the joinpoint executes normally, an after advice will be invoked, but the after-throwing one will not. On the other hand, when the joinpoint throws an exception, all after advices are skipped while advices of after-throwing type will be invoked. Finally advices are a mixture of after and after-throwing advices. As in the case of both advices, finally advices are also invoked after the joinpoint execution. But finally advices are invoked after joinpoint execution independently of its outcome. Since finally advices are invoked from inside a finally block, they will always be executed. To understand better this mechanism, refer to the following: 0 try 1 { 2 call before advices 3 call around advices -> joinpoint 4 call after advices 6 } 7 catch(Throwable t) 8 { 9 call after-throwing advices 10 throw t; 11 } 12 finally 13 { 14 call finally advices 15 } This is a simplified view of how JBoss AOP invokes the several types of advices. Before advices are executed before everything else. Next, around advices are called. Since around advices are responsible for triggering the joinpoint execution, this execution is wrapped in line 3. After advices are called next. After-throwing advices follow inside a catch block and, finally advices, inside a finally block. As we can see, the advices that are called after a joinpoint execution depend on how the joinpoint returns. If the joinpoint throws an exception, after advices will be skipped and the control flow will be directed to the catch block, where after-throwing advices are invoked. And, after that, we follow to the finally block, where finally advices are executed. Lastly, the Throwable t is rethrown. But if, on the other hand, the joinpoint execution returns normally, the control flow will follow from around to after advices. Next, the catch block is skipped and the finally block executed.