[rules-users] Drools all lhs execute before all the rhs, i want to run sequentially

Saurabh Pandey meet.saurabhpandey at gmail.com
Mon Sep 26 06:22:11 EDT 2011


these are my rules:
rule "Rule 03"
  salience 10
    when
        $info : RuleRunner()
        eval(RuleRunner.check())
        eval(RuleRunner.setIt())
    then
        System.out.println("********3**********");
        $info.printResult(1);
end

rule "Rule 04"
  salience 8
    when
        $info : RuleRunner()
        eval(RuleRunner.check())
    then
        System.out.println("********4**********");
        $info.printResult(2);
end

these are my java methods:
static boolean cvar = true; 
public void printResult(int i){
    System.out.println(i);
  }
  public static boolean check(){
    System.out.println("********check**********");
    return cvar;
  }
  public static boolean setIt(){
    cvar = false;
    return true;
  }

this is how i am invoking the rules:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      kbuilder.add(ResourceFactory.newFileResource("rule03.drl"),
                               ResourceType.DRL );
      
      if ( kbuilder.hasErrors() ) {
          System.err.println( kbuilder.getErrors().toString() );
      }       
      KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
      kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() ); 
      StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
      ksession.execute(new RuleRunner());


This is the output:
********check**********
********3**********
1
********4**********
2

Why is check printing only once though its called 2 times in 2 rules, and
when cvar is false then also 2nd rule's then part is executing?
Is it that static methods of same name are called once and there result is
stored and used in all rules??


--
View this message in context: http://drools.46999.n3.nabble.com/Drools-all-lhs-execute-before-all-the-rhs-i-want-to-run-sequentially-tp3368215p3368864.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list