Dynamic Control Flow

Overview

Control flow is a runtime construct. A dynamic cflow will be called before the execution of the advices/interceptors it wraps. If it returns true then the advices execution. It allows you to do runtime dynamic checks at runtime to determine whether or not you want to run an advice stack.

Step One

To implement a Dynamic CFlow you first need to implement org.jboss.aop.pointcut.DynamicCFlow

public interface DynamicCFlow
{
   boolean shouldExecute(Invocation invocation);
}

Put in the logic you want to run at runtime into the shouldExecution method.

Step Two

Step two is to declare the Dynamic CFlow in the AOP XML file. See jboss-aop.xml:

   <dynamic-cflow name="simple" class="SimpleDynamicCFlow"/>

Then you can use the dynamic cflow in any cflow expression. The cflow will be allocate once and only once for the entire VM.

Configure with XML

If you want to do some XML configuration of the dynamic cflow instance, you can have it implement org.jboss.util.xml.XmlLoadable.

public interface XmlLoadable
{
   public void importXml(Element element);
}

Run the example

To compile and run:
  $ ant
It will javac the files and then run the AOPC precompiler to manipulate the bytecode, then finally run the example. The output should read as follows:
run:
     [java] --- pojo.method4(); ---
     [java] method1
     [java] --- turn on cflow ---
     [java] <<< Entering SimpleInterceptor for: public void POJO.method1()
     [java] method1
     [java] >>> Leaving SimpleInterceptor