Instances are concurrent threads of control executing a Flowchart. They execute the same state machine network stack logic (defined by a Flowchart) but have separate contexts (env, local data, etc.).
Q: What is the role of instances in FlowCoder?
A: It is the machanism for implementing concurrent calls/transactions.
NULL Instance is a special instance. It is the only instance automatically created at the start of Flowchart execution. Other instances are created dynamically by NULL Instance as described below. We call them working instances or just instances.
All instances other than NULL Instance are called working instances or just instances.
An instance can share data with other instances via global variables and network sockets.
NULL Instance is a special instance. It is the only instance automatically created at the start of Flowchart execution. NULL Instance starts at NULL State and remains in this state until the execution stops. Each time a triggering event (described below) takes place, NULL Instance spawns a new working instance.
- Starts when Flowchart execution starts
- Stops when Flowchart execution stops
- Always stays in NULL State
- Creates other (working) instances
Working instances are instances which are not NULL Instance. We’ll call them just instances from now on.
New instance is created by NULL Instance executing one of the following Blocks under special circumstanes:
Newly created instances are automatically enumerated. NULL Instance always has Instance ID = 0. The first instance spawned by NULL Instance is assigned 1, the next one — 2, etc.
A new instance inherits a copy of the Flowchart with all the associated data. The instance-scope variables are inherited at their initial values.
NULL Instance creates a new instance on reception of a packet by a Receive Block directly descending from a NULL State Block. Every packet of interest is presented to all instances for the opportunity to accept it for processing before it is shown to NULL Instance. New instance creation by a Receive Block happens only if none of the existing instances accepts the packet for processing.
A new instance is created periodically by a Trigger Block directly descending from a NULL State Block. Operations at the bottom pane of Trigger Block are executed by the newly created instance. This mechanism is usually used by a client side Flowchart.
A instance is “in State” ABC when it waits in ExitState Block ABC. The moment the instance starts executing one of children Blocks of the ExitState Block, it is described as “in transition” between states until it executes an EnterState Block.