[rules-users] Runtime addition of rules to a kbase

Justin King justin.matthew.king at gmail.com
Wed Sep 9 00:18:25 EDT 2009


Hi,

We have a project where we are attempting to add new rules to an existing
knowledgebase (read from a .drl file). We add them by using strings using
the following code:

String rule = "rule \"GeneralClause-2\" " +
            "when " +
                "ObligationComplianceEvent(term == \"term2\", obligation ==
\"obligation1\", level == 2) " +
            "then " +
                "System.out.println(\"GeneralClause-2\");" +
                "contract1.setState(\"Hello\");" +
            "end";

 Resource ruleResource = ResourceFactory.newReaderResource((Reader) new
StringReader(rule));
 kbuilder.add(ruleResource, ResourceType.DRL);
 kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

We do not even halt the currently running session to add the new rule
(although halting and re-firing appears to make little difference). This
appears to have strange effects. Some rules (specifically those that use
'accumulate' most of the time) will stop working after inserting the new
rule at runtime, even though they are completely unrelated. The timing in
which you add the new rule also seems to have an effect (e.g. before
inserting some events, after. etc). We cant seem to come to any logical
conclusion about the strange behavior our rules seem to give us.

My question is this: Is this a valid way to use Drools? Or are we somehow
breaking something (perhaps the rete tree or something) behind the scenes by
doing this? If so, is there a correct way?

Any input at all would be greatly appreciated as this is very critical to
our project.

Cheers,

Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090909/3ec9a5d9/attachment.html 


More information about the rules-users mailing list