org.lightwolf
Class FlowSignal
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.lightwolf.FlowSignal
- All Implemented Interfaces:
- Serializable
- Direct Known Subclasses:
- DelayedCallSignal, SuspendSignal
public abstract class FlowSignal
- extends RuntimeException
The root of all signal classes. A signal is sent to the flow-controller by the
Flow.signal(FlowSignal)
method. Because the signal is an exception,
it must be caught by the flow-controller in a catch
block. The
following snippet is an example of signal handling:
void startFlow() { // This is the flow-controller.
try {
runFlow(); // Runs the flow, which might send a signal.
System.out.println("The flow finished normally.");
} catch (FlowSignal signal) {
// A signal was sent.
signal.defaultAction(); // Calls the signal's default action.
System.out.println("The flow is waiting for something.");
}
}
@FlowMethod
void runFlow() { // This is the flow-creator.
...
}
A well-behaved signal handler should call the signal's
defaultAction()
method, like the above example. For more information
about sending and handling signals, please check the
Flow.signal(FlowSignal)
method.
- Author:
- Fernando Colombo
- See Also:
- Serialized Form
Method Summary |
abstract void |
defaultAction()
The signal's default action. |
Flow |
getFlow()
The flow that have sent this signal, or null if this signal
was just instantiated and not sent yet. |
Object |
getResult()
|
Methods inherited from class java.lang.Throwable |
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
FlowSignal
public FlowSignal()
getFlow
public final Flow getFlow()
- The flow that have sent this signal, or
null
if this signal
was just instantiated and not sent yet. While the signal is being
handled, it is guaranteed that the flow will be in suspended state.
getResult
public Object getResult()
defaultAction
public abstract void defaultAction()
- The signal's default action. The behavior of this method varies and is
defined by the actual signal class. Usually this method registers the
flow somewhere, so it can be resumed
when a certain event happens. A well-behaved flow-controller should always call
this method while handling a signal.
NOTE TO IMPLEMENTORS: Document well what the implementation of your
method does, specially on the method's JavaDoc. You can call
getFlow()
to obtain the flow that have sent the signal. Inside
this method, it is guaranteed that the flow will be in suspended state.