S - The SM-specific signal enum.A - The SM-specific action enum.public class AcsScxmlEngine<S extends java.lang.Enum<S>,A extends java.lang.Enum<A>>
extends java.lang.Object
The code has been taken from ESO SM framework class SMEngine.``
| Constructor and Description |
|---|
AcsScxmlEngine(java.lang.String scxmlFileName,
java.util.logging.Logger logger,
AcsScxmlActionDispatcher<A> actionDispatcher,
java.lang.Class<S> signalType) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
fireSignal(S signal)
Sends a signal (event) to the state machine.
|
boolean |
fireSignalWithErrorFeedback(S signal)
Synchronous event handling as in
fireSignal(Enum),
but possibly with exceptions for the following cases:
The signal gets checked if it can be handled by the current state(s);
an AcsJIllegalStateEventEx exception is thrown if not. |
java.util.Set<S> |
getApplicableSignals()
Gets the signals that would trigger transitions for the current state.
|
java.lang.String |
getCurrentState()
Retrieves the current state as a string.
|
SCXMLExecutor |
getEngine()
Exposes the underlying SCXMLExecutor engine,
for more specialized calls that we don't put in API methods for.
|
boolean |
isStateActive(java.lang.String stateName)
Checks if a given state is active.
|
void |
loadModel(java.lang.String scxmlFileName)
Loads the SCXML model from an XML file stored inside of a jar file on the classpath.
|
void |
startExecution()
Starts SCXML execution.
|
public AcsScxmlEngine(java.lang.String scxmlFileName,
java.util.logging.Logger logger,
AcsScxmlActionDispatcher<A> actionDispatcher,
java.lang.Class<S> signalType)
scxmlFileName - The qualified xml file name, e.g. "/alma/acs/nc/sm/EventSubscriberStates.xml",
in the form that Class.getResource(String) can use to load the scxml
definition file from the classpath.logger - actionDispatcher - signalType - enum class, needed to convert signal names to enum values.java.lang.IllegalArgumentException - if any of the args are null or if the actionDispatcher
is not complete for all possible actions.public void loadModel(java.lang.String scxmlFileName)
TODO: define and throw exception in case of load/parse failure.
scxmlFileName - The qualified xml file name, e.g. "/alma/acs/nc/sm/generated/EventSubscriberSCXML.xml"public void startExecution()
TODO: define and throw exception in case of model failure.
public java.lang.String getCurrentState()
public boolean isStateActive(java.lang.String stateName)
TODO: Protect against mismatches that can occur if one state name includes another state name as a substring, e.g. by splitting names at "::" and comparing those fragements.
stateName - The state name (fragment).
Hierarchical states are separated by "::", with outer state first, e.g. "EnvironmentCreated::Connected".true if the given state is active.public SCXMLExecutor getEngine()
public boolean fireSignal(S signal)
TODO: How can the client find out whether the signal was applicable for the current state or was ignored?
public boolean fireSignalWithErrorFeedback(S signal) throws AcsJIllegalStateEventEx, AcsJStateMachineActionEx, ModelException
fireSignal(Enum),
but possibly with exceptions for the following cases:
signal gets checked if it can be handled by the current state(s);
an AcsJIllegalStateEventEx exception is thrown if not.
ModelException, as thrown by SCXMLExecutor#triggerEvent, unlikely
with our static use of the SCXML engine.
signal - AcsJIllegalStateEventExAcsJStateMachineActionExModelExceptionpublic java.util.Set<S> getApplicableSignals()
When actually sending such signals later on, the SM may have moved to a different state.
To prevent this, you can synchronize on this AcsScxmlEngine, which will block concurrent calls to fireSignal(Enum).
This method can be useful for displaying applicable signals in a GUI,
or to reject signals (with exception etc) that do not "fit" the current state
(while normally such signals would be silently ignored).
The latter gets used in fireSignalWithErrorFeedback(Enum).
org.apache.commons.scxml.semantics.SCXMLSemanticsImpl#enumerateReachableTransitions(SCXML, Step, ErrorReporter)