cancel
Showing results for 
Search instead for 
Did you mean: 

Does engine have a hook to install an event listener?

chrisc
Champ in-the-making
Champ in-the-making
I was wondering if the Activiti engine has a hook to enable a listener to be configured whose callback method is invoked whenever a process instance progresses from one activity to the next.

Our current 'in house' workflow has hooks that allow us to configure a listener that fires off certain actions based on entering/exiting particular activities. We're looking to switch over to Activiti and need to be able to implement this functionality somehow.

I noticed that there seems to be some extensions in Activiti's BPMN file but we were hoping to plug this in at the Java level to avoid modifying all of the process definitions.
6 REPLIES 6

trademak
Star Contributor
Star Contributor
Hi,

Yes this is supported via ExecutionListeners –> http://www.activiti.org/userguide/index.html#executionListeners
If you don't want to add the execution listener in every process definition, you can write a BpmnParseListener to add it to all process definitions.
Extend the AbstractBpmnParseListener class and hook it in to the process engine configuration like this:

<property name="customPostBPMNParseListeners">
        <list>
                <bean class="org.activiti.cdi.impl.event.CdiEventSupportBpmnParseListener" />
        </list>
</property>

Note that in Activiti 5.12 the BpmnParseListener changes quite a bit. But the idea and logic remains the same.

Best regards,

chrisc
Champ in-the-making
Champ in-the-making
Thanks for the reply.

We don't use spring so I'm hoping that the 'bean' in

<bean class="org.activiti.cdi.impl.event.CdiEventSupportBpmnParseListener" />
does not imply Spring support must be present.

Does the BpmnParseListener activate when a process definition is added to the repository or each time a process instance is created for the process definition?

frederikherema1
Star Contributor
Star Contributor
No need to use spring, you can add the listener to the processEngineConfigurationImpl in code as well…

The listener is called when:

  • New process is deployed

  • Process is added to the deployment-cache (again) after engine reboot or when definition was evicted from cache.
So you can be 100% sure that EVERY process-definition that is going to be used, will pass through the listener. In that listener, you can add execution-listeners (class implementing ExecutionListener interface) to ALL flow-elements in the parsed process. This way, every process that runs, you'll be notified of every step completing…

chrisc
Champ in-the-making
Champ in-the-making
So you can be 100% sure that EVERY process-definition that is going to be used, will pass through the listener. In that listener, you can add execution-listeners (class implementing ExecutionListener interface) to ALL flow-elements in the parsed process. This way, every process that runs, you'll be notified of every step completing…
That sounds like what I need.

Thanks,
Chris

boberetezeke
Champ in-the-making
Champ in-the-making
I need to do the exact same thing (be notified of all state transitions). Would you be willing to share the code using the BpmnParseListener?

Thanks,

Steve

jbarrez
Star Contributor
Star Contributor
It's called 'BpmnParseHandler' now. Implement that interface, and attach to each SequenceFlow your own ExecutionListener which is called on state transation, shouldn't be too hard.