cancel
Showing results for 
Search instead for 
Did you mean: 

How to get listener?

afenske
Champ in-the-making
Champ in-the-making
Hello.

I've got a problem. I have a business process and a client, which is written in Eclipse RCP. My client interacts with the business process through Activiti API.

How can I determine the moment when there is a new task in the queue? In other words, I want to add a listener on the client to catch moments when new task is added to the queue.

Best regards,
Anton Fenske.
16 REPLIES 16

pkromolowski
Champ in-the-making
Champ in-the-making
If using Activiti version prior to 5.12 you can register a BpmnParseListener like this:

configuration.getPreParseListeners().add(new MyBPMNPreParseListener());
before you call configuration.buildProcessEngine() method.

You can then register task listeners within your MyBPMNPreParseListener:


public void parseUserTask(Element elem, ScopeImpl scope, ActivityImpl activity)
{
      TaskDefinition definition = ((UserTaskActivityBehavior) activity.getActivityBehavior()).
      definition.addTaskListener(TaskListener.EVENTNAME_CREATE, new MyTaskListener()); // MyTaskListener implements org.activiti.engine.delegate.TaskListener
      …
}

In 5.12+ versions you should use the new BpmnParseHandler approach, wich basically gives you the same functionality (hovewever, you can't  access the XML structure of a task - this will propably be available in 5.13 version).

Best regards,

afenske
Champ in-the-making
Champ in-the-making
Thank you, Przemek Kromolowski.

afenske
Champ in-the-making
Champ in-the-making
I encountered a problem. Suggested approach works well just when you do some actions within the same application where you created a listener. If you try to complete some action from another app, for example, activiti explorer, listener won't catch that moment.

Best regards,
Anton Fenske.

jbarrez
Star Contributor
Star Contributor
No, that is indeed correct. If you want to use it in Explorer, the process engine config must be updated + the relevant classes must be put on the classpath.

afenske
Champ in-the-making
Champ in-the-making
I don't understand.

Let me clarify the task.

I have the next problem. Imagine that you have an application A and another application B. They work with the same instance of some business process.

In A I created a listener and it works well when I do some steps of business process from A. But when I do some steps from B, A's listener  doesn't catch any actions which have done from B.

Is it possible to let A's listener to react on actions which have happened in B?

Best regards,
Anton Fenske.

jbarrez
Star Contributor
Star Contributor
> Is it possible to let A's listener to react on actions which have happened in B?

Clarification was not needed, I did understand what you mean. And my response stays the same: if you want the listeners to fire on both A and B you need to configure both A and B to have the same configuration: same process engine config + same listener classes.

afenske
Champ in-the-making
Champ in-the-making
I tried to do it. I launched two the same apps, but I recognized that listener worked just from the process which I had used before event was happened and listener in another app didn't react to that event.

jbarrez
Star Contributor
Star Contributor
I don't really get what you try to do. I read your original question and it seems to me you just need to fire an event on the task creation to some queue (outside of Activiti) that then acts upon that. And the way to do it, is exactly how the first response (from Przemek) describes it.

> Is it possible to let A's listener to react on actions which have happened in B?

Can you clarify that with some BPMN? Cause I really don't get what exactly you try to do.

afenske
Champ in-the-making
Champ in-the-making
Ok. We have two user tasks. Kermit uses the first one to select a user who will complete the second task. The problem is to fire some event, which will be signal about a new task creation, from  those client who will be selected by kermit in the first task.
Could you give an example of a necessary task handler and an activiti-config.xml file?
Bpmn file is in the attacnment.