new module:ct-trading /statemachine /State Machine Factory()
Constructs a StateMachineFactory.
The StateMachineFactory is responsible providing module:ct-trading/statemachine/StateMachine
s,
which are constructed from an XML configuration file (provided with module:ct-trading/statemachine/StateMachineFactory#loadModels
. A StateMachine
instance is required to construct a
module:ct-trading/trademodel/Trade
instance.
The XML configuration file defines the States and Transitions within the trade model. Below is an example XML configuration file for the ESP trading protocol.
<?xml version="1.0" encoding="UTF-8" ?> <tradeModels> <tradeModel name="ESP" initialState="Initial"> <state name="Initial"> <transition target="OpenSent" trigger="Open" source="client"/> </state> <state name="OpenSent" timeout="10" timeoutEvent="Timeout"> <transition target="Opened" trigger="OpenAck" source="server"/> </state> <state name="Opened"> <transition target="TradeConfirmed" trigger="TradeConfirmation" source="server"/> <transition target="TradePassed" trigger="Pass" source="server"/> <transition target="TradeExpired" trigger="Expired" source="server"/> </state> <state name="TradeConfirmed"> </state> <state name="TradePassed"> </state> <state name="TradeExpired"> </state> </tradeModel> </tradeModels>
The XML configuration file contains all possible routes a trade can traverse on its way to completion, whether or not it is successful. There are a number of states, each containing a number of transitions that cause the trade model to move to other states. A transition defines the message that will cause the change to occur, and the new state the model will move into. Transition events correlate to either server-side or client-side trade messages.
Methods
get State Machine(model Name)
Returns a new StateMachine for the specified model name.
Parameters:
Name | Type | Description |
---|---|---|
modelName |
String | The model name for the wanted StateMachine. |
Throws:
-
If the specified model does not exist.
- Type
-
module:ct-core
/Error
Returns:
A new state machine for the specified model name, set to the initial state.
load Models(file Url)
Loads the models into the factory from the given file at the specified url.
Parameters:
Name | Type | Description |
---|---|---|
fileUrl |
String | The URL of the file to load the models from. |
Throws:
-
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
- Type
-
module:ct-core
/Error
load Models From Xml(sXml String)
Loads the models into the factory from the specified XML string.
Parameters:
Name | Type | Description |
---|---|---|
sXmlString |
String | The XML to load the models from. |
Throws:
-
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
- Type
-
module:ct-core
/Error
load Models From Xml Element(XML)
Loads the models into the factory from the specified XML DOM element.
Parameters:
Name | Type | Description |
---|---|---|
XML |
DOM element to load the models from. |
Throws:
-
If more than one model with the same name is defined in the XML, or if there was an error parsing the XML.
- Type
-
module:ct-core
/Error