Caplin Trader 5.1.0

Class: module:ct-trading/statemachine/StateModel

module:ct-trading/statemachine/StateModel(sModelName)

new module:ct-trading/statemachine/StateModel(sModelName)

Constructs a StateModel.

The StateModel represents the network of module:ct-trading/statemachine/States that a module:ct-trading/statemachine/StateMachine operates on. It contains a group of related states, and the start state. As used in the trade model code, there would be a single StateModel for each protocol trade flow (e.g. ESP). The StateModel is simply a convenient place to store related states.

It has two phases, configuration and use. During configuration, the various adding and setting methods should be called. During use, only the getInitialState method is expected to be called.

Parameters:
Name Type Description
sModelName String

The name the model represents.

Methods

addState(oState)

Add a state object to this group of related States. It is expected that this method will only be called during the configuration phase of the StateModel.

Parameters:
Name Type Description
oState module:ct-trading/statemachine/State

The state object to add to this StateModel

Throws:

if the module:ct-trading/statemachine/State has already been added, or if it is not an instance of module:ct-trading/statemachine/State

Type
module:ct-core/Error

getAllStates()

Returns all the states contained within this StateModel.

getInitialState()

Get the State that a StateMachine operating on this group of States should start with.

Throws:

if the initial state has not already been set.

Type
module:ct-core/Error
Returns:

The initial state object of a model

getName()

Returns the model name that this StateModel represents.

Returns:

The name of the model.

setInitialState(oState)

Set the State that a StateMachine operating on this group of States should start with. It is expected that this will be called only once, when the StateModel is being configured.

Parameters:
Name Type Description
oState module:ct-trading/statemachine/State

The initial state object for a model.

Throws:

if the initial state has already been set, or the caller tries to set it to null or something that is not an instance of module:ct-trading/statemachine/State.

Type
module:ct-core/Error