Time for action – running the Activiti Engine

So far, we have created a process using the Designer and Modeler and deployed it using the Activiti Explorer. We have seen that configuration can be done using activiti-standalone-context.xml. Similar configurations can also be done using the ProcessEngine class. In this section, we will take a look at this and in Chapter 6, The Activiti ProcessEngine API, we will see more details regarding various APIs.

We can create the Activiti Process Engine using the org.activiti.engine.ProcessEngines class. To configure the Process Engine, we have to create the activiti.cfg.xml file.

Let's see how we can run the Activiti Engine.

Firstly, we can create an instance of ProcessEngine as follows:

ProcessEngineprocessEngine = ProcessEngines.getDefaultProcessEngine()

This instance will search for the activiti.cfg.xml file and create a Process Engine based on the configuration defined in that file.

We can configure the file using the following configuration properties:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">

<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />

<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />

<property name="mailServerHost" value="mail.demo.com" />
<property name="mailServerPort" value="25" />
</bean>

</beans>

This configuration is done for the Spring environment.

It is not mandatory to create the configuration of ProcessEngine in the Spring environment. We can also create an object of ProcessEngineConfiguration programmatically in the configuration file. We can also use a different bean ID.

Using the following code, we can create ProcessEngine:

ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource);
ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource, String beanName);
ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream);
ProcessEngineConfiguration.createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);

All the ProcessEngineConfiguration.createXXX() methods return a ProcessEngineConfiguration instance that can be used further.

ProcessEngine is created after calling the buildProcessEngine() method as follows:

ProcessEngineprocessEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
  .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
  .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
  .setJobExecutorActivate(true)
  .buildProcessEngine();

What just happened?

We learned about the class that is used to create the Process Engine. Now we know which properties are required in the activiti.cfg.xml file for the Process Engine. We learned to create the Activiti Process Engine without using the Spring environment.

Have a go hero

Now that you've gone through the chapter, feel free to attempt the following activities:

  • Configuring Activiti with the Oracle database
  • Adding the e-mail task for order confirmation in the laptop order process that we saw in Chapter 2, Modeling Using the Activiti Modeler

Pop quiz – the Activiti Process Engine

Q1. Which bean ID is used for configuring the mail server's properties?

  1. transactionManager
  2. datasource
  3. ProcessEngineConfiguration
  4. processEngine

Q2. Which file is used to configure the production database in the Spring environment?

  1. db.properties
  2. activiti-standalone-context.xml
  3. web.xml
  4. rebel.xm

Q3. Which layer is optional in Activiti?

  1. The Activiti Spring layer
  2. The Activiti Engine layer
  3. The PVM layer
  4. The Activiti components
..................Content has been hidden....................

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