If I understand this correctly, for me to capture the continuation and
run it later, I do:

Have a look into the serialization testcase

    // serialize the continuation
    ObjectOutputStream oos = ...;
    oos.writeObject(c);
    oos.writeObject(myRunnable);

Since the resume will only work with the
exact same class there is no point in
making the runnable serializable and
saving it.


    c.continueWith(new DefaultContinuationContext(myRunnable));

is that correct?


Correct - except for the serialization of the
runnable.

(I'm assuming that you designed ContinuationContext to
keep track of things you want to change between runs, so it's not reachable from Continuation if it's not executing.)

Sorry, did not get that ..what do you mean?

The ContinuationContext holds all the references
that are required to restore the state but cannot
really be part of the continuation. Logger,
ComponentManager and things like that.

See the example in my blog ...which is actually
taken from the Cocoon integration. (I think in
there is also the link to the class) Would be
great if you could also have a look into that
class.

I thought it would be nice if I can write it instead as:

    Runnable myRunnable = new MyRunnable(...);
    Continuation  c = Continuation.startWith(myRunnable,null);

Did understand that ...but that restricts the
API a bit too much. With the propose way we
can have the best of both worlds - I think.

Or maybe what I really wanted was to the "ContinuableThread" class or something that wraps the existing API into a class that feels like java.lang.Thread, so that I can do:

    ContinuableThread t = new ContinuableThread() {
      // override run or pass in Runnable to the constructor
      void run() { ...; suspend(); ...; }
    }

    t.start();    // start running. return when suspended

    oos.writeObject(t);    // serialize
    t = ois.readObject();    // deserialize
    t = t.clone();        // AKA thread fork

Don't understand the cloning.

    while(t.isAlive())
        t.continue();

Hmmm... looks interesting but you would
need to poll the continuations. So you
would have to start the "thread" with
every resume ..that's a bit awkward.

cheers
--
Torsten

Attachment: PGP.sig
Description: This is a digitally signed message part

Reply via email to