Instances are concurrent threads of control executing a Flowchart.
Instances execute the same state machine (stack logic described by the 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 working instances when triggered
New working instance is created by NULL Instance executing one of the following Blocks under special circumstanes:
Newly created working instances are automatically enumerated. NULL Instance always has Instance ID = 0. The first working instance spawned by NULL Instance is assigned 1, the next one — 2, etc.
A new working 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 working 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 working instances for the opportunity to accept it for processing before it is shown to NULL Instance. New working instance creation by a Receive Block happens only if none of the existing working instances accepts the packet for processing.
A new working 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 working 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.