-
1. Re: Drools - Dynamic rule-files or url specification
njrich28 Sep 4, 2010 6:43 PM (in response to mdesignz)There are a couple of things to solve here - there first is how to dynamically assign the filename/url in the built-in components, the second is to decide whether to use the file-based rulebase or Guvnor to resolve your rulebase.
To solve the first issue create a new component:
@Name("dynamicRuleFiles") @Scope(ScopeType.APPLICATION) public class DynamicRuleFiles { private String[] ruleFiles; /** * Call this method to clear the application-scoped rule base component * from the application context. The next time it is requested, Seam will * automatically reload it using the new value for the rule files. */ public void reloadRuleBase() { Contexts.getApplicationContext().remove("ingPOCRules"); } public String[] getRuleFiles() { return ruleFiles; } public void setRuleFiles(String[] ruleFiles) { this.ruleFiles = ruleFiles; } }
next configure the built-in RuleBase component to use the dynamic value in this component
<drools:rule-base name="ingPOCRules" rule-files="#{dynamicRuleFiles.ruleFiles}"/>
To use the component in your app to change the rule files dynamically can do something like:
@In private DynamicRuleFiles dynamicRuleFiles; public void changeFiles() { dynamicRuleFiles.setRuleFiles({"/WEB-INF/different-file.drl"}); dynamicRuleFiles.reloadRuleBase(); }
You can use a similar technique to dynamically set the url on the rule agent.
Solving the second issue of how to decide which type of rule base to use kind of depends on how you are using the rulebase. How are you using it exactly?
-
2. Re: Drools - Dynamic rule-files or url specification
mdesignz Sep 4, 2010 8:13 PM (in response to mdesignz)Thank you for the reply. It is very helpful. I'd prefer using Guvnor. However, there was an issue in 5.0 that didn't handle a rule refresh properly. A server restart was required when a rule was changed. I read somewhere this was fixed in the latest version, but have not tried it. Thanks again for your reply!