Apama 10.2 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in Event Modeler | Working with Blocks Created from Scenarios | Creating sub-scenarios
 
Creating sub-scenarios
The scenario block create operation creates a new sub-scenario with the current values of the scenario block's input-variables parameters. A sub-scenario is an instance of the source scenario. Call this operation for each sub-scenario you want to create.
You can have any number of sub-scenarios running in parallel. You do not need to wait for one sub-scenario to complete processing before you create another sub-scenario. When you invoke the create operation, the scenario block immediately sends an update event to its output feed. The fields in this event have the following values:
*instance id — This field provides the instance ID of the sub-scenario being created. This is either the instance ID you specified as the value of the instance id parameter before you called the create operation, or it is the instance ID generated by the scenario block if the value of the instance id parameter was an empty string. For the format of a generated instance ID, see Descriptions of scenario block parameters.
*instance created — This field is false because the scenario block has not yet created the new sub-scenario.
*instance ended — This field is also false.
*instance status — This field has a value of UNKNOWN because, again, the scenario block has not yet created the new sub-scenario.
In addition, the output feed contains a field for each variable that the source scenario defines.
As soon as the scenario block actually creates the new sub-scenario, it sends another event to the output feed. This time, if creation was successful, the instance created field is true, and the instance status field is RUNNING. For example, you might want to do something like this:
State: Step 1
When  true
Then  create [MyScenarioBlock]
Then  move to state [Step 2]

State: Step 2
When  instance created from MyScenarioBlock (output)
Then  status = "Instance created successfully"
When the scenario block sends the first event after you invoke the create operation, that event indicates that the sub-scenario you are creating is the context sub-scenario. For example, to issue two orders in sequence you can specify the following:
State 1

When  true
Then  Symbol from MyScenarioBlock = "APMA"
Then  create [MyScenarioBlock]
Then  continue

When  instance status from MyScenarioBlock(output) = "ENDED"
Then  Quantity = Quantity + Quantity from MyScenarioBlock(output)
Then  Symbol from MyScenarioBlock = "MSFT"
Then  create [MyScenarioBlock]
Then  move to state [State 2]

State 2
When  instance status from MyScenarioBlock(output) = "ENDED"
               (Note that this now reflects the second sub-scenario created.)
Then  Quantity = Quantity + Quantity from MyScenarioBlock(output)
Alternatively, you can do it this way:
When  true
Then  Symbol from MyScenarioBlock = "APMA"
Then  create [MyScenarioBlock]
Then  Symbol from MyScenarioBlock = "MSFT"
Then  create [MyScenarioBlock]
Then  Symbol from MyScenarioBlock = "ORCL"
Then  create [MyScenarioBlock]
To operate on a sub-scenario that you just created, you must wait for the value of the instance status field to be RUNNING.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release