Drools Rule Engine
The following is a description of the important libraries that make up JBoss Drools
- this provides the interfaces and factories.
- this provides internal interfaces and factories.
- This is the core engine, runtime component.
- Contains both the RETE engine and the LEAPS engine.
- This is the only runtime dependency.
- This contains the compiler/builder components to take rule source, and build executable rule bases. This is often a runtime dependency of your application, but it need not be if you are pre-compiling your rules. This depends on drools-core.
- This is the JSR-94 compliant implementation, this is essentially a layer over the drools-compiler component.
- this is the decision tables ‘compiler’ component, which uses the drools-compiler component. This supports both excel and CSV input formats.
Stateless Knowledge Session:
- Don not use inference, forms the simplest use case.
- A stateless session can be called like a function passing it some data and then receiving some results back.
- Some common use cases for stateless sessions are, but not limited to:
- Validation : Is this person eligible for a mortgage?
- Calculation: Compute a mortgage premium.
- Routing and Filtering
- Filter incoming messages, such as emails, into folders.
- Send incoming messages to a destination.
Stateful Knowledge Session:
- Stateful Sessions are long lived and allow iterative changes over time.
- Some common use cases for Stateful Sessions are, but not limited to:
- Monitoring: Stock market monitoring and analysis for semi-automatic buying.
- Diagnostics: Fault finding, medical diagnostics
- Logistics: Parcel tracking and delivery provisioning
- Compliance User Guide
- Validation of legality for market trades.
Method versus Rule:
- Methods are called directly.
- Specific instances are passed.
- One call results in a single execution.
- Rules execute by matching against any data as long it is inserted into the engine.
- Rules can never be called directly.
- Specific instances cannot be passed to a rule.
- Depending on the matches, a rule may fire once or several times, or not at all.
- The Agenda is a Rete feature.
- It maintains set of rules that are able to execute, its job is to schedule that execution in a deterministic order.
- During actions on the RuleRuntime, rules may become fully matched and eligible for execution; a single Rule Runtime Action can result in multiple eligible rules.
- The Agenda controls the execution order of these Matches using a Conflict Resolution strategy.
The engine cycles repeatedly through two phases:
- Rule Runtime Actions.
- This is where most of the work takes place, either in the Consequence (the RHS itself) or the main Java application process.
- Once the Consequence has finished or the main Java application process calls fireAllRules() the engine switches to the Agenda Evaluation phase.
- Agenda Evaluation.
- This attempts to select a rule to fire.If no rule is found it exits,
- otherwise it fires the found rule, switching the phase back to Rule Runtime Actions.
- When we want to prioritise rule then this value to rule.
- Max value have max priority.
- Place rules under groups and place them on stack
- setFocus put following group onto stack.
- Rule are defined in rule file with extension as .drl.
- Structure of rule file
- package package-name imports
- Package should be first element, other can be declared in any order
- Structure of rule
- rule “name” attributes
- rule “name” attributes
- Hard keywords : reserved for use in .drl file (true,false and null)
- Soft keywords : can be used but, but recommended to avoid use (confusion)
- Global , function, no-loop etc