Delving into the process engine

The process engine is the heart of Activiti and is used to take advantage of the various services in Activiti. Using the ProcessEngine API, we can interact with the Activiti Engine and perform various functionalities. The ProcessEngine objects are thread-safe, so we can keep a reference for the whole server. It provides access to all the services that expose the workflow operations. An end-user application will require only one central Process Engine instance. A process engine is built through a ProcessEngineConfiguration instance and is a costly operation that should be avoided. For that purpose, it is advised that you store it in a static field or at a JNDI location (or something similar). This is a thread-safe object, so no special precautions need to be taken. The ProcessEngine class will scan for two files: one is activiti.cfg.xml and the other is activiti-context.xml.

The process engine uses Spring, so first a Spring application context is created and then the process engine is obtained from that application context. In Activiti, all services are stateless, so we can easily run Activiti on multiple nodes in a cluster environment, with each pointing to the same database. For configuring a process engine, you have to use the following API:

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine()

RuntimeService

RuntimeService deals with starting new process instances of process definitions. This service is used to retrieve and store process variables. The data available in the process variables is specific to the given process instance. In a given process instance, various types of gateways can be used. These process variables determine the path to continue the process. We can also query on process instances and executions using RuntimeService. Executions are a representation of the token concept introduced by BPMN 2.0. RuntimeService points to the process that is being executed. Lastly, RuntimeService is used whenever a process instance is waiting for an external trigger and the process needs to be continued. A process instance can have various wait states, and RuntimeService contains various operations to signal to the instance that the external trigger is received and the process instance can be continued. The API used for RuntimeService is as follows:

RuntimeService runtimeService = processEngine.getRuntimeService();

RepositoryService

RepositoryService is considered the main service for interacting with the Activiti Engine. With the help of this service, we can manage and manipulate the business process. Using this service, we can perform the following actions:

  • Deployment of a process into the repository
  • Querying the deployed process from the process engine
  • Suspending and activating the deployed process

To access RepositoryService, use the following API:

RepositoryService repositoryService = processEngine
        .getRepositoryService();
..................Content has been hidden....................

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