Property reactivity does not work when Java methods are used in constraints of the rule.
Issue
I gave property a
of the fact object, which is not used in action of the rule, as a parameter in constraints in the rule.
Rule:
rule "rule-1"
when
$fact: Fact(convertToClassifiedString(a) == "LARGE")
then
System.out.println("***** Action of rule-1");
modify($fact) { setResult("OK") };
end
Fact class:
public class Fact {
private int a;
private String result;
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
The code of the Java method used in constraints of the rule above:
public class CommonUtil {
public static String convertToClassifiedString(int num) {
if (num < 1000) {
return "SMALL";
}
return "LARGE";
}
}
I executed the rule like below,
...
KieSession kSession = kContainer.newKieSession();
Fact fact = new Fact();
fact.setA(99999);
fact.setResult("NG");
kSession.insert(fact);
kSession.fireAllRules();
...
and expected that property reactivity did work and the rule was evaluated only once, but the rule was unexpectedly evaluated infinitely.
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
***** Action of rule-1
...
Environment
- Red Hat Decision Manager (RHDM)
- 7.4.0 - 7.9.1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.