开发者

In Drools Rules, how to use two different ArrayList objects,obj1 is used in rule 1 and obj2 used in rule2?

开发者 https://www.devze.com 2022-12-09 02:04 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消