-->

Monday 30 June 2008

A simple process definition example

NGinn is under development and almost every part of it keeps changing. It also happens to the language itself. Currently NGinn is based on XML description of process structure and there is no graphical representation. It is important to have graphical design tools for process graphs, but I think it is too early to develop them -XML form is enough for now. Graphical NGinn representation will be developed after the language becomes stable enough.

OK, so how does NGinn process definition look like?

First of all, NGinn process is a Petri-net, so the definition contains the net structure. Petri net consists of places, transitions and connections between them. Then process-specific extensions are added, such as specialized tasks and process data specification. Let's see an example:

1. Here's a simple process

2. And here's the XML description of this process:



<?xml version="1.0" encoding="utf-8"?>
<process version="2" name="TimerTask" xmlns="http://www.nginn.org/WorkflowDefinition.1_0.xsd">
<places>
<place id="start" type="StartPlace"></place>
<place id="end" type="EndPlace"></place>
</places>
<tasks>
<task id="init" type="EmptyTask" splitType="AND">
</task>
<task id="timeout" type="TimerTask" joinType="AND" splitType="AND">
<timerTask>
<delayTime>00:01:00</delayTime>
</timerTask>
</task>
<task id="timeout2" type="TimerTask" joinType="AND" splitType="AND">
<timerTask>
<delayTime>00:01:00</delayTime>
</timerTask>
</task>
</tasks>

<flows>
<flow from="start" to="init" />
<flow from="init" to="timeout" />
<flow from="init" to="timeout2" />
<flow from="timeout" to="end" />
<flow from="timeout2" to="end" />
</flows>
<processDataTypes>
</processDataTypes>
<variables>
<variable name="delayAmount" type="string" required="true" dir="In" />
</variables>
</process>


OK, so let's see what we have here:
  • the main process element is the root of process definition file. Contains process identification attributes, such as name and version number
  • The 'places' section - contains list of places in the process definition. Here we have only starting and ending place (note the 'type' attribute identifying the start and end place)
  • The 'tasks' section - contains a list of tasks, that is transitions in Petri-net terminology. Tasks can be of several types, offering different functionalities. Here we used empty task (init), which does nothing but is present for synchronization purposes, and two timer tasks which wait for specified period of time. Each type of task is defined in 'task' element, however internal structure of 'task' element depends on the task type.
    Note the 'joinType' and 'splitType' attributes of tasks. These are very important attributes - they specify the synchronization logic between tasks. There are three types of split and join: AND, OR and XOR, we will discuss each type in later posts.
  • The 'flows' section, connecting places and tasks. Each 'flow' has its starting node (from) and ending node (to).

That's the Petri-net structure description. However, there is an inconsistency with Petri-net specification. Note that the 'init' task is connected directly to 'timeout1' and 'timeout2' tasks, without intermediate places. Petri nets forbid that - there can be flow only from place to a transition and from transition to a place, place-place and transition-transition connections are not allowed. In NGinn two tasks can be connected. In such case and implicit place is inserted between these two tasks. In our example, there would be an implicit place between init and timeout1 and second implicit place between init and timeout2. The purpose of such construct is only to simplify process definition, however in some cases we will need to specify places explicitly.

There are two more sections in the process definition XML:

  • 'processDataTypes' section - contains definitions of data structures used for representing process data. Here it is empty, and data structures will be discussed in later posts
  • 'variables' section, containing definitions of process variables. Process variables are like arguments of a function - there can be input variables (input arguments), output variables (return values) and local variables. Also, input-output variables are possible. Here we have only one  variable - 'delayAmount' string.

OK, done with process definition. But what does this process do?

  1. Init task is executed. It does nothing, but then the execution is split in two parallel flows(remember the 'AND' split). So the 'init' task consumes one token from the 'start' place and produces two tokens in the implicit places for timeout1 and timeout2 tasks.
  2. Timeout1 and Timeout2 execute simultaneously - each of them waits exactly 1 minute and then completes, consuming token from the implicit place between 'init' and itself and producing token in the 'end' place. 
  3. There are no tokens except for the 'end' place, so the process is completed.

No comments: