|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.lightwolf.Continuation
public class Continuation
An object that stores a flow's execution context for
further resuming. Usage requires invocation of checkpoint()
and
resume()
on an instance of this class. It is allowed to subclass
this class as a way to associate additional data or functionality to a
continuation.
Constructor Summary | |
---|---|
Continuation()
Creates a new continuation. |
Method Summary | |
---|---|
Future<?> |
activate()
|
Future<?> |
activate(Object result)
|
boolean |
checkpoint()
Places a checkpoint on the current flow, which can be used resume execution from the point of invocation. |
Continuation |
clone()
Returns an identical, independent copy of this continuation. |
void |
placeOnCheckpoint(Flow flow)
|
void |
placeOnCheckpointAndForget(Flow flow)
|
Object |
resume()
Creates a new flow and resumes it from the last checkpoint. |
Object |
resume(Flow flow)
Resumes the informed flow from the last checkpoint. |
Object |
resumeAndForget()
Creates a new flow and resumes it from the last checkpoint, throwing away the checkpoint. |
Object |
resumeAndForget(Flow flow)
Resumes the informed flow from the last checkpoint, throwing away the checkpoint. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Continuation()
checkpoint()
for that.
checkpoint()
Method Detail |
---|
public Continuation clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public final boolean checkpoint()
After invocation, it's possible to call resume()
on this
continuation, so a flow can resume from the checkpoint. When a checkpoint
is created, this method returns true
. Upon resuming, this
method returns false
. The following example illustrates this
behavior:
void example() { System.out.println("Before doFlow()"); Continuation continuation = doFlow(); System.out.println("After doFlow()"); continuation.The above example prints the following:resume()
; System.out.println("After continuation.resume()"); } @FlowMethod
FlowContext doFlow() { System.out.println("Before doCheckpoint()"); Continuation continuation = doCheckpoint(); System.out.println("After doCheckpoint()"); return continuation; } @FlowMethod
Continuation doCheckpoint() { Continuation continuation = new Continuation(); System.out.println("Before continuation.checkpoint()"); if (continuation.checkpoint()) { System.out.println("Checkpoint is set."); } else { System.out.println("We are resuming."); } return continuation; }
Before doFlow() Before doCheckpoint() Before continuation.checkpoint() Checkpoint is set. After doCheckpoint() After doFlow() We are resuming. After doCheckpoint() After continuation.resume()This method may return multiple times, at the discretion of whoever is using the continuation. Each time it might return in a different flow. But it's guaranteed that whenever this method returns
true
, it will return in the same flow as the
invoker.
A continuation can hold at most one checkpoint, so this method throws away any previous checkpoint that this continuation was holding.
true
if a checkpoint was created, false
if this method is resuming from a previously created checkpoint.
IllegalStateException
- If the invoker is not a FlowMethod
.public Object resume()
checkpoint()
on this
continuation. Such invocation returns false
, indicating that
execution is being resumed.
The new flow will execute synchronously. This method returns only then
the flow-creator returns, as if by
invocation of Flow.resume()
. If the resumed flow sends a
signal, this method throws the
corresponding FlowSignal
. In other words, the invoker will be the
flow-controller.
This method behaves exactly as:
Flow flow = Flow.Before resuming, this method performs a copy of the current checkpoint, so a futurenewFlow()
; continuation.resume(flow)
;
resume
operation will
succeed. If there is no intention to resume again, one should call
resumeAndForget()
.
IllegalStateException
- If there is no stored checkpoint on this
continuation.resume(Flow)
,
resumeAndForget()
,
resumeAndForget(Flow)
public Object resume(Flow flow)
resume()
. The difference is that no new flow is
created. Instead, the informed flow is resumed.
IllegalStateException
- If there is no stored checkpoint on this
continuation, or if the informed flow is on an invalid state for
resuming.
NullPointerException
- If the informed flow is null
.resume()
,
resumeAndForget(Flow)
public Object resumeAndForget()
resume()
. The
difference is that after invocation, this continuation will have no
checkpoint()
, which means that further invocations of
resume
methods will throw an exception.
This method is cheaper than resume()
, because it does not
involves a copy of the current checkpoint.
IllegalStateException
- If there is no stored checkpoint on this
continuation.resume()
,
resumeAndForget(Flow)
public Object resumeAndForget(Flow flow)
resume(Flow)
. The
difference is that after invocation, this continuation will have no
checkpoint()
, which means that further invocations of
resume
methods will throw an exception.
This method is cheaper than resume(Flow)
, because it does not
involves a copy of the current checkpoint.
IllegalStateException
- If there is no stored checkpoint on this
continuation, or if the informed flow is on an invalid state for
resuming.
NullPointerException
- If the informed flow is null
.resume()
,
resumeAndForget()
public Future<?> activate()
public Future<?> activate(Object result)
public void placeOnCheckpoint(Flow flow)
public void placeOnCheckpointAndForget(Flow flow)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |