Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

An active Class is one that has a classifier behavior associated with it, which defines the asynchronous behavior of instances of the class. When such a classifier behavior is an Activity or an Opaque Behavior, you can specify it using Alf code.

Warning

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 Cameo Simulation Toolkit 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 CST 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, 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 > Environment 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 Objectsproperty to false in your configuration.


To create a classifier behavior using Alf


  1. Open the Specification window for the Class and check the Is Active property.

    Info

    If the Is Active property does not appear in the Specification window, select All from the Properties drop-down at the top right of the window.


  2. Close the Specification window.
  3. Right click on the Class in the Model Browser, select Create Element and choose Activity or Opaque Behavior.


    Note

    MagicDraw will automatically make the newly created Behavior a classifier behavior only if the Class is an active Class. So be sure a Class is marked as active before attempting to create a classifier behavior under it. Otherwise you will need to manurally set the new Behavior as the Classifier Behavior property in the Specification window for the Class.


  4. Select the newly created Behavior and open the Alf editor window (select Windows > Alf), if it isn't already open.



  5. Enter the Alf code for the classifier behavior and click on the Save button to compile and save the code.


Once a classifier behavior is created as above, it is simply an Activity or Opaque Behavior with an Alf body, and it can be edited as described in Using Alf to define Activities or Using Alf in Opaque Behavior bodies. You can also edit a classifier behavior that has an Alf body in the Alf editor by selecting the Class that owns the behavior.

Info

While a classifier behavior may be edited like any other Behavior with an Alf body, as an asynchronous Behavior it is allowed to have Alf accept statements, which can handle Signals sent to instances of its active Class and are not allowed in synchronously called Behaviors. However, Alf requires that, for any Signal appearing in an accept statement, the containing Class must have a Reception (as shown below).

Referencing a Reception in an Alf accept statement



Panel
titleRelated pages