Message Triggered Transition
Such transition is executed when the statechart receives a message (an instance of an arbitrary Java class, or
value) that conforms with the defined message descriptor. Arrival triggered transition is depicted by the icon
You send messages from one agent to other(s) by calling one of agent's
functions, see the functions list
When a statechart receives a message:
If there is one or several transitions outgoing from the current simple state or any of its container states, the trigger of which matches the first event in the queue, such transitions become enabled, i.e. one of it is taken depending on guards. The
message is immediately consumed.
- Otherwise, the message is discarded.
You can perform message checking and discard messages not matching the defined conditions. The match can be determined using only message class and/or the message object also.
- You can define message type checking to allow triggering transition only by messages of some particular message type.
- Moreover, you can filter messages by contents. You can define a message descriptor and accept only messages matching this descriptor. Event descriptor is an object, which is compared with a received message to decide if a transition should be
triggered – a filter for message events. Or you can define some boolean condition operating with message contents and check it on each message reception. Transition will be triggered only when this condition is
true. Since you can refer to the message contents in this expression, this way you can implement sophisticated message contents checking.
To define a message triggered transition
- Select the
in the graphical editor.
- In the
- If you want to perform message type checking, specify the message type allowed to trigger the transition using
parameter. To define some Java class, select the
button and enter the class name in the edit box on the right. In this case transition will be triggered only by messages of this particular type or Java class.
- Otherwise, if you do not wish to perform message type checking, leave the default settings when
button is selected and
class is specified.
- Now define the message contents checking conditions using the
group of buttons.
- In case you do not wish to perform message contents checking, simply choose the
- If you want to define the message descriptor and accept only messages with the same contents, choose the
On particular message
option and specify the descriptor value in the edit box
below. It works in the following way: when a message is received at a statechart, AnyLogic calls the function
of a descriptor, giving a reference to the message as a parameter. The function
may use just message type information, or may look at message parameters. If it returns
true, then the event matches the descriptor and the transition should be taken.
means no match. Possible message descriptors are
for a message of type
String, or 5.0 for a message of type
- Otherwise, if you want to define a sophisticated message contents checking using a condition, choose the
If expression is true
option. Enter the expression in the edit box below. Here you can access the just received message as
Enter the transition's guard expression in the
- Enter the transition's action code in the
Sometimes you may need to place incoming messages into the statechart queue. The message queue is necessary because message may arrive at those moments of time in which the statechart cannot react to events (e.g. when a transition is executed).
The queue is processed by a statechart every time something occurs to the statechart or
function of the statechart. It iteratively checks all message in the queue starting from the "oldest" one according to the following algorithm:
A statechart can make several consequent steps processing several messages from the queue (these steps take zero model time).
- If there is one or several transitions outgoing the current simple state or any of its container states, the trigger of which matches the currently checked message, such transitions become enabled, i.e. one of it is taken depending on guards.
This message and all preceding messages in the queue are discarded. The next message in the queue is processed.
- If there are no such transitions, the next message is processed.
Triggering a transition