Have you read the expert guide?
http://docs.jboss.org/drools/release/5.2.0.Final/drools-expert-docs/html_...
- At least up to the end of chapter 4.
Why are you using static fields and methods?
You are changing the value of objects in the when condition which is really really really
bad and it's no wonder nothing is working like you are expecting.
The fact that you are using eval's is a good indication that your code is written
wrong, for simple rules you never need to use it.
Thomas
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-
bounces(a)lists.jboss.org] On Behalf Of Saurabh Pandey
Sent: 26 September 2011 11:22
To: rules-users(a)lists.jboss.org
Subject: Re: [rules-users] Drools all lhs execute before all the rhs, i want to
run sequentially
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.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************