The Alf code in your project is not executed directly. Rather, it is translated by the Alf compiler into UML Activities within the larger model containing the Alf code. These Activities can then be executed using Cameo Simulation Toolkit (CST), as part of an overall simulation of your UML model.

A simulation of a model that contains Alf code is run as for any other executable model using CST. Either click on an executable element in your model and select Simulation > Run (or Run in Context, as appropriate) or create a simulation configuration and run that.

If an active Class is instantiated using an Alf instance creation expression, then the classifier behavior for the Class is explicitly started on the newly created instance after the completion of initialization of the instance. However, the default MagicDraw option is to Autostart Active Objects, in which case the classifier behavior for an active object will be automatically started as soon as the object is created. While MagicDraw will ensure that any Properties with default values are properly initialized before the classifier behavior is started, if you have initialization code in a constructor for an active Class, then this will not execute before the classifier behavior starts.

Therefore, if you intend to instantiate an active Class from Alf code using a constructor that carries out initialization on which the classifier behavior depends, it is important to make sure that the classifier behavior waits for the constructor execution to complete. You can do this by having the classifier behavior wait for a special Start Signal before carrying out any other behavior, and having the constructor invoke this.Start() when it is done with its initialization behavior. (If the classifier behavior is an activity, then use an Accept Event Action to wait for the Start signal. If the classifier behavior is a State Machine, have the State Machine transition from its initial Pseudostate to a Waiting State that is exited by a Transition triggered by the Start Signal.)

Alternatively, you can turn off the Autostart Active Objects option:

  1. Select Options > Envronment from the main menu.
  2. Choose Simulation (the last option group on the left).
  3. Uncheck the Autostart Active Objects option under Simulation Frameworks (so it is false).

However, doing this will turn off the option globally for all projects, which may cause some other simulation projects to not work. You can turn this option off for just a specific project if you use a simulation configuration, by setting the Autostart Active Objects property to false in your configuration.