Helma Logo
main list history

Continuations

Rhino Continuations

Rhino continuations allow to capture the state of a complete running script to be resumed later on.

http://wiki.apache.org/cocoon/RhinoWithContinuations

Rhino continuations only work in interpreter mode with the compiler disabled, so make sure that you have the following in your app.properties:

  rhino.optlevel = -1

While adding continuation and callback support to existing Helma releases has been a bit of a hack, recent Helma snapshots have added features to make that easier, namely the introduction of req.uri and req.actionHandler.

The following script is a first prototype for adding Continuation support to the Helma 1.7 web framework.

nametypesize
Continuation.jsundefined bytes

This adds the following static methods to the Continuation constructor:

And although continuations work best with POST forms and ordinary links, if you must use GET forms, there also is:

Here's an example action that makes use of this framework:

  function test_continuation_action() {
    res.write(<form method="post" action={Continuation.nextUrl()}>
                <input name="foo"/>
                <input type="submit"/>
              </form>);
    Continuation.nextPage();
    var foo = req.data.foo;
    res.write('<a href="' + Continuation.nextUrl() + '">click here</a>');
    Continuation.nextPage();
    res.write("you said: " + foo);
  }

This action displays three pages: the first renders a form, the second a link, and the third will show a message containing the string entered in the first page. Remember that for continuation support to work, you must call Continuation.resume() in onRequest():

  function onRequest() {
    Continuation.resume();
  }

When running the example, you will notice that the continuations have the same URI path as the original action, just with a continuation_id query parameter added:

  /test.continuation?continuation_id=at5fgn5zz18g

This has the great benefit that trying to run a non-existing continuation (either because the link has been passed outside the originating session, or because the session has expired, or because the client does not support cookies) will actually result in the right action being invoked - it will simply result in the action to be started from the beginning. So in order to detect all these cases, it is sufficient to test for a continuation_id parameter at the very beginning of the action:

  function continuation_action() {
    if (req.data.continuation_id) {
      // Request has a continuation_id, but we landed at the beginning
      // beginning of the action. Either the session timed out, 
      // or the link comes from another session. 
      res.debug("Continuation invalid or expired. Starting over.");
    }
    // Continue rendering first page
    Continuation.nextPage();
    // From here on, req.data.continuation_id is expected to be set
  }

As of 2008/02/08, serialization issues in combination with Continuations and Javascript functions in general have been fixed in Subversion, so it's no longer a problem to use continuations in combination with persistent sessions.

Jetty Continuations

Jetty continuations are a mechanism to keep HTTP connections pending without having a Java thread associated with the request.

http://docs.codehaus.org/display/JETTY/Continuations

This is not a "real" continuation as this isn't supported by Java. Instead, it relies on "that all actions taken by a filter or servlet before a call to suspend(long) are either idempotent (can be retried) or are made conditional on isPending() so they are not performed on retried requests".

http://jetty.mortbay.com/apidocs/org/mortbay/util/ajax/Continuation.html

Jetty continuations are a means to allow AJAX polling without a thread penalty.

Links to this page: Continuations for the masses, Helma 1.6.2 Changelog