Go with the flow
I have never been totally convinced of using javascript as the flow language. So I took a closer look into BCEL and Brakes. After I updated Brakes to the current BCEL implementation it seems that everything we need to let java continuations become reality is already in place. The following example is already working:
public final class Runner {
public static void main(String[] args) throws Exception {
Classloader loader = new Classloader();
Class clazz = loader.loadClass("org.apache.bcel.brakes.test.SimpleFlow");
Flow flow = (Flow) clazz.newInstance();
Continuation c = null;
do {
System.out.println("*** starting flow");
c = flow.continueWith(c);
System.out.println("*** returning from flow");
}
while(c != null);
}
}
public final class SimpleFlow extends AbstractFlow {
public void run() {
int i = 3;
String s = new String(""+i);
System.out.println("STEP1");
suspend();
for (int b=0;b<3;b++) {
System.out.println("" + b + " of " + s);
System.out.println("STEP2");
suspend();
}
System.out.println("STEP3");
suspend();
System.out.println("STEP4");
suspend();
System.out.println("end of flow");
}
}