Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drools - Ability to define rules at runtime?

It is possible to define rules dynamically completely at runtime ? Also change the ruleset at runtime.

For example,

at time = t_1 the ruleset is { R1, R2, R3 } 
at time = t_2 the ruleset is { R1, R3, R4 } 
..... 

R1, R2 are rules that are defined at runtime.

Thanks.

like image 658
Soumya Simanta Avatar asked Feb 23 '12 22:02

Soumya Simanta


People also ask

How do you define a rule in drools?

Rule Definition − It consists of the Rule Name, the condition, and the Consequence. Drools keywords are rule, when, then, and end. In the above example, the rule names are “Hello World” and “GoodBye”. The when part is the condition in both the rules and the then part is the consequence.

How can you improve drools performance of rule execution?

Literal Restrictions using the operator '==' provide for faster execution as we can index using hashing to improve performance. One can bind variables to facts and their fields and then use them in subsequent field constraints. A bound variable is called a declaration.

What is drools rule engine used for?

Drools Rule Engine is a rule-based approach to implement an Expert system in the Drools software. The Rule engine provides Expert systems which are knowledge-based systems that help you to make decisions like what to do and how to do it. It gathers knowledge into a knowledge base that can be used for reasoning.


1 Answers

Yes, Drools is completely dynamic. You can add/remove/replaces rules at runtime. All the existing sessions are automatically updated in order to keep consistency. Check the documentation/javadoc:

http://www.jboss.org/drools/documentation

And here you can see some integration tests:

DynamicRulesTest.java

like image 55
Edson Tirelli Avatar answered Oct 09 '22 17:10

Edson Tirelli