Drools: How to update only specific rules?
We use Drools with an interface where users can update / edit rules. Those rules are then stored (and versioned) in a database. Afterwards the rules are fetched again from database and added one by one in the following way:
for (Rule rule ...) {
knowledgeBuilder.add(ResourceFactory.newByteArrayReso开发者_开发百科urce(rule.getRuleContent().getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) { throw Error... }
}
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());
We have several hundred rules and a rule checking throughput of also several hundred rules/second (on 2 nodes). With the number of rules increasing this KnowledgeBase update takes longer and longer (compiling all those rules) and during this time no rule can be checked. So the system stands still from the user point of view.
There seems to exist no possibility to refresh a rule selectively - is this correct? If yes, then how is the best way to handle such a situation? The first idea that comes to mind is using two KnowledgeBases in parallel...
The KnowledgeBase API has methods to remove rules/packages and also to add packages. So to accomplish this you could remove the rule you want to update and then insert the updated version into the knowledge base. If you have any statefull sessions who's dispose() method has not been called, than the changes to the KnowledgeBase should get pushed out to them as well.
精彩评论