Drools : 2 identical calls to the same knowledgeBase don't give the same result... why?

StackOverflow https://stackoverflow.com/questions/21585666

  •  07-10-2022
  •  | 
  •  

Question

I am using drools to process some user rules (the Excel way). If I call the rules with the exact same data at different time in the process, I don't get the same result. (I am using a StateLessSession)

Can someone explain me why ?

Here is more info on how I use it :
The Excel rule is something like

    | CONDITION | CONDITION | ACTIVATION-GROUP | ACTION              |
    |  myFact : MyFact                         | myFact              |
    |  isOK     | isBuild   |                  | setStatus("$param") |
     -----------------------------------------------------------------
    |  true     |           |    firstmatch    |   DONE              |
    |           |   true    |    firstmatch    |   TODO              |

Declaration with Spring :

    <drools-spring:kbase id="kbase"> 
      <drools-spring:resources>
        <drools-spring:resource type="DTABLE" source="classpath:rules/myRule.xls" >
          <drools-spring:decisiontable-conf input-type="XLS" worksheet-name="processStatus"/>
        </drools-spring:resource>
      </drools-spring:resources>
    </drools-spring:kbase>

    <drools-spring:ksession id="ksession" type="stateless" kbase="kbase" />

Use in the code :

    ksession.addEventListener(new DebugAgendaEventListener() );
    ksession.addEventListener(new DebugWorkingMemoryEventListener());
    ksession.execute(myFact);

The log (with the event listener) when I call it at first

    ==>[ActivationCreatedEvent: getActivation()=[Activation rule=process status_14, act#=0, salience=65522, tuple=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)]], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9]
    ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], getObject()=MyFact(...<identical data>..., status=NONE), getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]
    ==>[BeforeActivationFiredEvent:  getActivation()=[Activation rule=process status_14, act#=0, salience=65522, tuple=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)]], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9]
    ==>[AfterActivationFiredEvent: getActivation()=[Activation rule==process status_14, act#=0, salience=65522, tuple=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=DONE)]], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9]

As you can read, after this call, the status on myFact change to "DONE"

Now, after others calls to this rule with completely different data (about 20 calls), here is the log of the call with the same data as above :

    ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:1929411279:-1926420662:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], getObject()=MyFact(...<identical data>..., status=NONE)), getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:1929411279:-1926420662:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]

And that's it : no rule activated...

any Guess ? is it because of the "ACTIVATION-GROUP" ? if so why.. it is supposed to be stateless ?

Thanks for all your ideas !

Was it helpful?

Solution

This was a bug of the 5.5.0.Final version. If I upgrade the project to 5.6.0.FINAL, it works !

This was answered on the drools user list : http://drools.46999.n3.nabble.com/Drools-2-identical-calls-to-the-same-knowledgeBase-don-t-give-the-same-result-why-td4028038.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top