Class
caplin.trading.statemachine

StateMachine

A StateMachine tracks state and manages transitions between them.

Constructor Summary

Attributes Name and Description
caplin.trading.statemachine.StateMachine(caplin.trading.statemachine.StateModel oStateModel)

Constructs a StateMachine that uses the specified StateModel to determine which transitions are possible from the current state.

Method Summary

Attributes Name and Description
void addStateChangedListener(caplin.trading.statemachine.StateChangedListener oStateChangedListener)

Adds a listener that will be notified any time the state of this statemachine changes.

void addTriggerActiveChangedListener(caplin.trading.statemachine.TriggerActiveChangedListener oTriggerActiveChangedListener, String sEvent)

Adds a listener that will be notified any time the supplied trigger goes from active to inactive or inactive to active.

caplin.trading.statemachine.State getCurrentState()

Gets the current state that the state machine is in.

String getName()

Returns the name that this state machine represents.

String getStateModel()

Returns the state model the state machine is an instance of.

caplin.trading.validation.ValidationResult processEvent(String sEvent, Object oContext)

Attempts to change the state to a new state, following a transition defined as being activated by the supplied Event.

void removeStateChangedListener(caplin.trading.statemachine.StateChangedListener oStateChangedListener)

Removes a StateChangedListener.

void removeTriggerActiveChangedListener(caplin.trading.statemachine.TriggerActiveChangedListener oTriggerActiveChangedListener, String sEvent)

Removes the specified listener from the list of those to be notified when the specified event triggers a transition from one state to another.

void testContext(Object oContext)

Tests a specific context against the current state.

Constructor Detail

caplin.trading.statemachine.StateMachine(caplin.trading.statemachine.StateModel oStateModel)

Constructs a StateMachine that uses the specified StateModel to determine which transitions are possible from the current state.

Parameters
caplin.trading.statemachine.StateModel oStateModel The statemodel for this statemachine. May not be null.

Method Detail

void addStateChangedListener(caplin.trading.statemachine.StateChangedListener oStateChangedListener)

Adds a listener that will be notified any time the state of this statemachine changes.

Parameters
caplin.trading.statemachine.StateChangedListener oStateChangedListener The listener that wishes to be notified of state changes. May not be null or undefined.
Throws
caplin.core.Error
if the listener is not a non-null instance of StateChangedListener.

void addTriggerActiveChangedListener(caplin.trading.statemachine.TriggerActiveChangedListener oTriggerActiveChangedListener, String sEvent)

Adds a listener that will be notified any time the supplied trigger goes from active to inactive or inactive to active. A trigger is considered active if there is an event that would trigger a transition from the current state given the supplied context.

Parameters
caplin.trading.statemachine.TriggerActiveChangedListener oTriggerActiveChangedListener The listener that wishes to be notified of possible state changes. May not be null or undefined.
String sEvent The Event that we're interested in. Must be a non-null string.
Throws
caplin.core.Error
if the listener is not a non-null instance of StateChangedListener.

caplin.trading.statemachine.State getCurrentState()

Gets the current state that the state machine is in.

Returns
The current caplin.trading.statemachine.State of this Statemachine. Will not be null.

String getName()

Returns the name that this state machine represents.

Returns
The state machine name

String getStateModel()

Returns the state model the state machine is an instance of.

Returns
The state model

caplin.trading.validation.ValidationResult processEvent(String sEvent, Object oContext)

Attempts to change the state to a new state, following a transition defined as being activated by the supplied Event. If the validators pass, it will change state. If they do not pass, the state will remain the same.

Parameters
String sEvent The event that triggers a transition to a new state.
Object oContext The data to be validated - indicating whether or not the transition is allowed.
Throws
caplin.core.Error
if the Event is not a non-null string, If context is null or undefined, if the Event doesn't lead to a state from the current state, or if any of the validators throws an exception.
Returns
The result of checking the validations for the transition associated with this Event.

void removeStateChangedListener(caplin.trading.statemachine.StateChangedListener oStateChangedListener)

Removes a StateChangedListener.

Parameters
caplin.trading.statemachine.StateChangedListener oStateChangedListener The listener that no longer wishes to be notified of state changes. May not be null or undefined.
Throws
caplin.core.Error
if the listener is not a non-null instance of StateChangedListener.

void removeTriggerActiveChangedListener(caplin.trading.statemachine.TriggerActiveChangedListener oTriggerActiveChangedListener, String sEvent)

Removes the specified listener from the list of those to be notified when the specified event triggers a transition from one state to another.

Parameters
caplin.trading.statemachine.TriggerActiveChangedListener oTriggerActiveChangedListener The listener that no longer wants to be notified of possible state changes. May not be null or undefined.
String sEvent The Event that we're no longer interested in. Must be a non-null string.
Throws
caplin.core.Error
if the listener is not a non-null instance of StateChangedListener.

void testContext(Object oContext)

Tests a specific context against the current state. If this new context would change the result of calling any validators - i.e. some transitions that under the previously tested context could not be followed can, under the supplied context be followed (or vice versa) - then all the TriggerActiveChangedListeners associated with the Event that would give a different result to before are notified. A concrete example is an execute button. It wants to be told any time the situation of the Execute trigger changes.

Parameters
Object oContext the data context. May not be null or undefined.