In addition to per-user state, a scenario segment has some global, or collective, states -- that is, states associated with the segment as a whole. Consider the following example:

Here, the scenario waits for a particular date and time and then sends an e-mail invitation to all the site’s female users. The state machine for this scenario looks like this:

Notice that, unlike in the promotion example, there are no user-specific events here. Up until the transition to state 3, where the scenario sends e-mail to all women, there is no mention of users at all. Thus, the scenario server cannot use individual scenario instances to maintain the scenario state while scenario execution moves through states 0, 1, and 2. Instead, it uses a collective scenario instance, which is simply another repository item, of type collectiveScenario. The properties of collective instances are a subset of the individual instance properties:

When a scenario segment is first started, a single collective scenario instance, called the root instance, is always created and placed in the initial SSM state (in the example, state 0). After 1 second goes by, the root instance moves on to the next state, and so on, until the entire scenario state can no longer be represented by the collective instance, and individual instances must be created to hold per-user state. In the promotion example, the collective instance only proceeds as far as state 1 - after a user registers, an individual instance is created for him, and is subsequently responsible for maintaining that user’s scenario state. In the invitation example, however, the root instance proceeds as far as state 2; when taking the transition to state 3, it is replaced with individual instances, one for each of the female users.

In addition, collective scenario instances allow for scenarios which apply to anonymous, as well as registered, users.

Note that, because of database query overhead, individual scenario instances are generally more efficient than collective ones in terms of site performance. For more information, refer to Designing Effective Scenarios.

loading table of contents...