0 Replies Latest reply on Mar 7, 2014 2:48 PM by Jan Stastny

    Agenda & Process Event Listeners To Fire All Rules

    Jan Stastny Newbie

      Hi,

      I am writing to ask how this solution works. When I add event listeners like this:

                ksession.addEventListener(

                      new DefaultAgendaEventListener()

                      {

                          @Override

                          public void activationCreated(ActivationCreatedEvent event) {

                              ((StatefulKnowledgeSession) event.getKnowledgeRuntime()).fireAllRules();

                          }

                      });

              ksession.addEventListener(

      new DefaultProcessEventListener()

              {

                  @Override

                  public void afterProcessStarted(ProcessStartedEvent event) {

                      ((StatefulKnowledgeSession) event.getKnowledgeRuntime()).fireAllRules();

                  }

                 

              }

      );

      Here http://blog.athico.com/2012/07/processes-rules-or-rules-processes-3x.html is stated, that this works the same as fireUntilHalt() in seperate thread.

       

      But I have encountered, that the listener for activationCreated event fires rules activated earlier, not the rule whose activation trigerred the listener method. Or at least it seems like that. My debug log ends with ActivationCreatedEvent, no AfterActivationFiredEvent emerges.

      So basicly the agenda & process event listeners solution works like fireuntilhalt, but it is dependent upon the fact, that another activation occurs to trigger the preceding one. Am I right or should I look for an error? I came across this problem when testing rules and processes. Simple ksession.fireAllRules(); at the end of a test solves the problem (fires the last pending activation). But I am afraid that while the app is up and running there would be problem with rules, which wait a long time for its firing after activation.