Package kilim
Class Continuation
- java.lang.Object
-
- kilim.Continuation
-
- All Implemented Interfaces:
Fiber.Worker
- Direct Known Subclasses:
Generator,Pure.PureDemo,Pure.PureMega,Xorshift.X2
public abstract class Continuation extends java.lang.Object implements Fiber.Worker
a minimal bridge or trampoline between woven and unwoven code backed by a Fiber giving the programmer explicit control over the event loop see Task for a more general and easier to use green thread implementation that automatically handles the event loop see Generator for more user friendly wrapper to use override execute() and call run() each time run() is called, execute runs until it yields, returns or throws an exception return value of true means either execute returned or threw an exception (accessible as ex()) with state stored in an internal Fiber field across invocations to reuse a Continuation, call reset() Continuation provides no scheduler - it is entirely the responsibility of the calling code to call run() again once the pausing condition has been satisfied typically used for state machines and Generators or to port an existing event loop to kilim this is a low level facility, see kilim.examples.Xorshift.X2 for an example of direct use
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContinuation.FakeTask
-
Field Summary
Fields Modifier and Type Field Description private booleanactiveprivate java.lang.Exceptionex(package private) static Continuation.FakeTaskfakeTaskprivate Fiberfiberprivate static Fiber.MethodRefrunnerInfo
-
Constructor Summary
Constructors Constructor Description Continuation()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Exceptionex()get the stored exceptionvoidexecute()the top level entrypoint for the continuation override this method cannot be called directly - use run() instead use Fiber.yield() to yield control cooperatively and return execution to the caller of run()voidexecute(Fiber fiber)the woven variant of execute() generated by the weaver overriding this method will cause the weaver to leave it unchanged this is a low level facility (override execute() instead)voidreset()reset the Continuation and corresponding Fiber cannot be called inside execute() subsequent invocations of run() will enter execute() as a normal method, ie at the beginningbooleanrun()perform one iteration of execute() the first invocation begins as a normal method subsequent invocations continue from the most recent yield
-
-
-
Field Detail
-
runnerInfo
private static Fiber.MethodRef runnerInfo
-
fakeTask
static final Continuation.FakeTask fakeTask
-
ex
private java.lang.Exception ex
-
fiber
private Fiber fiber
-
active
private boolean active
-
-
Method Detail
-
ex
public java.lang.Exception ex()
get the stored exception- Returns:
- the stored Exception if execute() has thrown one, otherwise null
-
run
public boolean run() throws NotPausableperform one iteration of execute() the first invocation begins as a normal method subsequent invocations continue from the most recent yield- Returns:
- true if execute returned or threw an Exception (call ex() to retrieve)
- Throws:
NotPausable
-
execute
public void execute() throws Pausable, java.lang.Exceptionthe top level entrypoint for the continuation override this method cannot be called directly - use run() instead use Fiber.yield() to yield control cooperatively and return execution to the caller of run()- Specified by:
executein interfaceFiber.Worker- Throws:
Pausablejava.lang.Exception
-
execute
public void execute(Fiber fiber)
the woven variant of execute() generated by the weaver overriding this method will cause the weaver to leave it unchanged this is a low level facility (override execute() instead)- Specified by:
executein interfaceFiber.Worker- Parameters:
fiber- the stack information automatically provided by run()
-
reset
public void reset()
reset the Continuation and corresponding Fiber cannot be called inside execute() subsequent invocations of run() will enter execute() as a normal method, ie at the beginning
-
-