Executable State Machines

Executable State Machines provide a powerful means of rapidly generating, executing and simulating complex state models. In contrast to dynamic simulation of State Charts using Enterprise Architect's Simulation engine, Executable State Machines provide a complete language-specific implementation that can form the behavioral 'engine' for multiple software products on multiple platforms. Visualization of the execution uses and integrates seamlessly with the Simulation capability. Evolution of the model now presents fewer coding challenges. The code generation, compilation and execution is taken care of by Enterprise Architect. For those having particular requirements, each language is provided with a set of code templates. Templates can be customized by you to tailor the generated code in any ways you see fit.

These topics will introduce you to the basics of modeling Executable State Machines and tell you how to generate and simulate them.

Executable State Machines

This collection of images spotlights the process of designing, compiling, executing and simulating a State Machine.

Overview of Building and Executing State Machines

Building and using Executable State Machines is quite straight forward, but does require a little planning and some knowledge of how to link the different components up to build an effective executing model. Luckily you do not have to spend hours getting the model right and fixing compilation errors before you can begin visualizing your design.

Having sketched out the broad mechanics of your model, you can generate the code to drive it, compile, execute and visualize it in a matter minutes. These points summarize what is required to start executing and simulating State Machines.



Build Class and State models

The first task is to build the standard UML Class and State models that describe the entities and behavior to construct. Each Class of interest in your model should have its own State Machine that describes the various states and transitions that govern its overall behavior.

Create an Executable Statemachine Artifact

Once you have modeled your Classes and State models, its time to design the Executable Statemachine Artifact. This will describe the Classes and objects involved, and their initial properties and relationships. It is the binding script that links multiple objects together and it determines how these will communicate at runtime. Note that it is possible to have two or more objects in an Executable Statemachine Artifact as instances of a single Class. These will have their own state and behavior at run-time and can interact if necessary.

Generate Code and Compile

Whether it is Javascript, C++, Java or C# that you need, EA's engineering capabilities provide you with a powerful tool, allowing you to regenerate the executable at any time, and without the loss of any customized code you may have made. This is a major advantage over a project's lifetime. It is probably also worth noting that the entire code base generated is independent and portable. In no way is the code coupled with any infrastructure used by the simulation engine.

Execute State Machines

So how do we see how these state machines behave. One method is to build the code base for each platform, integrate it in one or more systems, examining the behaviors, 'in-situ', in perhaps several deployment scenarios. Or we can execute it with Enterprise Architect. Whether it is Java, Javascript, C, C++ or C#, EA will take care of creating the runtime, the hosting of your model, the execution of it's behaviors and the rendition of all state machines.

Visualize State Machines

Executable Statemachine visualization integrates with Enterprise Architect's Simulation tools. Watch state transitions as they occur on your diagram and for which object(s). Easily identify objects sharing the same state. Importantly, these behaviors remain consistent across multiple platforms. You can also control the speed at which the machines operate to better understand the timeline of events.

Debug State Machines

When states should change but do not, when a transition should not be enabled but is, when the behavior is in short undesirable and not immediately apparent from the model, we can turn to debugging. Enterprise Architect's Visual Execution Analyzer comes with debuggers for all the languages supported by Executable State Machine code generation. Debugging provides many benefits, one of which might be to verify / corroborate the code attached to behaviors in a State Machine to ensure it is actually reflected in the executing process.