Topic
Prev Next

Executable StateMachines

Executable StateMachines 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 StateMachines 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 introduce you to the basics of modeling Executable StateMachines and tell you how to generate and simulate them.


Executable StateMachines

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


Overview of Building and Executing StateMachines

Building and using Executable StateMachines 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 StateMachines.

Facility

Description

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 StateMachine 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 use, Enterprise Architect'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 might 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 StateMachines

So how do we see how these StateMachines 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#, Enterprise Architect will take care of creating the runtime, the hosting of your model, the execution of its behaviors and the rendition of all StateMachines.

Visualize StateMachines

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 StateMachines

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 ExecutableStateMachine code generation. Debugging provides many benefits, one of which might be to verify / corroborate the code attached to behaviors in a StateMachine to ensure it is actually reflected in the executing process.