To develop a component with FSM Tool:
-
write the FSM specifications — use the FSM DSL to write a text file defining states, actions, transitions, inputs, and outputs
-
generate the classes — use the spec you’ve written to generate code
-
extend the generated SBB and FSM POJOs — deploy runtime classes, extend the class, map events to inputs, unset durable inputs, and implement action methods
-
compile, package, and deploy — use standard methods to deploy the completed SBB
-
document — use FSM Tool’s features to automatically document the SBB.
Specify the state machines
When creating multiple FSMs per SBB the process is the same as for bSBB FSM specification.
The FSM Tool installation has an example called multifsmsbb
. This example has two FSMs:
-
MessageFSM
— handles text string requests in seconds for delay before responding -
TimerFSM
— handles the timer for delayed responses.
Generate the FSM POJO classes and hosting SBB class
FSM Tool uses the FSM specifications to generate an FSM POJO classes and SBB class. To correctly generate the code:
-
Set up the Ant
build.xml file
to use the FSM Tool Ant task (see make-multi-fsm-sbb):-
Add a
<fsmtool:make-multi-fsm-sbb>
task to the build file, and set the properties of the task for the component under development. -
Run Ant on the target that includes the
<fsmtool:make-multi-fsm-sbb>
task. -
Look for errors that the FSM Tool reports when parsing the specification — correct them, and re-run the Ant target.
-
Implement the necessary classes
The FSM specification defines the abstract behaviour of the component. To make it work, you must:
-
create an SBB class which maps received events to raised inputs, and executes the state machines which have been registered. The SBB must extend the generated FSM host SBB.
-
define, create and register implementations of the actions interfaces (defined by a generated Actions interfaces) which contain implementations for the FSM’s action methods.
Here are the required steps:
1 |
Deploy runtime classes FSM Tool has a small runtime environment. The generated FSM SBB implements the |
---|---|
2 |
Extend the generated FSM hosting SBB The developer-defined SBB class extends the generated FSM hosting SBB class, as follows:
|
3 |
Wire up and register the actions implementation classes The FSMs are wired up to support interaction between the FSMs. The FSM action implementation POJO classes are registered to the generated FSMs.
|
4 |
Map events to state machine inputs Create SBB’s event handlers to map events to state-machine inputs, and to call the state machines. The following snippet shows the typical pattern of usage in an SBB event-handler method in a FSM hosting SBB:
You can directly reference the inputs, which are kept internally in the generated state-machine SBB class. For example, if the declared input is message and received on endpoint tcp, the service calls the If you need to set more than one input before executing the state machine, simply add more Finally, trigger the FSM execution cycle by calling In this example there is a second FSM called TimerFSM. It is accessed using |
5 |
Implement actions interfaces Each action defined in the state machine specification renders into a method declaration in an actions interface, which is declared as an inner interface of the state-machine POJO class. In this case
The action interfaces are typically implemented in POJO classes, and an instance must be registered with the state machine execution class (best to do this in the
|
Compile, package, and deploy the SBB and supporting POJO classes
Follow standard procedures
Once you’ve finished the steps to implement an classes, use the |
Generate documentation
To create a graphic illustration of the state machine, configure a <fsmtool:generate-dot>
task to generate the Graphviz dot file format (see the "Hello World" example for details).