cancel
Showing results for 
Search instead for 
Did you mean: 

Listening to Lifecycle events (start, end, transitions)

jjfutt
Champ in-the-making
Champ in-the-making
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
——————————————

Hello:

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">
        <list>
                <bean class="org.activiti.cdi.impl.event.CdiEventSupportBpmnParseListener" />
        </list>
</property>
and the @Observer annotation

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

p4w3l
Champ in-the-making
Champ in-the-making
Just have exciting weekend with CDI so can share experience, strenght and hope:

No need for EJB. No need to configure anything ( except activiti-cdi ). Say you tested activiti-cdi working for you. As a minimal test I would say that the below works for you instead of:
   processEngine = ProcessEngines.getDefaultProcessEngine();
   identityService = processEngine.getIdentityService();
you use:
private @Inject IdentityService identityService;
Then you update activiti-context.xml with what you referenced and create a POJO with method you referenced say with e content like:
log.debug( businessProcessEvent );then you see in log every stupid event of every running process

jjfutt
Champ in-the-making
Champ in-the-making
Thanks a lot for the help – I will be checking this out this weekend. Thanks again.

smcardle
Champ in-the-making
Champ in-the-making
What happened to these classes in the 5.13 release ????

There is no longer a class BpmnParseListener and no setCustomPostBPMNParseListeners(…) method on the ProcessEngineConfigurationImpl.

So in 5.13 how do I now setup the engine so that I can hook into all of the process engine events ?

Steve

frederikherema1
Star Contributor
Star Contributor
They are refactored to have a cleaner model. It's now called BPMNParseHandlers…