org.apache.commons.javaflow
Class Continuation

java.lang.Object
  extended byorg.apache.commons.javaflow.Continuation
All Implemented Interfaces:
java.io.Serializable

public final class Continuation
extends java.lang.Object
implements java.io.Serializable

Snapshot of a thread execution state.

A Continuation object is an immutable object that captures everything in the Java stack. This includes (1) current instruction pointer, (2) return addresses, and (3) local variables.

Continuation objects are used to restore the captured execution states later.

Version:
CVS $Id: Continuation.java 232929 2005-08-16 03:53:33Z kohsuke $
See Also:
Serialized Form

Method Summary
static Continuation continueWith(Continuation resumed)
          Resumes the execution of the specified continuation from where it's left off.
static Continuation continueWith(Continuation resumed, java.lang.Object context)
          Resumes the execution of the specified continuation from where it's left off.
static java.lang.Object getContext()
          get the current context.
static Continuation startSuspendedWith(java.lang.Runnable target)
          Creates a new Continuation object from the specified Runnable object.
static Continuation startWith(java.lang.Runnable target)
          Starts executing the specified Runnable object in an environment that allows suspend().
static Continuation startWith(java.lang.Runnable target, java.lang.Object context)
          Starts executing the specified Runnable object in an environment that allows suspend().
static void suspend()
          Stops the running continuation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getContext

public static java.lang.Object getContext()
get the current context.

This method returns the same context object given to startWith(Runnable, Object) or continueWith(Continuation, Object).

A different context can be used for each run of a continuation, so this mechanism can be used to associate some state with each execution.

Returns:
null if this method is invoked outside startWith(Runnable, Object) or continueWith(Continuation, Object) .

startSuspendedWith

public static Continuation startSuspendedWith(java.lang.Runnable target)
Creates a new Continuation object from the specified Runnable object.

Unlike the startWith(Runnable) method, this method doesn't actually execute the Runnable object. It will be executed when it's continued.

Returns:
always return a non-null valid object.

startWith

public static Continuation startWith(java.lang.Runnable target)
Starts executing the specified Runnable object in an environment that allows suspend().

This is a short hand for startWith(target,null).

See Also:
startWith(Runnable, Object).

startWith

public static Continuation startWith(java.lang.Runnable target,
                                     java.lang.Object context)
Starts executing the specified Runnable object in an environment that allows suspend(). This method blocks until the continuation suspends or completes.

Parameters:
target - The object whose run method will be executed.
context - This value can be obtained from getContext() until this method returns. Can be null.
Returns:
If the execution completes and there's nothing more to continue, return null. Otherwise, the execution has been suspended, in which case a new non-null continuation is returned.
See Also:
getContext()

continueWith

public static Continuation continueWith(Continuation resumed)
Resumes the execution of the specified continuation from where it's left off.

This is a short hand for continueWith(resumed,null).

See Also:
continueWith(Continuation, Object)

continueWith

public static Continuation continueWith(Continuation resumed,
                                        java.lang.Object context)
Resumes the execution of the specified continuation from where it's left off. This method blocks until the continuation suspends or completes.

Parameters:
resumed - The resumed continuation to be executed. Must not be null.
context - This value can be obtained from getContext() until this method returns. Can be null.
Returns:
If the execution completes and there's nothing more to continue, return null. Otherwise, the execution has been suspended, in which case a new non-null continuation is returned.
See Also:
getContext()

suspend

public static void suspend()
Stops the running continuation.

This method can be only called inside continueWith(org.apache.commons.javaflow.Continuation) or startWith(java.lang.Runnable) methods. When called, the thread returns from the above methods with a new Continuation object that captures the thread state.

Throws:
java.lang.IllegalStateException - if this method is called outside the continueWith(org.apache.commons.javaflow.Continuation) or startWith(java.lang.Runnable) methods.

toString

public java.lang.String toString()


Copyright © 2004-2005 The Apache Software Foundation. All Rights Reserved.