yglodt
yglodt

Reputation: 14551

Example use of Drools fluent API to change rules on the fly

I came along the Drools fluent API which, as far as I understand, allows Rules to be added/edited/deleted from working memory at runtime.

The documentation mentions it here without going into details:

http://docs.jboss.org/drools/release/5.2.0.Final/droolsjbpm-introduction-docs/html/ch02.html#d0e124

Does anyone have example code on how to use this API?

I am specially interested in adding/changing/deleting rules at runtime.

Upvotes: 3

Views: 3306

Answers (1)

josh-cain
josh-cain

Reputation: 5216

I think that section was speaking more to the fact that they have a programmatic way to create rules. I was under the impression that the "fluent" part referred the their use of the builder pattern that allowed you to string methods together in the same way a rule would appear.

But yes, you are able to change/edit/delete rules dynamically for a particular KnowledgeBase. An example can be found in their sample integration tests, or consult the KnowledgeBase docs - particularly the addKnowledgePackages(Collection<KnowledgePackage> kpackages) and removeRule(String packageName, String ruleName) functions.

I suppose you can combine the DescrFactory with the rule addition/creation. I'm not really able to find a public API anywhere that will help you with how to use it, and it's in the drools-compiler dependency, so I'm not certain that there will be one published as much of that artifact is meant for drools internal use.

There is also another related S/O discussion about this here.

Upvotes: 1

Related Questions