Skip to content

Element <state-machine>

Purpose: Declare a named weighted state graph consumed as a deterministic generator.

Why: Use it when generated values must follow a named, weighted transition graph.

Example

1
<state-machine id="orderLifecycle"/>

Decision guide

Business value: Generates values that obey an explicit business lifecycle instead of independent sampling.

  • Use when

    • A status or state must follow allowed, optionally weighted transitions.
  • Choose another approach when

    • Values are independent categories without lifecycle constraints.
  • Prerequisites

    • Declare a start state and a connected set of transition children.
  • Alternatives

    • Use key values or weights for independent categorical sampling. (See: <key>)

Complete examples

Generate a deterministic order lifecycle from a transition graph

Use a state machine when values must follow allowed business transitions instead of independent random selection.

order-lifecycle/datamimic.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<setup rngSeed="42">
    <state-machine id="order_lifecycle" start="open">
        <transition from="open" to="paid"/>
        <transition from="paid" to="shipped" weight="0.9"/>
        <transition from="paid" to="cancelled" weight="0.1"/>
        <transition from="shipped" to="delivered"/>
    </state-machine>
    <generate name="orders" count="20" target="LogExporter">
        <key name="status" generator="order_lifecycle"/>
    </generate>
</setup>

Rules and invalid combinations

I923 — State Machine No Transitions

must declare at least one child

Why: A element has zero children.

Resolution: Add at least one child.

Full rule

I924 — State Machine Duplicate Id

Duplicate : a state machine with this id is already registered

Why: Two or more elements declare the same id=.

Resolution: Use a distinct id= for each .

Full rule

I925 — State Machine Id Collides With Generator

collides with a builtin generator class name

Why: A matches an existing builtin generator class name.

Resolution: Choose an id= that does not match any registered generator class name.

Full rule

Allowed parents / Allowed children

Allowed parents: else, else-if, if, setup, while

Allowed children:

transition

Attributes

Show all 2 attributes

id

Registration id for this state machine; referenced later via generator=.

required; string.

start

Starting state name. Defaults to the first 's from= in document order.

optional; string; Default: null.