Introducing execution and task listeners

Listeners are used to perform background execution. They are used to perform automatic tasks in the background, such as the autoexecution of any activity, autotransactions, and creating users. Listeners provide great hooks into process execution; they can be used for business process management and simpler things such as flexibly assigning a group of candidate users to a user task. It is used to execute external Java code. We can also perform some expressions during the occurrences of some events.

Activiti supports two types of listeners:

  • Execution listeners
  • Task listeners

Execution listeners

An execution listener is a class file implementation that can be used during the execution of a process. Let's say we want to fetch some data from an external API or implement some logic on the execution of a process; in this case, we can call it using an execution listener. It can be configured on the following:

  • The process itself
  • Activities
  • Transition

These listeners can be executed on various events, such as the following:

  • The start and end events of the process itself
  • The start and end events of the activities
  • The take event of the transition phase

Task listeners

A task listener is similar to an execution listener; the only difference is that it will execute on a task.

A task listener can be executed on the user task. We can use this listener to allocate tasks to a particular user at runtime. We can complete the task using the task listener.

A task listener can be executed on the create, assignment, and complete events of the user task.

Now let's model a process to use these listeners.

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

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