State machine model#
- class besser.BUML.metamodel.state_machine.state_machine.Body(name: str, callable: Callable)[source]#
Bases:
Method
The body of the state of a state machine.
Each state has a Body, which defines the sequence of actions to be executed when an event causes the transition to a state (and a secondary body, i.e., a fallback body, that defines the actions to be executed in case of error in the machine).
- Parameters:
name (str) – The name of the body.
callable (Callable) – The function containing the body’s code.
- parameters#
Inherited from Method, the set of parameters for the body.
- Type:
- _abc_impl = <_abc._abc_data object>#
- class besser.BUML.metamodel.state_machine.state_machine.Condition(name: str, callable: Callable)[source]#
Bases:
Method
The representation of a condition (i.e., a boolean function) that may cause the transition of state in a state machine.
- Parameters:
name (str) – The name of the condition.
callable (Callable) – The function containing the condition’s code.
- parameters#
Inherited from Method, the set of parameters for the condition.
- Type:
- _abc_impl = <_abc._abc_data object>#
- class besser.BUML.metamodel.state_machine.state_machine.ConfigProperty(section: str, name: str, value: Any)[source]#
Bases:
object
A configuration property of a state machine.
- Parameters:
- value#
Te value of the configuration property
- Type:
Any
- class besser.BUML.metamodel.state_machine.state_machine.Event(name: str)[source]#
Bases:
NamedElement
The representation of an event (i.e., external or internal stimuli or input) that may cause the transition of state in a state machine.
- Parameters:
name (str) – The name of the event.
- _abc_impl = <_abc._abc_data object>#
- class besser.BUML.metamodel.state_machine.state_machine.Session[source]#
Bases:
object
A user session in a state machine execution.
When a user starts interacting with a state machine, a session is assigned to him/her to store user related information, such as the current state or any custom variable. A session can be accessed from the body of the states to read/write user information. If a state machine does not have the concept of ‘users’ (i.e., there are no concurrent executions of the state machine, but a single one) then it could simply have 1 unique session.
- delete(key: str) None [source]#
Delete an entry of the session private data storage.
- Parameters:
key (str) – the entry key
- get(key: str) Any [source]#
Get an entry of the session private data storage.
- Parameters:
key (str) – the entry key
- Returns:
the entry value, or None if the key does not exist
- Return type:
Any
- move(transition: Transition) None [source]#
Move to another state of the state machine.
- Parameters:
transition (Transition) – the transition that points to the state to move
- class besser.BUML.metamodel.state_machine.state_machine.State(sm: StateMachine, name: str, initial: bool = False)[source]#
Bases:
NamedElement
A state of a state machine.
- Parameters:
sm (StateMachine) – the state machine the state belongs to
name (str) – the state name
initial (bool) – whether the state is initial or not
- visibility#
Inherited from NamedElement, determines the kind of visibility of the state (public as default).
- Type:
- sm#
the state machine the state belongs to
- Type:
- transitions#
The state’s transitions to other states
- Type:
- _transition_counter#
Count the number of transitions of this state. Used to name the transitions.
- Type:
- _abc_impl = <_abc._abc_data object>#
- _t_name() str [source]#
Name generator for transitions. Transition names are generic and enumerated. On each call, a new name is generated and the transition counter is incremented for the next name.
- Returns:
a name for the next transition
- Return type:
- set_fallback_body(body: Body) None [source]#
Set the state fallback body.
- Parameters:
body (Body) – the body
- when_condition(condition: Condition) TransitionBuilder [source]#
- when_event(event: Event) TransitionBuilder [source]#
- class besser.BUML.metamodel.state_machine.state_machine.StateMachine(name: str)[source]#
Bases:
Model
A state machine model.
- Parameters:
name (str) – the state machine name
- visibility#
Inherited from Model, determines the kind of visibility of the state machine (public as default).
- Type:
- properties#
the configuration properties of the state machine.
- Type:
- _abc_impl = <_abc._abc_data object>#
- add_property(property: ConfigProperty) ConfigProperty [source]#
Add a configuration property to the state machine.
- Parameters:
property (ConfigProperty) – the property to add
- Returns:
the configuration property
- Return type:
- initial_state() State [source]#
Get the state machine’s initial state. It can be None if it has not been set.
- Returns:
the initial state of the machine, if exists
- Return type:
State or None
- new_property(section: str, name: str, value: Any) ConfigProperty [source]#
Create a new configuration property on the state machine.
- Parameters:
- Returns:
the configuration property
- Return type:
- class besser.BUML.metamodel.state_machine.state_machine.Transition(name: str, source: State, dest: State, event: Event, conditions: list[Condition])[source]#
Bases:
NamedElement
A state machine transition from one state (source) to another (destination).
A transition is triggered when an event and/or condition/s occurs.
- Parameters:
name (str) – Inherited from NamedElement, the transition name
source (State) – the source state of the transition (from where it is triggered)
dest (State) – the destination state of the transition (where the machine moves to)
event (Callable[[Session, dict], bool]) – the event that triggers the transition
conditions (list[Condition]) – the conditions that trigger the transition
- visibility#
Inherited from NamedElement, determines the kind of visibility of the named element (public as default).
- Type:
- _abc_impl = <_abc._abc_data object>#
- class besser.BUML.metamodel.state_machine.state_machine.TransitionBuilder(source: State, event: Event = None, conditions: list[Condition] = None)[source]#
Bases:
object
A transition builder.
This class is used to build transitions, allowing for a “fluent api” syntax where consecutive calls can be made on the same object.
- Parameters:
- go_to(dest: State) None [source]#
Set the destination state of the transition.
Completes the transition builder and effectively adds the source state.
- Parameters:
dest (State) – the destination state
- with_condition(condition: Condition) TransitionBuilder [source]#