Message Triggered Transition

Such transition is executed when the statechart receives a message (an instance of an arbitrary Java class, or primitive type 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 send() functions, see the functions list here.

When a statechart receives a message:

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.

To define a message triggered transition

  1. Select the transition in the graphical editor.
  2. In the Properties view, choose Message from the Triggered by drop-down list.
  3. If you want to perform message type checking, specify the message type allowed to trigger the transition using Message type parameter. To define some Java class, select the Other 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.
  4. Otherwise, if you do not wish to perform message type checking, leave the default settings when Other button is selected and Object class is specified.
  5. Now define the message contents checking conditions using the Fire transition group of buttons.
  6. In case you do not wish to perform message contents checking, simply choose the Unconditionally option.
  7. 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 Message below. It works in the following way: when a message is received at a statechart, AnyLogic calls the function equals() of a descriptor, giving a reference to the message as a parameter. The function equals() 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. false means no match. Possible message descriptors are "STOP!" for a message of type String, or 5.0 for a message of type Double.
  8. 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 msg variable.
  9. Enter the transition's guard expression in the Guard edit box.
  10. Enter the transition's action code in the Action edit box.

Statechart queue

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 fireEvent() 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).

Related topics



Triggering a transition