4 Replies Latest reply on Jan 23, 2012 5:43 AM by jbpm_new

    ProcessEventListener methods executed twice




      I am playing with ProcessEventListener implementation and I have the feeling that methods are executed twice for the same Node.

      For now, I am just tracing a message when a method is triggered and I get it twice in the log file !

      My goal is to fire rules when I reach a Rule Task Node because I have issues if I fireAllRules at process startup...

      What's wrong ?


      Here's how I initialize the ksession


      ksession =  JPAKnowledgeService.newStatefulKnowledgeSession(base, kconfig,

      JPAWorkingMemoryDbLogger wkfLogger = new JPAWorkingMemoryDbLogger(ksession);


      ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new CommandBasedWSHumanTaskHandler(ksession));


      ksession.addEventListener(new JbpmProcessEventListener(ksession));


      here's the code of my EventListener:


      import org.drools.event.process.ProcessCompletedEvent;

      import org.drools.event.process.ProcessEventListener;

      import org.drools.event.process.ProcessNodeLeftEvent;

      import org.drools.event.process.ProcessNodeTriggeredEvent;

      import org.drools.event.process.ProcessStartedEvent;

      import org.drools.event.process.ProcessVariableChangedEvent;

      import org.drools.runtime.StatefulKnowledgeSession;

      import org.jbpm.workflow.core.node.RuleSetNode;

      import org.slf4j.Logger;

      import org.slf4j.LoggerFactory;


      public class JbpmProcessEventListener implements ProcessEventListener {


                      private StatefulKnowledgeSession session;

                      private static Logger logger = LoggerFactory.getLogger(JbpmProcessEventListener.class);


                      public JbpmProcessEventListener(StatefulKnowledgeSession ksession){

                                     session = ksession;



                      public void beforeVariableChanged(ProcessVariableChangedEvent event) {



                      public void beforeProcessStarted(ProcessStartedEvent event) {



                      public void beforeProcessCompleted(ProcessCompletedEvent event) {



                      public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {


                          logger.debug("beforeNodeTriggered: " + event.getNodeInstance().getNode().getClass());

                          logger.debug("beforeNodeTriggered: " + event.getNodeInstance().getNode().getName());

                          if (event.getNodeInstance().getNode() instanceof RuleSetNode) {





                      public void beforeNodeLeft(ProcessNodeLeftEvent event) {



                      public void afterVariableChanged(ProcessVariableChangedEvent event) {



                      public void afterProcessStarted(ProcessStartedEvent event) {



                      public void afterProcessCompleted(ProcessCompletedEvent event) {



                      public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {



                      public void afterNodeLeft(ProcessNodeLeftEvent event) {





        • 1. Re: ProcessEventListener methods executed twice


          I imagine that you are trying to fire all the rules after a ruleflow set node, but that's not recommended. What are you trying to achieve with that?

          What is your business scenario? Cheers

          • 2. Re: ProcessEventListener methods executed twice



            we are having trouble with Rule nodes. It seems that if we design BPMN process embedding a Rule Task, the rules listed in the referenced ruleflow group are never fired (even rulesl with always true condition)

            So I imagine that we need to "manually" fireAllRules but the processInstance never hangs in the Rule node if we startProcess and then fireAllRules just after...


            Knowing that, I am trying to find a workaround and launch the fireAllRules method each time a process instance reaches a Rule node. This is why I focused on ProcessEventListener implementation but I am facing new problems exposed in the first post.


            What is the best practice concerning RuleTasks ?


            My environment is Tomcat 6/JBPM 5.1 Final/Oracle 11g/Bitronix TM



            • 3. Re: ProcessEventListener methods executed twice

              After some further test, I manage to make the solution based on AgendaEventListener work but ONLY WHEN A NEW SESSION is created.

              In my application, i query the sessiontable at startup and I load the existing StatefulSession if I find an entry in this table.

              If no previous session was created, I created one (see below)


                          // check if there is an existing session in the DB

                          // if a session is found, then restore it else create a new one

                          int existingSessionId = findLastKnowledgeSessionID();

                          if (existingSessionId != -1) {

                              ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(existingSessionId, base, kconfig, env);

                          } else {

                                 ksession =  JPAKnowledgeService.newStatefulKnowledgeSession(base, kconfig, env);



              In case where I load the previous session then the Agenda Event Listener is not triggered...

              When I look in the nodeinstancelog table, I can see that the engine enters the Rule node (type = 0) but it hangs.


              Any idea ?

              • 4. Re: ProcessEventListener methods executed twice

                Hi Sebatian,


                I am also facing the same problem when i load a existing session and try launching the process with Agenda Listener the Rules are not getting fired. Do you have any solution. ? Thanks