This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Extending BPMN to Handle Events via Business Processes

The Activiti API provides extension points that can be used as custom implementations that you can trigger where necessary. Task listener is one such extension point.

A task listener can be used when you need to trigger a custom implementation upon the occurrence of a particular task.

To create a task listener you need to write a java class that implements the org.activiti.engine.delegate.TaskListener interface. In the java class, you need to add the listener logic inside the notify method as follows:

package org.wso2.testbpmn;

import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

public class FirstTaskListener implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
   	 delegateTask.setDescription("First Task Listener");

    }
}

Note

For example, if you want to log the time that a task starts, you can use a logger inside the task listener to print the start time of a task. 


Once you write the Java class, you can build the project containing the class, add the built .jar file inside the <EI_HOME>/lib directory, and restart the server.

In the process definition you can point to the created class using an eventListener as follows:

<userTask id="myTask" name="My Task" >
  <extensionElements>
    <activiti:taskListener event="create" class="org.wso2.testbpmn.FirstTaskListener"/>
  </extensionElements>
</userTask>

If you look at the process definition given above, you will see that there is a parameter named event. You can use the event parameter to define the event that should trigger the task listener class.

For more information, see Task Listener in the Activiti User Guide.

For information on other event listeners that allow you to handle various events from business processes you create, see Event handlers in the Activiti User Guide.