Querying transitions

40 views
Skip to first unread message

Gaurav Arora

unread,
Oct 28, 2014, 7:38:49 AM10/28/14
to squirrel-st...@googlegroups.com
Hi,

We're writing a FSM that will be hidden behind a RESTful interface. We return back the possible transitions of the FSM in the responses using HATEOAS. Ideally we would like to do this by querying the state machine to ask for available transitions from a particular state so we can link this information. However we haven't been able to find any methods that would expose available transitions. Do such methods exist?

Thanks,
Gaurav

He Henry

unread,
Oct 28, 2014, 10:16:40 PM10/28/14
to squirrel-st...@googlegroups.com
Hi Gaurav,

StateMachine.getCurrentRawState() will return ImmutableState instance of current stage which contains all available transition informations, e.g. ImmutableState.getAllTransitions() will return all available transitions start from this state and also ImmutableState.getTransitions(E event) will return all possible transitions triggered by input event. 

Moreover, you can also use SCXMLVisitor to export each transition xml definition for further usage, e.g.
        <state id="RIGHT">
            <transition cond="InBorderCondition" event="MOVE_AHEAD" target="RIGHT">
                <raise event="callMethod(SnakeController.onMove)"/>
            </transition>
            <transition cond="Always" event="TURN_UP" target="UP">
                <raise event="callMethod(SnakeController.onChangeDirection)"/>
            </transition>
            <transition cond="Always" event="TURN_DOWN" target="DOWN">
                <raise event="callMethod(SnakeController.onChangeDirection)"/>
            </transition>
        </state>

Thanks,
Henry

在 2014年10月28日星期二UTC+8下午7时38分49秒,Gaurav Arora写道:

Gaurav Arora

unread,
Oct 29, 2014, 3:54:12 AM10/29/14
to squirrel-st...@googlegroups.com
Thanks Henry, that works perfect.
Reply all
Reply to author
Forward
0 new messages