150 likes | 253 Views
StateMachine representations (file formats). Maciej Czechowski. Introduction. Harel StateCharts have become a convenient way for describing applications and services. Currently there are a few major file formats designed for storing StateMachine information. UML – graphical solution.
E N D
StateMachine representations(file formats) Maciej Czechowski
Introduction Harel StateCharts have become a convenient way for describing applications and services. Currently there are a few major file formats designed for storing StateMachine information.
UML – graphical solution UML has support for Harel-like statemachines with some Object-Oriented additions. This allows easy design, using one of many UML-tools available. • easy graphical design • statemachines are only part of UML, they have to be part of classes or collaborations and use their datamodel • different tools may use different file formats
XMI –XML metadata interchange • interchange format for UML – allows different tools to work together • text format, based on XML • saves all UML features – results are very large • no direct, clearly specified way for describing statemachine variables (they may to be described in other elements, e.g. parent class, if needed), etc. • hardly human-readable, designed for machine analysis
SCXML – StateChart XML • XML based language developed by W3C (current status: working draft) • general-purpose event-based state machine language based on Harel statecharts • has well-defined datamodel • human readable • execution environment based on webservices exists (Apache SCXML)
XMI vs SCXML • XMI comes from UML-diagram,is larger and less readable • Most of UML design tools can produce XMI files, providing comfortable way to design statemachines; SCXML is still working draft with few tools available • SCXML files are smaller andcleaner as they represent only StateMachines with their datamodel, while XMI saves all UML metadata • Conversion between these formats should be possible, although it would not be 1:1 (e.g. SCXML does not support Choice states)
Other formats • ebXML – language designed for business process specification; its statemachine language semantics are closely connected to e-commerce and therefore not applicable for general applications • XTND – notation for simple finite state machines; lacks Harel statecharts additions (parallel states,etc.) • other formats exits, but are rather unpopular and used mostly in proprietary solutions
Runtime representation (1/4) • StateMachines can be used for direct execution by developing Virtual Machine. • VM designed for mobile environment would need compact data files, describing only logic required for correct StateMachine execution – let’s call such file format as runtime representation. • XML-based formats do not meet these requirements!
Runtime representation (2/4) • Both XMI and SCXML save all design information (such as variable names). XMI saves also a lot of UML-specific information. • All expressions and commands (guards, effects) are saved as plain text (opaque expressions) without parsing, type checking, variable matching, etc. • Many parts of design information are not used in runtime!
Runtime representation (3/4) • State and variable names are not needed in runtime, as they have unique identifiers. • We have to maintain Operation (used for triggers) and Effect names, as they come from and are parsed outside. • Effect and Guard expressions can be saved as corresponding Abstract Syntax Trees – syntax and type checking can be made after design; virtual machine can be simpler (no parser)!
Runtime representation (4/4) • XML format uses a lot of space for tags – as runtime representation format is designed for machine analysis we can use more compact binary format. • Simple translator was designed, being able to convert XMI file to binary (maintaining UML StateChart structure).
Simple Example Consider the following simple StateMachine: Attributes: tempInFahrenheit : int temperature : int Operations: tempRead(tempInFahrenheit: out)
AssignCommand for the opaque behaviour temperature=tempInFahrenheit+273 SimpleVariable BinaryExpression reference to temperature AST tree is built… right left Operator VariableExpression IntegerExpression + SimpleVariable 273 reference to tempInFahrenheit and can be byte-saved as 5C5A 00006466745A0001686E0000 01117207 Example - AST
Example - results (size in bytes)
Summary • Design-stage formats like XMI or SCXML provide easy way for describing StateMachines, however they save a lot of additional information not needed in runtime. • By removing unnecessary names, parsing expressions and saving result as byte stream a great size improvement can be achieved. • Binary format is mostly unusable for further editing, but can have great use for virtual machines as it fully maintains statemachine logic.