Graph Composition and Nested Processes

Much like any software, a set of process definitions can grow larger, more complex and more intertwined as time goes. One solution used in the broader software world is encapsulation. This involves pulling out common functionality and breaking up large pieces into smaller components. These same techniques can be used with a set of process definitions. Rather than using copy/paste, sections of process definitions that are common can be extracted. Large process definitions can be split out into smaller components.

Sarasvati supports two ways of doing encapsulation, each with it's own advantages and disadvantages. The first is graph composition , the second is nested processes . Both of these techniques allow complete process definitions and components that have been split out to be defined in separately. The difference lies in when they are composed.

Now that we have general idea of how graph composition and nested processes compare, let us investigate them in more detail.

Graph Composition Example One

Let's look at an examples of how this works in practice. Here is a small process definition which we want to embed. This process definition will be named ext .

It only has two nodes. Notice that both nodes are using the label-and join strategy, even though one node has no inputs and the other only has one. However, in the composed graph these nodes may have more inputs.

Next is the process definition which will be using ext.

This process definition looks very different from previous examples. It isn't even fully connected.

Some things to note:

  • The external arcs are labeled with the process definition name, instance and node name that they are intended to link to.

  • In this case, all the arcs are connecting to the same instance of ext , instance 1.

  • Both in and out external arcs may connect to any node in the target external. They are not limited to just start nodes, for example.

When the graph is loaded, the composed version will look as follows:

Graph Composition Example Two

The previous example referenced only a single instance. Here is the example using two instances 'ext.

When it is loaded, the composed graph looks like:

As you can see, we now have two copies of ext embedded in the process definition. One copy will be made for each unique instance referenced. A process definition can have references to any number of different external definitions and each external process definition can be imported any number of times.

Nested Processes Example

The above example could not be implemented with nested processes because a nested process must be represented by a single node in the parent process. So, here is a similar, but simpler example using nested processes.

Nodes S and T both refer to the nested process named nested . Note that nested is almost the same as ext , except that the first node is a start node. This is because nested will be executed as a separate process. If it didn't have a start node, it would not execute.

When S and T execute, each will spawn a separate process. When S is executed, it will have an incomplete node token t . As part of execution it will start a new nested process P which have have the token t as a parent. When P completes, it will check if it has a parent token, and finding that it does, will complete t . This will allow execution to continue in the original process.