Reputation:
Drools - How can I fire multiple rules from multiple DRL files with different facts?
I'm new to Drools. I have multiple facts, each associated with different DRL files. How do I fire all the rules with different facts from a single java class or from a single session? Is it possible? Or should have different facthandles loaded into different sessions from different java classes to do this?
Upvotes: 2
Views: 10819
Reputation: 490
You can also modify the kmodule.xml to include the resources (drl or xls files) you want in the kbase property. The attribute you should set is
<kbase name = "Foo" packages="resource_package1, resource_package2,...,resource_packagen"/>
.
You can also set it to all
meaning you will include all your project's resources. By creating a session and fire it all your rules with fire and run according to their salience.
Upvotes: 2
Reputation: 6322
Add all your DRL files into a PackageBuilder and create a single KnowledgeBase with the resulting packages. Then create a session from that kbase and insert all your facts.
--Edit: adding code snippet
//Add all your drls to a single kbuilder
kbuilder.add(xxx.drl);
kbuilder.add(yyy.drl);
kbuilder.add(zzz.drl);
//Create a kbase using the generated kpackages
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
//Create a session containing all the rules you have in all your .drl files
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
//Insert all your objects
ksession.insert(new XXX());
ksession.insert(new YYY());
ksession.insert(new ZZZ());
//fire all the activated rules
ksession.fireAllRules();
Hope it helps,
Upvotes: 1