header

Torsten Curdt’s weblog

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;
        }
    };

  • You are missing something ;) ...usually this means the class did not get instrumented. Feel free to contact me via email if you have further problems.
  • Eric
    I've tried to get the flow working within cocoon, I see that execution continues after the Continuation.suspend is called. This breaks AbstractContinuable and FlowInstance, should the thread connected to the continuable stop execution or am I missing something?
  • > Just recently I've did quite a big change to the javaflow API



    this link is broken,



    http://svn.apache.org/repos/asf/cocoon/trunk/src/blocks/javaflow/java/org/apache/cocoon/components/flow/java/JavaInterpreter.java



    where is the change updated
  • There is a link my blog entry to the Cocoon classes if you are after the technical details. Having no "browser back button" problem is a natural thing with continuations. Maybe just a have a look into the Cocoon examples.
  • Is there an example which demonstrates 'browser back button' using javaflow continuations ?



    Otherwise, may i know how to accomplish the same using javaflow?



    thanks
blog comments powered by Disqus