Chapter 2. BPM Systems' Structure

Business Process Management (BPM) systems are pieces of software created with the sole purpose of guiding your processes through the BPM cycle. They were originally monolithic systems in charge of every aspect of a process, where they had to be heavily migrated from visual representations to executable definitions. They've come a long way from there, but we usually relate them to the same old picture in our heads when a system that runs all your business processes is mentioned. Nowadays, nothing is further from the truth.

Modern BPM Systems are not monolithic environments; they're coordination agents. If a task is finished, they will know what to do next. If a decision needs to be made regarding the next step, they manage it. If a group of tasks can be concurrent, they turn them into parallel tasks. If a process's execution is efficient, they will perform the processing 0.1 percent of the time in the process engine and 99.9 percent of the time on tasks in external systems. This is because they will have no heavy executions within, only derivations to other systems. Also, they will be able to do this from nothing but a specific diagram for each process and specific connectors to external components.

In order to empower us to do so, they need to provide us with a structure and a set of tools that we'll start defining to understand how BPM systems' internal mechanisms work, and specifically, how jBPM6 implements these tools.

Components of a BPMS

All big systems become manageable when we divide their complexities into smaller pieces, which makes them easier to understand and implement. BPM systems apply this by dividing each function in a different module and interconnecting them within a special structure that (in the case of jBPM6) looks something like the following figure:

Components of a BPMS

BPMS' internal structure

Each component in the preceding figure resolves one particular function inside the BPMS architecture, and we'll see a detailed explanation on each one of them.

The execution node

The execution node, as seen from a black box perspective, is the component that receives the process definitions (a description of each step that must be followed; from here on, we'll just refer to them as processes). Then, it executes all the necessary steps in the established way, keeping track of each step, variable, and decision that has to be taken in each process's execution (we'll start calling these process instances).

The execution node along with its modules are shown in the following figure:

The execution node

The execution node is composed of a set of low-level modules: the semantic module and the process engine.

The semantic module

The semantic module is in charge of defining each of the specific language semantics, that is, what each word means and how it will be translated to the internal structures that the process engine can execute. It consists of a series of parsers to understand different languages; of these, we'll concentrate on BPMN2 in Chapter 3, Using BPMN 2.0 to Model Business Scenarios.

It is flexible enough to allow you to extend and support multiple languages; it also allows the user to change the way already defined languages are to be interpreted for special use cases. It is a common component of most of the BPMSes out there, and in jBPM6, it allows you to add the extensions of the process interpretations to the module. This is so that you can add your own language parsers, and define your very own text-based process definition language or extend existing ones.

The process engine

The process engine is the module that is in charge of the actual execution of our business processes. It creates new process instances and keeps track of their state and their internal steps. Its job is to expose methods to inject process definitions and to create, start, and continue our process instances.

Understanding how the process engine works internally is a very important task for the people involved in BPM's stage 4, that is, runtime. This is where different configurations can be used to improve performance, integrate with other systems, provide fault tolerance, clustering, and many other functionalities.

The process engine

Process Engine structure

In the case of jBPM6, process definitions and process instances have similar structures but completely different objectives. Process definitions only show the steps it should follow and the internal structures of the process, keeping track of all the parameters it should have. Process instances, on the other hand, should carry all of the information of each process's execution, and have a strategy for handling each step of the process and keep track of all its actual internal values.

Process definition structures

These structures are static representations of our business processes. In Chapter 3, Using BPMN 2.0 to Model Business Scenarios, we will see how these representations can be written by technical people and different domain experts in detail; we do this using an XML standard called BPMN 2.0 for process definition and graphical representation.

However, from the process engine's internal perspective, these representations are far from the actual process structure that the engine is prepared to handle. In order for the engine to get those structures generated, it requires the previously described semantic module to transform those representations into the required object structure.

The following figure shows how this parsing process happens as well as the resultant structure:

Process definition structures

Using a process modeler, business analysts can draw business processes by dragging-and-dropping different activities from the modeler palette. For jBPM6, there is a web-based modeler designed to draw Scalable Vector Graphics (SVG) files; this is a type of image file that has the particularity of storing the image information using XML text, which is later transformed into valid BPMN2 files.

Note that both BPMN2 and jBPM6 are not tied up together. On one hand, the BPMN2 standard can be used by other process engine provides such as Activiti or Oracle BPM Suite. Also, because of the semantic module, jBPM6 could easily work with other parsers to virtually translate any form of textual representation of a process to its internal structures.

In the internal structures, we have a root component (called Process in our case, which is finally implemented in a class called RuleFlowProcess) that will contain all the steps that are represented inside the process definition.

From the jBPM6 perspective, you can manually create these structures using nothing but the objects provided by the engine. Inside the jBPM6-Quickstart project, you will find a code snippet doing exactly this in the createProcessDefinition() method of the ProgrammedProcessExecutionTest class:

//Process Definition
RuleFlowProcess process = new RuleFlowProcess();
process.setId("myProgramaticProcess");

//Start Task
StartNode startTask = new StartNode();
startTask.setId(1);

//Script Task
ActionNode scriptTask = new ActionNode();
scriptTask.setId(2);
DroolsAction action = new DroolsAction();
action.setMetaData("Action", new Action() {
    @Override
    public void execute(ProcessContext context) throws Exception {
        System.out.println("Executing the Action!!");
    }
});
scriptTask.setAction(action);

//End Task
EndNode endTask = new EndNode();
endTask.setId(3);

//Adding the connections to the nodes and the nodes to the processes
new ConnectionImpl(startTask, "DROOLS_DEFAULT", 
        scriptTask, "DROOLS_DEFAULT");
new ConnectionImpl(scriptTask, "DROOLS_DEFAULT", 
        endTask, "DROOLS_DEFAULT");
process.addNode(startTask);
process.addNode(scriptTask);
process.addNode(endTask);

Using this code, we can manually create the object structures to represent the process shown in the following figure:

Process definition structures

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

This process contains three components: a start node, a script node, and an end node. In this case, this simple process is in charge of executing a simple action. The start and end tasks simply specify a sequence.

Even if this is a correct way to create a process definition, it is not the recommended one (unless you're making a low-level functionality test). Real-world, complex processes are better off being designed in a process modeler, with visual tools, and exported to standard representations such as BPMN 2.0. The output of both the cases is the same; a process object that will be understandable by the jBPM6 runtime. While we analyze how the process instance structures are created and how they are executed, this will do.

Process instance structures

Process instances represent the running processes and all the information being handled by them. Every time you want to start a process execution, the engine will create a process instance. Each particular instance will keep track of all the activities that are being created by its execution.

In jBPM6, the structure is very similar to that of the process definitions, with one root structure (the ProcessInstance object) in charge of keeping all the information and NodeInstance objects to keep track of live nodes. The following code shows a simplification of the methods of the ProcessInstance implementation:

public class RuleFlowProcessInstance implements ProcessInstance {
  public RuleFlowProcess getRuleFlowProcess() { ... }
  public long getId() { ... }
  public void start() { ... }
  public int getState() { ... }
  public void setVariable(String name, Object value) { ... }
  public Collection<NodeInstance> getNodeInstances() { ... }
  public Object getVariable(String name) { ... }
}

After its creation, the engine calls the start() method of ProcessInstance. This method seeks StartNode of the process and triggers it. Depending on the execution of the path and how different nodes connect between each other, other nodes will get triggered until they reach a safe state where the execution of the process is completed or awaiting external data.

You can access the internal parameters that the process instance has through the getVariable and setVariable methods. They provide local information from the particular process instance scope.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset