I am doing ksession.insert(list) and after that I have to fire rule 1 in the drl file, then ksession.insert(list) and fire rule 2 in the drl.
Could someone tell me how to achieve this. I read about agenda filters a开发者_StackOverflownd facthandles but do not really know how to get this to work
Below is some code:
ArrayList list = new ArrayList(); list.add(product1); list.add(product2); list.add(product3);
ksession.insert(list);
ksession.fireAllRules("fire rule 1 in drl");//remove list?
ArrayList list2 = new ArrayList(); list2.add(str1); list2.add(str2); list2.add(str3);
ksession.insert(list2); ksession.fireAllRules("fire rule 2 in drl");
I think there is a better workaround...you can control pattern matching..
Here is a simple and quick way
arrayList1.add("Rule 1");//if you can afford this without generics
arrayList1.add(...);//everything else you want to add
arrayList2.add("Rule 2");
arrayList2.add(..);//rest...
..
ksession.insert(..) ;//insert everything one by one
..
in your drl and inside Rule 1
..when you want Rule 1 to work with arraylist1, have this matching first in the lhs
$al:ArrayList(this contains "Rule 1")
That is all..
You don't directly control what rules fire - the constraints on the rules determine this. Filters can only help if you are stopping rules from firing.
精彩评论