Thanks for reply @dominikh I’m using a shared process engine so I added my listener defining a plugin implementing ProcessApplicationEventListenerPlugin
The event parse listener class override addEndEventListener and addStartEventListener, for example:
I agree with Dominik: There is no need to subclass ProcessApplicationEventListenerPlugin. Just let your process application return a custom execution listener via ProcessApplicationInterface#getExecutionListener.
It is correct that you will receive two events for every activity instance: one start and one end event. If you are only interested in one of them, then why not simply ignore one of the events like this:
public class MyListener implements ExecutionListener
{
public void notify(DelegateExecution execution)
{
if (ExecutionListener.EVENTNAME_END.equals(execution.getEvent())
{
return;
}
// do stuff
}
}
Hi @thorben I’m using a plugin to use it for all executions to catch Event for all deployed process
I’ve customized it to provide my implementation providing a custom EXECUTION_LISTENER
However catch event (Start | Take | End) is not a problem, my problem is Start triggered twice as different activityInstanceState (maybe) or other but I need to catch it once to avoid duplicated actions
The process engine has at least once execution semantics. That means, a start listener for an activity instance is guaranteed to be invoked at least once. During regular, exception-free operation, the behavior is exactly once (i.e. one invocation per activity instance). However, if the transaction in which the process instance is executed rolls back, the process engine may invoke the listener a second (or third, etc.) time. To be on the safe side, your listener implementation should either a) participate in the engine’s transaction (such that its effects are rolled back when the engine transaction rolls back) or b) be idempotent.
In addition you could implement a ProcessApplication that extends the ServletProcessApplication and returns the ExecutonListener you want like mentioned before. You could extend it in every ProcessApp you create instead of extending the ServletProcessApplication. With this approach you would not have to use your own ProcessApplicationEventListenerPlugin.