AnsweredAssumed Answered

Listening to Lifecycle events (start, end, transitions)

Question asked by jjfutt on Mar 22, 2012
Latest reply on Aug 5, 2013 by frederikheremans1
update: 3/22/2012

After going through the CDI section of documentation and the examples in ActivitiInAction book, I now understand that part of my question was just wrong and was a consequence of my bad understanding of differences between CDI (JSR299) vs Spring. I am going to ask my new question in a separate thread since it's going to be a completely different set of questions.

Original Question below


We'd like to implement generic listeners/observers that do 'stuff' when process lifecycle events occur (such as process started, process ended, transition taken etc). It appears that we can do it in two ways:

(i) By explicitly defining listeners on the Process Definition (requires the process authors to explicitly code listeners)
(ii) "Hooking up to Activiti-CDI BUS"

Needlessly to say, (i) is not our preferred approach because it requires the process authors to explicitly configure the listeners, which is both error-prone, and tantamount to hardcoding. We are looking for an AOP type of approach where we can configure and implement lifecycle event listeners without the process authors doing anything about it.

The 'Activiti CDI' documentation section kind of describes such an approach. We were able to successfully configure the Spring configurations to start and interact with the processes. However, taking the next step of configuring and implementing event listeners is not very clear.

I'd be grateful if someone could shed some light on the following questions:

(i) Does using the CDI-EventBus listener approach require the use of EJBs? There are some comments around the use of EJBs in this section which makes it confusing.

(ii) Beyond using the ProcessEngine bean, which we have successfully configured, we just want to respond to Lifecycle events. The documentation briefly hints at adding a property to configuration (see below in the code section) and using @Observer notation on listener methods. Is there more specific information available on this? Where in the Bean configurations this property needs to be specified? Is it for the engine, for the runtime, for a single process? If it needs to be specific for a single process, does it mean we have to declare each process as a Bean? Do we have to find an implementation of JSR299 to use the @Observer annotation since activiti-cdi module alone is unable to resolve this annotation? Can I put the @Observer annotation on any ordinary POJO or does that need to be configured in a specific way too?

I'd appreciate if any of you can share information or examples to clarify this. Also, if there is another way to react to lifecycle events (without explicitly coding them in processes), I'd love to know about that too.

<property name="customPostBPMNParseListeners">
                <bean class="org.activiti.cdi.impl.event.CdiEventSupportBpmnParseListener" />
and the @Observer annotation

public void onProcessEvent(@Observes BusinessProcessEvent businessProcessEvent) {
        // handle event