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

5 Responses to “Serialize your flow”

  1. krishna said, on 3. April 2005 at 8:27

    Is there an example which demonstrates ‘browser back button’ using javaflow continuations ?

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

    thanks

  2. Torsten Curdt said, on 3. April 2005 at 16:10

    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.

  3. krishna said, on 13. April 2005 at 22:12

    > 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

  4. Eric said, on 20. April 2005 at 14:51

    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?

  5. Torsten Curdt said, on 26. July 2005 at 11:21

    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.

Leave a Reply

Please copy the string 7lC95C to the field below: