Arriving in Gent
Today I went down from St. Peter Ording meeting up with Marcus and Michael in Köln traveling to Gent together. After finding our way to the nice Bed&Breakfast where we met up with Stefano we went out for the first Belgium beers :)
Some days off
Finally some days off. Now I am just about to leave to St. Peter Ording. I used to go there with my family when I was a child. Now going
for a little revival :)
I’ll be heading to Belgium from there on Sunday. A nice week coming up :)
Still in the flow
A first (and slightly modified) version of the famous Calculator example is working with Java continuations :) It currently looks like this:
But there is no integration with Cocoon yet. You have to run it like this:
A lot of things are still missing …or are just dead ugly. But I’d like to hear
some comments from my fellow Cocooner’s first before going down that
road. Looking forward doing this face-to-face on the GetTogether :))
final public class CalculatorFlow extends AbstractCocoonFlow {
public void run() {
CocoonEnvironment env;
float a, b;
String op;
String uri = "page/";
HashMap parameters = new HashMap();
env = sendPageAndWait(uri + "getNumberA", parameters);
a = Float.parseFloat(env.getRequest().getParameter("a"));
parameters.put("a", new Float(a));
env = sendPageAndWait(uri + "getNumberB", parameters);
b = Float.parseFloat(env.getRequest().getParameter("b"));
parameters.put("b", new Float(b));
env = sendPageAndWait(uri + "getOperator", parameters);
op = env.getRequest().getParameter("operator");
if ("plus".equals(op)) {
parameters.put("result", new Float(a + b));
sendPageAndWait(uri + "displayResult", parameters);
} else if ("minus".equals(op)) {
parameters.put("result", new Float(a - b));
sendPageAndWait(uri + "displayResult", parameters);
} else if ("multiply".equals(op)) {
parameters.put("result", new Float(a * b));
sendPageAndWait(uri + "displayResult", parameters);
} else if ("divide".equals(op)) {
if (b == 0) {
//sendPage("Error: Division by zero!");
} else {
parameters.put("result", new Float(a / b));
sendPageAndWait(uri + "displayResult", parameters);
}
} else {
//sendPage("Error: Unkown operator!");
}
}
public static void calculator() throws Exception {
Classloader loader = new Classloader();
Class clazz = loader.loadClass("org.apache.cocoon.jflow.test.CalculatorFlow");
Flow flow = (Flow) clazz.newInstance();
Continuation c = null;
System.out.println("*** starting flow");
c = flow.continueWith(flow.createContinuation(c),
new CocoonEnvironment(null));
System.out.println("*** returning from flow");
System.out.println("*** starting flow");
c = flow.continueWith(flow.createContinuation(c),
new CocoonEnvironment(AbstractCocoonFlow.createRequest( new String[][] { {"a","1"}} )));
System.out.println("*** returning from flow");
System.out.println("*** starting flow");
c = flow.continueWith(flow.createContinuation(c),
new CocoonEnvironment(AbstractCocoonFlow.createRequest( new String[][] { {"b","1"}} )));
System.out.println("*** returning from flow");
System.out.println("*** starting flow");
c = flow.continueWith(flow.createContinuation(c),
new CocoonEnvironment(AbstractCocoonFlow.createRequest( new String[][] { {"operator","plus"}} )));
System.out.println("*** returning from flow");
if (c == null) {
System.out.println("*** end of flow");
}
}
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");
}
}