Hello!

I have following rules file:

import java.util.List;

global List outErrorCodes;
global Boolean condition1;
global Boolean condition2;
global Boolean condition3;

rule "01"
        when
                eval( condition3 == false);             
        then
                outErrorCodes.add("ERROR_CODE1");
                System.out.println("01");
end

rule "02"
        when
                eval((condition1 == true) && (condition2 == true));
        then
                outErrorCodes.add("ERROR_CODE2");
                System.out.println("02");
end


When I evaluate this file repeatedly, it is evaluated correctly only
the first time.

I don't understand why it happens, because I always create a new
knowledge base for every execution (I don't re-use sessions).

Here is the code:

final KnowledgeBase knowledgeBase2 = createKnowledgeBase(getRuleFileNames());
final StatefulKnowledgeSession session2 =
knowledgeBase2.newStatefulKnowledgeSession();

...

Then, I set condition1, condition2 and condition3 with calls like this:

session2.setGlobal(curName, curValue);

curValue is Boolean.TRUE or Boolean.FALSE.

Then, I insert the value of the output variable:

session2.setGlobal("outErrorCodes",
                new LinkedList<String>());

Then, I invoke these methods:

session2.fireAllRules();
...
session2.dispose();

After fireAllRules, outErrorCodes is always empty (apart from the
first run), even in cases, where rule "01" should apply.

What am I doing wrong?

Thanks in advance

Dmitri
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to