![]() |
![]() |
Rule Engine |
|
|
|
|
|
OpenRulesEngine and Rules Execution Logic |
|
|
|
|
OpenRules® include a rule engine known as "OpenRulesEngine" that is used to execute different rule sets and methods specified in Excel files using application-specific business objects. OpenRulesEngine can be invoked from any Java application using a simple Java OpenRules API or the standard JSR-94 interface. Rules Execution LogicWhen OpenRulesEngine is created it downloads the main xls-file and all other files using the "include" properties in the Environment tables. The engine executes the rules starting with the main method defined for this particular engine run.
If a customer is Married Female the conditions of the second rules are satisfied and the salutation "Mrs." will be selected. This is only a business view of the rules table. The complete view including the hidden implementation details ("Java snippets") are presented below:
OpenRulesEngine will execute rules (all 3 "white" rows) one after another. For each row if conditions C1 and C2 are satisfied then the action A1 will be executed with the selected "salutation". Please note that for this table conditions for all 3 rules will be examined before executing any actions. This is an example of so-called "multi-hit" rules table that executes all rules it may "hit". We may add one more rules at the very end of this table:
In this case, after executing the second rule OpenRulesEngine will also execute the new 4th rule and will override a salutation "Mrs." with "???". It is obviously not good. However, sometimes it may have a positive effect to avoid undefined values in cases when our previous rules did not cover all possible situations. What if our customer is a Divorced Female?! How to avoid this multi-hit effect? We want to produce "???" only when no other rules were satisfied. To achieve this you may use so-called "single-hit" tables that are specified by putting any return type except of "void" after the keyword "Rules". The following is an example of a single-hit rules table that will do exactly what we need:
Another positive effect of such "single-hitness" may be felt for large tables with say 1000 rows: if OpenRulesEngine hits a rule #10 it would not bother to check the validity of the remaining 990 rules. Having rules tables with a return value may also simplify your interface. For example, we do not really need a special object Response in which we used to write the defined salutation. Our simplified rules table may look like follows:
Here is an example of Java code that creates an OpenRulesEngine and executes the latest rules table "defineSalutation":
You can learn more about OpenRulesEngine API from the User's Guide. The standard OpenRules's installation contains many examples that demonstrate how to invoke OpenRulesEngine from regular Java applications (see projects HelloJava, HelloJsr94, HelloXMLCustomer) as long as from web-based applications (see projects HelloJsp, HelloForms, and HelloWS). Relationships Between Rule Tables In most practical cases business rules are not located in one file or in a single rule set, but rather are represented as a hierarchy of inter-related rules tables located in different files and directories - see Business Rules Repository. When you run OpenRulesEngine, you are executing a method from its main xls-file. Frequently, this method defines an execution logic that uses the conditions and sequences of rules presented in other rules tables and methods. In trivial cases, the rule engine can execute a rule table directly from a Java program. Typically, the main method executes a launcher that is a simple method specifying the execution sequence for different rules tables. Because OpenRules interprets rules tables as regular methods, designers of rules frequently create special "processing flow" decision tables to specify the conditions under which different rules should be executed. See examples of processing flow rules in such sample projects as Loan2 and LoanDynamics. One way or another, a rule designer needs to explicitly specify the execution logic for different rule sets. Dynamic Rules UpdatesIf a business rule is changed, OpenRulesEngine automatically reloads the rule when necessary. Before any engine's run, OpenRulesEngine checks to determine if the main Excel file associated with this instance of the engine has been changed. Actually, OpenRulesEngine looks at the latest modification dates of the file xlsMainFileName. If it has been modified, OpenRulesEngine re-initializes itself and reloads all related Excel files. OpenRules Implementation of JSR-94OpenRules provides a reference implementation of the JSR94 standard known as Java Rule Engine API (see http://www.jcp.org/en/jsr/detail?id=94). The standard OpenRules installation includes the following projects:
Engine Performance and ScalabilityIn the several years that OpenRules has been used as a component of complex real-world applications it has proven its high level of performance and its scalability. These days most Rule Engines demonstrate a high level of performance, but OpenRules is frequently chosen over major commercial BR products because of the following differentiators:
Consider the results cited in a a report OpenRules recently received from a major international bank. The bank created a series of performance and scalability tests before selecting OpenRules as the BR product of choice. They demonstrated that OpenRules scales to more than 300 concurrent users on a hyper-threaded Xeon box. Each concurrent user executed its rules 10,000 times with the following results:
Note that initially OpenRulesEngine takes more time to download all rules into the memory. However, there is no need to create a pool of concurrent rule engines: being stateless, the same instance of OpenRulesEngine can handle different concurrent requests.
OpenRules is a registered trademark of OpenRules, Inc. All other trademarks are the properties of their respective owners.
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 2003-2007 OpenRules, Inc. All rights reserved | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||