public interface SCXMLSemantics
The purpose of this interface is to separate the the
W3C SCXML Algorithm for SCXML Interpretation
from the SCXMLExecutor
and therefore make it pluggable.
From an SCXML execution POV, there are only three entry points needed into the Algorithm, namely:
firstStep(SCXMLExecutionContext)
. The state machine thereafter should be ready
for processing external events (or be terminated already)nextStep(SCXMLExecutionContext, TriggerEvent)
.
SCXMLExecutionContext.isRunning()
== false), after either
of the above steps, finalize the state machine by performing the final step.
See: finalStep(SCXMLExecutionContext)
.
After a state machine has been terminated you can re-initialize the execution context, and start again.
Except for the loading of the SCXML document and (re)initializing the SCXMLExecutionContext
, the above steps
represent the interpret,mainEventLoop and exitInterpreter entry points specified in Algorithm
for SCXML Interpretation, but more practically and logically broken into separate steps so that the blocking wait
for external events can be handled externally.
These three entry points are the only interface methods used by the SCXMLExecutor. It is up to the specific SCXMLSemantics implementation to provide the concrete handling for these according to the Algorithm in the SCXML specification (or possibly something else/different).
The default SCXMLSemanticsImpl
provides an implementation of the
specification, and can easily be overridden/customized as a whole or only on specific parts of the Algorithm
implementation.
Note that both the firstStep(SCXMLExecutionContext)
and nextStep(SCXMLExecutionContext, TriggerEvent)
first run to completion for any internal events raised before returning, as expected and required by the SCXML
specification, so it is currently not possible to 'manage' internal event processing externally.
Specific semantics can be created by subclassing
org.apache.commons.scxml2.semantics.SCXMLSemanticsImpl
.
Modifier and Type | Method and Description |
---|---|
void |
finalStep(SCXMLExecutionContext exctx)
The final step in the execution of an SCXML state machine.
|
void |
firstStep(SCXMLExecutionContext exctx)
First step in the execution of an SCXML state machine.
|
boolean |
isLegalConfiguration(Set<EnterableState> states,
ErrorReporter errRep)
Checks whether a given set of states is a legal Harel State Table
configuration (with the respect to the definition of the OR and AND
states).
|
void |
nextStep(SCXMLExecutionContext exctx,
TriggerEvent event)
Next step in the execution of an SCXML state machine.
|
SCXML |
normalizeStateMachine(SCXML input,
ErrorReporter errRep)
Optional post processing immediately following SCXMLReader.
|
SCXML normalizeStateMachine(SCXML input, ErrorReporter errRep)
input
- SCXML state machineerrRep
- ErrorReporter callbackvoid firstStep(SCXMLExecutionContext exctx) throws ModelException
In the default implementation, this will first (re)initialize the state machine instance, destroying any existing state!
The first step is corresponding to the Algorithm for SCXML processing from the interpret() procedure to the mainLoop() procedure up to the blocking wait for an external event.
This step should complete the SCXML initial execution and a subsequent macroStep to stabilize the state machine again before returning.
If the state machine no longer is running after all this, first the finalStep(SCXMLExecutionContext)
should be called for cleanup before returning.
exctx
- The execution context for this stepModelException
- if the state machine instance failed to initialize or a SCXML model error occurred during
the execution.void nextStep(SCXMLExecutionContext exctx, TriggerEvent event) throws ModelException
The next step is corresponding to the Algorithm for SCXML processing mainEventLoop() procedure after receiving an external event, up to the blocking wait for another external event.
If the state machine isn't SCXMLExecutionContext.isRunning()
(any more), this method should do nothing.
If the provided event is a TriggerEvent.CANCEL_EVENT
, the state machine should stop running.
Otherwise, the event must be set in the SCXMLSystemContext
and processing of the event then should start,
and if the event leads to any transitions a microStep for this event should be performed, followed up by a
macroStep to stabilize the state machine again before returning.
If the state machine no longer is running after all this, first the finalStep(SCXMLExecutionContext)
should be called for cleanup before returning.
exctx
- The execution context for this stepevent
- The event to processModelException
- if a SCXML model error occurred during the execution.void finalStep(SCXMLExecutionContext exctx) throws ModelException
This final step is corresponding to the Algorithm for SCXML processing exitInterpreter() procedure, after the state machine stopped running.
If the state machine still is SCXMLExecutionContext.isRunning()
invoking this method should simply
do nothing.
This final step should first exit all remaining active states and cancel any active invokers, before handling the possible donedata element for the last final state.
NOTE: the current implementation does not yet provide final donedata handling.
exctx
- The execution context for this stepModelException
- if a SCXML model error occurred during the execution.boolean isLegalConfiguration(Set<EnterableState> states, ErrorReporter errRep)
When SCXMLExecutionContext.isCheckLegalConfiguration()
is true (default) the SCXMLSemantics implementation
should invoke this method before executing a step, and throw a ModelException if a non-legal
configuration is encountered.
This method is also first invoked when manually initializing the status of a state machine through
SCXMLExecutor#setConfiguration(java.util.Set
.
states
- a set of stateserrRep
- ErrorReporter to report detailed error info if neededCopyright © 2005–2015 The Apache Software Foundation. All rights reserved.