Serialize your flow
Just recently I’ve did quite a big change to the javaflow API. It should now be much easier to use plus it also separates the execution context from the continuation itself.
A good example how to use it is the class that hooks javaflow into cocoon.
The context of course depends on your application. For cocoon it includes access to the ServiceManager and other cocoon specific classes or components.
The MethodLookup is being used for a lazy lookup of the method that is our entry point into the java based flow.
Why separating everything? …because that makes a continuation resumable in a different context. If you now make sure that all objects on the stack are going to be serializable you can write a continuation to disk and even resume it on a different machine by providing a new context.
final CocoonContinuationContext context =
createContinuationContext(params, redirector);
final Continuation firstContinuation =
Continuation.startWith(methodName, context);
...
final Continuation nextContinuation =
Continuation.continueWith(firstContinuation, context);
private CocoonContinuationContext createContinuationContext(final List params, final Redirector redirector) {
final CocoonContinuationContext context = new CocoonContinuationContext();
context.setAvalonContext(avalonContext);
context.setLogger(getLogger());
context.setServiceManager(manager);
context.setRedirector(redirector);
context.setMethodLookup(lookup);
...
context.setParameters(parameters);
return context;
}
final Map methods = ReflectionUtils.discoverMethods(MyFlow.class);
...
MethodLookup lookup = new MethodLookup() {
public Method getMethod(final String methodName) {
final Method method = (Method) methods.get(methodName);
return method;
}
};