Download presentation
Presentation is loading. Please wait.
Published byMervyn Jeffrey Long Modified over 8 years ago
1
Business Rules Engine in Java Introduction to JBoss Rules by Tom Sausner
2
Overview ● JBoss Rules introduction ● Rules Engine Overview ● Applications ● Integration with Java applications ● Eclipse IDE plug-in ● Rules ● Demos ● Conclusion
3
JBoss Rules ● Apache License v2.0 open source license ● Previously Drools ● Other Business Rules Engines – Jess, OPS5, Clips, SOAR, Lisa ● Eclipse IDE integration!!! ● Runs on Jdk 1.4 or greater
4
BRE Standards ● Java Rule Engine API -JSR-94 ● Wrapper around a rules engine – Register and unregister rules – Parse rules – Inspect rule metadata – Execute rules – Retrieve results – Filter results ● W3C is working on Rules Interchange Format (RIF) and ● RuleML, a standard rule language, SWRL ● Existing rules need to be ported
5
Business Rules Engines ● Rule Based approached to implement an Expert System ● Primarily Implements the Rete algorithm – Created by Charles Forgy – “efficient pattern matching algorithm for implementing production rule systems” – Network of nodes... each node is a pattern defined by the LHS of the rules – Designed to sacrifice memory for increased speed ● Leaps algorithm
6
Why, When and Where ● Why – Separate decision making logic from data – Speed and Scalability – Declarative Programming – Centralization of Knowledge ● When – Problem does not lend itself to algorithmic sol'n – Logic often changes – Domain experts are available but not technical ● Where – http://www.jboss.com/products/rules
7
Rule Processing ● Forward Chaining ● Object asserted into Working Memory ● RETE selects matching Rules ● Rule Engine fires executes any rules that match ● Agenda resolves conflicts ● Consequences fire
8
Rules Engine
9
Rule Terms ● Fact ( application data ) ● Working Memory ( stateful collection of facts ) ● Production Memory ( the rules ) ● Inference Engine ( JBoss Rules & RETE ) ● Agenda ( conflict resolution ) ● Salience ( priority ) ● Assert, Retract and Modify
10
Rule File Organization ● package org.rjug ● #list any import classes here. ● #declare any global variables here ● #implement functions here ● rule "Your Rule" ● #include attributes such as "salience" here... ● when ● #conditions ● then ● #action ● end
11
Rule Syntax ● rule “ ” ● ● when ● ● then ● ● end
12
When - LHS ● Binding – Parameter – Fact ● Field Constraints ● Query – Allows you to query object in working memory – Looks like the “when” part. – Use 'workingMemory.getQueryResults(...)'
13
Columns ● The list of constraints on an object type ● Constraint types – Literal – Bound variable – Return value ( must evaluate to an object ) – Predicate ( must evaluate to primitive boolean ) ● Associated by the normal operators + matches(regex), contains, excludes( collections) ● Eval – catch all that executes and returns a boolean ● Autoboxing can be quirky
14
Rule Attributes ● Salience – priority ● Agenda-group – Allows partitioning of the agenda, only rules in this group are allowed to fire ● Auto-focus – Gives focus to an agenda group ● Activation-group – Xor group ● No-loop – Prevents recursion ● duration
15
Conflict Resolution ● Two phase recursive Agenda ● Agenda Evaluation – Selects the next rule & calls Working Memory Action – If no rules are left, exit ● Working Memory Action – Fires the consequence – Switches to Agenda Evaluation ● Resolution Strategy – Salience – LIFO ( Last In First Out ) ● Agenda Filtering
16
Decision Tables ● Ideal for spreadsheet-friendly staff ● Entry validation ● Control which fields can be changed ● Each row is a rule ● Each column is a conditional or consequence
18
Domain Specific Languages ● Allows rules to be more easily edited by analysts ● Maps common language to rule expression ● Aids developer and business collaboration ● DSLs can also act as "templates" of conditions or actions that are used over and over in your rules ● No impact on rules at runtime – Just a parse/compile time issue ● DSL support in the eclipse plugin
19
DSL Example ● [when]There is a Person with name of "{name}"=Person(name=="{name}") ● [when]Person is at least {age} years old and lives in "{location}"=Person(age > {age}, location=="{location}") ● [then]Log "{message}"=System.out.println("{message}"); ● [when]And = and
20
DSL from the IDE plug-in
21
Integration with Java ● Can write java directly in the rules file – Not much fun to debug here ● Can import and dereference java objects in the “then” part of a rule – Don't want the “when” part to change.
22
Jboss Rules Workbench ● Eclipse plug-in – 3.2 or greater ● Rules Project Creation ● Rule Editor – Syntax Highlighting!!! – Content assist – Outline – Builder... watch out! ● DSL editor ● Rule validation ● Views – Working memory, agenda, global data, Rete
23
Demo 1 ● Simple rules application ● Java – Read rules file – Assert facts – Fire all rules ● Rules – Rules file layout – Simple rules evaluation – Eclipse “views” on the rules – Binding objects and parameters – Retract
24
Demo 2 ● Same Java setup – different facts – Implement functionality called from the rules ● Rules – Globals – Multi – layer rules ● Re-asserting facts ● Utility rules( array list ) – Functions in the rule file – Calling out to methods elsewhere in java
25
Demo 3 - “The Road Test” ● Java – same setup, different facts ● Rules – Controlling the Agenda – Salience – Activation - Groups – no-loop
26
Best Practices ● Building rules – Strong vs. loose coupling – Use fine grained rules – Try not to rely on rule order – Consider asserting an object before making it global ● Stateful or stateless memory? ● Rule versioning ● Test Cases ● Performance testing & tuning
27
Other Enterprise Issues ● Rule Authoring – Validation – Profiling – Testing ● Business Rule Management Systems(BRMS) – Managing rules/rule sets – Versioning – BR system life cycle ● Fair Issac - Blaze Advisor
28
Questions? ● www.jboss.org/rules
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.