Michael Neale michael@michaelneale jboss michaelneale
-
Upload
simon-barnes -
Category
Documents
-
view
36 -
download
0
description
Transcript of Michael Neale michael@michaelneale jboss michaelneale
![Page 2: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/2.jpg)
Project history
![Page 3: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/3.jpg)
JBoss/Red Hat
![Page 4: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/4.jpg)
History of Rule Engines
70s: Mycin/E-Mycin80s: CLIPS + many more
(expert systems)90s: BRMS (Ilog, Fair Isaac)
(business rules management)
![Page 5: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/5.jpg)
Practical rule engines
Humorous introductionThanks to Thomas Meeks
(it tries to be funny)
![Page 6: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/6.jpg)
What are rule engines for?Add rules == expert system
(a system that emulates a domain expert)
BRMS == Business Rule Management System(central management of changing business
rules)
Decision services (automated decisions, decision support)
![Page 7: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/7.jpg)
No really?
What are they good for? Some example users:
HR (coping with multiple awards)Transport (monitoring sensors)
Mortgage products (> 4000 rules)
![Page 8: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/8.jpg)
Drools is an engine++
IDE (developer tooling) – debuggingWeb based tooling (analysis – BRMS)Deployment toolsCEP/Stream processing (future)Testing and analysis tools (next release)Multiple authoring paradigms:DRL, DSL, XLS (decision tables), PNL, Rule Flow
![Page 9: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/9.jpg)
A quick visual tour...
![Page 10: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/10.jpg)
Dev tools:
![Page 11: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/11.jpg)
IDE
![Page 12: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/12.jpg)
Web tools:
![Page 13: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/13.jpg)
![Page 14: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/14.jpg)
rule editing
![Page 15: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/15.jpg)
DSLs for i18n
![Page 16: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/16.jpg)
![Page 17: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/17.jpg)
Integrated testing
![Page 18: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/18.jpg)
![Page 19: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/19.jpg)
Logic Analysis
![Page 20: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/20.jpg)
![Page 21: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/21.jpg)
Climbing the peak...
Helps simplify complicated logicLowers the cost of changing business logic
Usually very fastBasically a business logic framework
![Page 22: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/22.jpg)
Not another framework !
![Page 23: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/23.jpg)
No silver bullet
Rule engines are a complexity, use only as needed, otherwise, grrr.....
![Page 24: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/24.jpg)
So, when to use one?
Complicated logic (not 1+1 = 3 for large values of 1)Changes often (whatever that means)Traditional approaches are a challengeDomain expertise is readily available
![Page 25: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/25.jpg)
Don't use for a shopping cart
Don't use on applications with simple business logic
If the logic is complicated but will never (ever) change, might not need it.
Easy logic, changes often?try : Scripting, Lookup tables etc...
![Page 26: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/26.jpg)
Optimisation and speed
![Page 27: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/27.jpg)
RETE
Latin for “net”.As in network, or graph.
Performance is theoretically independent of the number of rules in the system.
Hint: its really a stateful optimisation technique, no-one expects you to know it (or care).
![Page 28: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/28.jpg)
![Page 29: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/29.jpg)
Example
Lets use rules to solve a real world scenario
Well, real, perhaps if you are a pirate
![Page 30: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/30.jpg)
![Page 31: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/31.jpg)
![Page 32: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/32.jpg)
A Domain expert
Yarr, Launch every ZIG !
(Captn' Domain Expert)
![Page 33: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/33.jpg)
if (us.somebodySetUsUpTheBomb()) { for (Zig zig : us.getZigs()) { zig.launch(); // for justice! }}
![Page 34: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/34.jpg)
Sally the Mechanic
Zigs should not launch without
their weapon system...
![Page 35: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/35.jpg)
Which of course are...
Atomic Kittens
![Page 36: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/36.jpg)
if (us.somebodySetUsUpTheBomb()) { for (Zig zig : us.getZigs()) { if (zig.hasAtomicKitty()) { zig.launch(); } }}
![Page 37: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/37.jpg)
Johnny the Regulator
Zigs must have been inspected in the last 24
hours to launch!
![Page 38: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/38.jpg)
if (us.somebodySetUsUpTheBomb()) { for (Zig zig : us.getZigs()) { if (zig.hasAtomicKitty() && zig.isInspected()) { zig.launch(); } }}
![Page 39: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/39.jpg)
Johnny the Regulator
Oh, and rule 23.43-57a#32.57 explicitly states that no more than 10 Zigs
can fly at a time!
![Page 40: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/40.jpg)
if (us.somebodySetUsUpTheBomb()) { int i = 0; for (Zig zig : us.getZigs()) { if (i == 10) { break; } if (zig.hasAtomicKitty() && zig.inspected()) { zig.launch(); i++; } } }
![Page 41: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/41.jpg)
Capt'n Domain expertArr! Only 10!?
If a Zig be shot down, launch more!
![Page 42: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/42.jpg)
Hmmm...
We could keep checking every Zig's status in an infinite loop.
We could implement the observer pattern on Zigs (when they explode, they tell someone).etc... <snore>
Lets stick with the loop for the example
![Page 43: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/43.jpg)
int i = 0;while (us.somebodySetUsUpTheBomb()) { for (Zig zig : us.getZigs()) { if (zig.hasExploded()) { us.getZigs().remove(zig); i--; continue; } if (zig.hasAtomicKitty() && zig.inspected() && i < 10) { zig.launch(); i++; } } }
![Page 44: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/44.jpg)
Sally the Mechanic
If those Zigs get beat up, they should land so I can fix them!
And don't try to launch them while I'm working on them!
![Page 45: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/45.jpg)
int i = 0;while (somebodySetUsUpTheBomb()) { for (Zig zig : us.getZigs()) { if (zig.needsMaintenance()) { zig.land(); mechanic.startFixing(zig); i--; continue; } if (zig.hasExploded()) { us.getZigs().remove(zig); i--; continue; } if (zig.hasAtomicKitty() && zig.inspected() && i < 10 && !zig.inMaintenance()) { zig.launch(); i++; } } }
Hint: Most likely “inMaintenance” check will be forgotten, the first time....
![Page 46: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/46.jpg)
Johnny the Regulator
I forgot to mention that rule 23.43-57a#32.57a explicitly states that all Zigs can fly if
you fax form 453.438-347#B in triplicate
![Page 47: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/47.jpg)
Capt'n Domain expertArr! That form takes hours to fill!
Arr! Launch 10 until we fax it, then Take off every Zig!
![Page 48: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/48.jpg)
int i = 0;while (somebodySetUsUpTheBomb()) { form.asyncFillOutAndFax();
for (Zig zig : us.getZigs()) { if (zig.needsMaintenance()) { zig.land(); mechanic.startFixing(zig); i--; continue; } if (zig.hasExploded()) { us.getZigs().remove(zig); i--; continue; } if (zig.hasAtomicKitty() && zig.inspected() && (i < 10 || form.isFaxed()) && !zig.inMaintenance()) { zig.launch(); i++; } } }
![Page 49: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/49.jpg)
Johnny the Regulator
We just changed the rules!All Zigs must be pink to fly
![Page 50: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/50.jpg)
Sally the Mechanic
Paint them pink!? That will take months! We have thousands!
![Page 51: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/51.jpg)
Capt'n Domain expert
Arr! Take off all pink Zigs!If we finish painting a Zig, launch
it!
![Page 52: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/52.jpg)
Getting complicated?
Thousands of Zigs? That loop could take a while
A lot of event-driven logic
Looks like it is going to end up really messy
No, the regulator will not stop
![Page 53: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/53.jpg)
Wait a second...
You might be thinking – that was awfully arbitrary!
Or – Hey, I can make up stupid requirements that are hard to implement in a huge loop cleanly too!
I must assume you aren't in a regulated industry...
![Page 54: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/54.jpg)
Now, using rules...
![Page 55: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/55.jpg)
rule “take off every zig (for great justice)” no-loop true; when Us(somebodySetUpUsTheBomb == true) zig : Zig(inspected == true, pink == true, atomicKitten == true, inMaintenance == false, launched == false) launched : launched(launched < 10 || formFaxed == true) then zig.launch() launched.increment() update(zig) update(launched)end
![Page 56: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/56.jpg)
rule “zig explodes” no-loop true when zig : Zig(destroyed == true) launched : Launched() then retract(zig) launched.decrement() update(launched)end
![Page 57: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/57.jpg)
rule “repair zig” no-loop true when zig : Zig(needsMaintenance == true) mechanic : Mechanic() launched : Launched() then zig.land(); launched.decrement(); mechanic.startFixing(zig); //update zig when done update(zig);end
![Page 58: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/58.jpg)
Where is the loop?
Implied
Each rule fires for each fact combination that matches
If you “assert” (insert) 1000 Zigs, the first rule will be checked 1000 times
(but it remembers, indexes, for future data changes)
![Page 59: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/59.jpg)
What else is good
New rules can be gracefully inserted into a large ruleset (even while running)
Will automatically fire when conditions are met
Caching facts makes execution very fast
Properly managed rules can create very dynamic systems
![Page 60: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/60.jpg)
The trough of disillusionment
Easy to overuse rules
Not all logic (even in complex systems) should be in rules
Notice that there is no rule describing how a Zig launches
Bugs in overly complex rules can be evil
![Page 61: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/61.jpg)
Java bug
![Page 62: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/62.jpg)
C Bug
![Page 63: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/63.jpg)
Rules Bug
![Page 64: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/64.jpg)
A quick aside on choosing a rule
engine..It needs to have a NOT conditional (e.g. Operate on the non-existence of a fact)
Don't trust claims of graphical programmingIt is neat, but not a silver bullet
Ditto for “end user computing”
Be realistic
![Page 65: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/65.jpg)
Deployment models
Decision service-Typically a web service (centrally hosted)
Embedded into an application
Central BRMS server
![Page 66: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/66.jpg)
Some standards
Java API: JSR94 *SBVR (OMG)
RuleMLRIF (W3C) *
![Page 67: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/67.jpg)
Other products
Ilog JRules Fair Isaac Blaze AdvisorCorticon -interesting spreadsheet based rule modellingRuleBurst (now Haley) -specialise in natural language and rules extracted from documentation
![Page 68: Michael Neale michael@michaelneale jboss michaelneale](https://reader031.fdocuments.net/reader031/viewer/2022032016/56813119550346895d977c85/html5/thumbnails/68.jpg)
Roadmap for 2008
CEPTesting & Analysis (Automated QA)
Integrated processes (BPM)“process server” (decision services)