Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Buenos Aires Drools Expert Presentation

2,627 views

Published on

Drools Expert presentation at Buenos Aires JUG

Published in: Technology
  • Be the first to comment

Buenos Aires Drools Expert Presentation

  1. 1. Mark Proctor Project Lead <ul><li>T he SkyNet funding bill is passed.
  2. 2. The system goes online on August 4th, 1997.
  3. 3. Human decisions are removed from strategic defense.
  4. 4. SkyNet begins to learn at a geometric rate.
  5. 5. It becomes self-aware at 2:14am Eastern time, August 29th
  6. 6. In a panic, they try to pull the plug.
  7. 7. And, Skynet fights back </li></ul>
  8. 8. Drools Vs BRMS Repository Rules and Metadata JBoss Enterprise BRMS Platform JBoss Rules Rules Engine/ Execution Rules Development & Management CEP Complex Events Jboss EWP
  9. 9. Drools Vs BRMS <ul><li>Stand-alone Framework
  10. 10. Innovation
  11. 11. Fast and Frequent Releases
  12. 12. Tested on developer environments
  13. 13. Suitable for development and prototype
  14. 14. No Patches – On to next big thing
  15. 15. Non SLA bound forum support </li></ul><ul><li>Fully Integrated Platform
  16. 16. Same Innovated Code + Stability
  17. 17. Stability – Includes usability, performance and security issues identified during productization
  18. 18. Certified for Multi-OS, Multi-DB
  19. 19. Best for Development and Production
  20. 20. 5 Yr lifecycle – Includes patches, updates, backward compatibility
  21. 21. SLA based full support from dedicated support engineers
  22. 22. Open Source Assurance – legal protection </li></ul>derived
  23. 23. JBoss Community & Enterprise Changes Community / Enterprise Platform Delta BRMS Drools Enterprise Platforms - Performance, Scalability, Security and Qualityimprove over time without compromising long-term compatibility. 08/09 12/10 03/11 05/11 Over 150+ defect fixes & 35+ OS/JVM/DB certifications (& counting) between Drools Community 5.1 & JBoss BRMS 5.1.x
  24. 24. Evolution of JBoss BRMS 05/08 04/09 12/10 ? <ul><li>Lightweight Business Rules Engine </li></ul><ul><li>Business Rules Engine
  25. 25. Authoring and Management App
  26. 26. Repository
  27. 27. EAP Certified
  28. 28. DBs, JVMs </li></ul><ul><li>Business Rules Engine
  29. 29. Authoring and Management App
  30. 30. Choice of Repository
  31. 31. Integrated Container
  32. 32. CEP – Tech Preview
  33. 33. EAP, EWS, EWP, JVMs, Dbs and more
  34. 34. Performance </li></ul>Repository JBoss Enterprise BRMS Platform 5.0 JBoss Rules BRM Repository JBoss Enterprise BRMS Platform 5.1 JBoss Rules BRM CEP Jboss EWP
  35. 35. Back Up
  36. 37. Agenda <ul><li>Community
  37. 38. History
  38. 39. Declarative Programming
  39. 40. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  40. 41. Conditional elements
  41. 42. Timers and Calendars
  42. 43. Truth maintenance and Inference
  43. 44. Backward chaining </li></ul><li>Roadmap </li></ul>
  44. 45. Sample Industries and Users <ul><li>Investment </li><ul><li>Millennium Investment Group (MIG) </li></ul><li>Logistics </li><ul><li>Fedex </li></ul><li>Airline </li><ul><li>Sabre </li></ul><li>Mortgage </li><ul><li>Franklin American </li></ul><li>Healthcare </li><ul><li>OSDE </li></ul></ul>
  45. 46. Boot Camps <ul><li>San Francisco 2009 (40+ attendees) </li><ul><li>Sponsored by Third Pillar
  46. 47. Sun, FAMC, OSDE, Kaseya, Fedex, TU Group, Intermountain Healthcare, Gap, Sony Pictures, Lockheed Martin, Kaiser, HP, Wells Fargo, US Navy Research, FOLIOfn, Boeing ..... </li></ul><li>San Diego 2010 (80+ attendess) </li><ul><li>Sponsored by US Navy
  47. 48. 5 day event, with 2 days focus on the healthcare industry
  48. 49. OSDE, AT&T, SAIC, US Navy Research, Kaiser, Clinica, Intermountain Healthcare, GE Healthcare, VA, Boeing, Nationwide .... </li></ul></ul>
  49. 50. Books <ul><li>Introduction to Expert Systems </li><ul><li>Peter Jackson </li></ul><li>Expert Systems, Principles and Programming </li><ul><li>Joseph C. Giarratano and Gary D. Riley </li></ul></ul>
  50. 51. Oh And There are Drools Books Too
  51. 52. Agenda <ul><li>Community
  52. 53. History
  53. 54. Declarative Programming
  54. 55. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  55. 56. Conditional elements
  56. 57. Timers and Calendars
  57. 58. Truth maintenance and Inference
  58. 59. Backward chaining </li></ul><li>Roadmap </li></ul>
  59. 60. It All Started Here Birth of CDSS 1970s 1980s Dendral Baobab Mycin Guidon Neomycin Teiresias Puff Emycin WM Sacon Centaur Wheeze Gravida Clot Oncocin
  60. 61. Because Not Everyone Is As Smart As He Is
  61. 62. Business Rules Engines 1980s 2010s 1990s 2000s OPS5 ART Clips Jess Drools 2 JRules Drools 3 Drools 4 Drools 5
  62. 63. Drools History <ul><li>Drools 2 </li><ul><li>Rete like XML Scripting language </li></ul><li>Drools 3 </li><ul><li>Based on Clips functionality
  63. 64. Iterative improves to JRules syntax with Clips functionality </li></ul><li>Drools 4 </li><ul><li>More declarative
  64. 65. Basic functional programming feature with “from”
  65. 66. Basic Rule Flow
  66. 67. Basic BRMS </li></ul><li>Drools 5 </li><ul><li>Improved functional programming with 'accumulate'
  67. 68. More Advanced Rule Flow integration
  68. 69. Complex Event Process </li><ul><li>Temporal Comparators
  69. 70. Sliding Time Windows </li></ul><li>Production ready BRMS (Guvnor) </li></ul></ul>
  70. 71. Drools History <ul><li>Drools 5.1 </li><ul><li>Differential Diff (true modify) </li></ul><li>Drools 5.2 (this month) </li><ul><li>Freeform expressions between patterns
  71. 72. Multi-function accumulates
  72. 73. Prolog like derivation queries
  73. 74. Decision tables and rule templates (Guvnor)
  74. 75. Pure GWT (Guvnor) </li></ul></ul>
  75. 76. Agenda <ul><li>Community
  76. 77. History
  77. 78. Declarative Programming
  78. 79. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  79. 80. Conditional elements
  80. 81. Timers and Calendars
  81. 82. Truth maintenance and Inference
  82. 83. Backward chaining </li></ul><li>Roadmap </li></ul>
  83. 84. Integrated Systems Semantic Ontologies Rules Event Processes Workflows Rules Workflows Event Processes Semantic Ontologies
  84. 85. Integrated Systems
  85. 86. Declarative Programming <ul><li>Production Rule Systems PRD (forward chaining) </li><ul><li>Reactive
  86. 87. when Alarm( status == “alert” ) then send( “warning” ) </li></ul><li>Logic Programming LP (backward chaining) </li><ul><li>Query
  87. 88. descendant( “mary”, “jane”) </li></ul><li>Functional Programming FP </li><ul><li>Map,Fold, Filter
  88. 89. avg([12, 16, 4, 6]) </li><ul><li>Returns single value 9.5 </li></ul><li>round([10.3, 4.7, 7.8] ) </li><ul><li>Returns List [10, 5, 8] </li></ul></ul><li>Description Logic </li><ul><li>Person Has Name and LivesAt Address </li></ul></ul>
  89. 90. Concepts Overview
  90. 91. Concepts Overview
  91. 92. Concepts Overview
  92. 93. Agenda <ul><li>Community
  93. 94. History
  94. 95. Declarative Programming
  95. 96. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  96. 97. Conditional elements
  97. 98. Timers and Calendars
  98. 99. Truth maintenance and Inference
  99. 100. Backward chaining </li></ul><li>Roadmap </li></ul>
  100. 101. Classes
  101. 102. rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance += $amount; end select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance += cf.amount Credit Cashflow Rule
  102. 103. rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance += $amount; end rule “decrease balance for AccountPeriod Debits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == DEBIT, accountNo == $accountNo, date >= ap.start && <= ap.end, $ammount : ammount ) then acc.balance -= $amount; end Rules as a “view”
  103. 104. Agenda <ul><li>Community
  104. 105. History
  105. 106. Declarative Programming
  106. 107. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  107. 108. Conditional elements
  108. 109. Timers and Calendars
  109. 110. Truth maintenance and Inference
  110. 111. Backward chaining </li></ul><li>Roadmap </li></ul>
  111. 112. Definitions public class Applicant { private String name; private int age; private boolean valid; // getter and setter methods here } rule &quot;Is of valid age&quot; when $a : Applicant( age < 18 ) then modify ( $a ) { valid = false }; ends
  112. 113. Building KnowledgeBuilder kbuilder = KnowledgeBuilderFactory .newKnowledgeBuilder(); kbuilder .add( ResourceFactory .newClassPathResource( &quot;licenseApplication.drl&quot; , getClass() ), ResourceType.DRL ); if ( kbuilder .hasErrors() ) { System.err.println( kbuilder .getErrors().toString() ); } kbase .addKnowledgePackages( kbuilder .getKnowledgePackages() );
  113. 114. Executing StatelessKnowledgeSession ksession = kbase .newStatelessKnowledgeSession(); Applicant applicant = new Applicant ( &quot;Mr John Smith&quot; , 16 ); assertTrue ( applicant .isValid() ); ksession .execute( applicant ); assertFalse ( applicant .isValid() ); rule &quot;Is of valid age&quot; when $a : Applicant( age < 18 ) then modify ( $a ) { valid = false }; ends
  114. 115. Agenda <ul><li>Product Overview
  115. 116. Community
  116. 117. History
  117. 118. Declarative Programming
  118. 119. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  119. 120. Conditional elements
  120. 121. Timers and Calendars
  121. 122. Truth maintenance and Inference
  122. 123. Backward chaining </li></ul><li>Roadmap </li></ul>
  123. 124. Definitions public class Room { private String name // getter and setter methods here } public class Sprinkler { private Room room ; private boolean on ; // getter and setter methods here } public class Fire { private Room room ; // getter and setter methods here } public class Alarm { }
  124. 125. Definitions rule &quot;When there is a fire turn on the sprinkler&quot; when Fire ($room : room) $sprinkler : Sprinkler ( room == $room, on == false ) then modify ( $sprinkler ) { on = true }; println ( &quot;Turn on the sprinkler for room &quot; + $room.name ); end rule &quot;When the fire is gone turn off the sprinkler&quot; when $room : Room ( ) $sprinkler : Sprinkler ( room == $room, on == true ) not Fire ( room == $room ) then modify ( $sprinkler ) { on = false }; println ( &quot;Turn off the sprinkler for room &quot; + $room.name ); end
  125. 126. Definitions rule &quot;Raise the alarm when we have one or more fires&quot; when exists Fire () then insert ( new Alarm () ); println ( &quot;Raise the alarm&quot; ); end rule &quot;Cancel the alarm when all the fires have gone&quot; when not Fire () $alarm : Alarm () then retract ( $alarm ); println ( &quot;Cancel the alarm&quot; ); end
  126. 127. Definitions rule &quot;Status output when things are ok&quot; when not Alarm () not Sprinkler ( on === true ) then println ( &quot;Everything is ok&quot; ); end
  127. 128. Executing String [] names = new String []{ &quot;kitchen&quot; , &quot;bedroom&quot; , &quot;office&quot; , &quot;livingroom&quot; }; Map < String , Room > name2room = new HashMap < String , Room >(); for ( String name : names ){ Room room = new Room ( name ); name2room .put( name , room ); ksession .insert( room ); Sprinkler sprinkler = new Sprinkler ( room ); ksession .insert( sprinkler ); } ksession .fireAllRules() > Everything is ok
  128. 129. Executing Fire kitchenFire = new Fire ( name2room.get( &quot;kitchen&quot; ) ); Fire officeFire = new Fire ( name2room.get( &quot;office&quot; ) ); FactHandle kitchenFireHandle = ksession .insert( kitchenFire ); FactHandle officeFireHandle = ksession .insert( officeFire ); ksession .fireAllRules(); > Raise the alarm > Turn on the sprinkler for room kitchen > Turn on the sprinkler for room office
  129. 130. Executing ksession .retract( kitchenFireHandle ); ksession .retract( officeFireHandle ); ksession .fireAllRules() > Turn off the sprinkler for room office > Turn off the sprinkler for room kitchen > Cancel the alarm > Everything is ok rule &quot;Status output when things are ok&quot; when not Alarm () not Sprinkler ( on === true ) then println ( &quot;Everything is ok&quot; ); end
  130. 131. Agenda <ul><li>Community
  131. 132. History
  132. 133. Declarative Programming
  133. 134. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  134. 135. Conditional elements
  135. 136. Timers and Calendars
  136. 137. Truth maintenance and Inference
  137. 138. Backward chaining </li></ul><li>Roadmap </li></ul>
  138. 139. not Bus( color = “red” ) Conditional Elements exists Bus( color = “red” ) forall ( $bus : Bus( floors == 2 ) Bus( this == $bus, color == “red” ) ) forall ( $bus : Bus( color == “red” ) )
  139. 140. Accumulate CE rule &quot;accumulate&quot; when $sum : Number( intValue > 100 ) from accumulate ( Bus( color == &quot;red&quot; , $t : takings ) sum( $t ) ) then print &quot;sum is “ + $sum; end
  140. 141. Accumulate CE Patterns and CE's can be chained with ' from ' rule &quot;collect&quot; when $zipCode : ZipCode() $sum : Number( intValue > 100 ) from accumulate ( Bus( color == &quot;red&quot; , $t : takings ) from $hbn.getNamedQuery( “Find Buses” ) .setParameters( [ “zipCode” : $zipCode ] ) .list(), sum( $t ) ) then print &quot;sum is “ + $sum; end
  141. 142. Aggregations Rule Engines do not deal with aggregations $n : Number( intValue > 100 ) from accumulate ( $s : StockTicker( symbol == “RHAT” ) over window:time ( 5s ), average ( $s.price ) ) Over 5 seconds Aggregate ticker price for RHAT over last 5 seconds The pattern 'Number' reasons 'from' the accumulate result
  142. 143. $c : Custumer( type == “VIP ) $oe : BuyOrderEvent( customer == $c ) from entry-point “Home Broker Stream” not BuyAckEvent( relatedEvent == $oe.id, this after[1s, 10s] $oe ) from entry-point “Stock Trader Stream” Operators Existing Drools 'not' Conditional Elements can be used to detect non-occurrence of events BackAckEvent must occur between 1s and 10s ' after' BuyOrderEvent
  143. 144. Agenda <ul><li>Community
  144. 145. History
  145. 146. Declarative Programming
  146. 147. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  147. 148. Conditional elements
  148. 149. Timers and Calendars
  149. 150. Truth maintenance and Inference
  150. 151. Backward chaining </li></ul><li>Roadmap </li></ul>
  151. 152. Timers rule “name” timer ( cron: 0 0/15 * * * * ) when Alarm( ) then sendEmail( ”Alert Alert Alert!!!” ) Field Name Mandatory? Allowed Values Allowed Special Characters Seconds YES 0-59 , - * / Minutes YES 0-59 , - * / Hours YES 0-23 , - * / Day of month YES 1-31 , - * ? / L W Month YES 1-12 or JAN-DEC , - * / Day of week YES 1-7 or SUN-SAT , - * ? / L # Year NO empty, 1970-2099 , - * / Send alert every quarter of an hour
  152. 153. Calendars rule &quot;weekdays are high priority&quot; calendars &quot;weekday&quot; timer (int:0 1h) when Alarm() then send( &quot;priority high - we have an alarm” ); end rule &quot;weekend are low priority&quot; calendars &quot;weekend&quot; timer (int:0 4h) when Alarm() then send( &quot;priority low - we have an alarm” ); end Execute now and after 1 hour duration Execute now and after 4 hour duration
  153. 154. Agenda <ul><li>Community
  154. 155. History
  155. 156. Declarative Programming
  156. 157. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  157. 158. Conditional elements
  158. 159. Timers and Calendars
  159. 160. Truth maintenance and Inference
  160. 161. Backward chaining </li></ul><li>Roadmap </li></ul>
  161. 162. TMS and Inference rule &quot;Issue Child Bus Pass&quot; when $p : Person ( age < 16 ) then insert(new ChildBusPass ( $p ) ); end rule &quot;Issue Adult Bus Pass&quot; when $p : Person ( age >= 16 ) then insert(new AdultBusPass ( $p ) ); end Couples the logic What happens when the Child stops being 16?
  162. 163. TMS and Inference <ul><li>Bad </li><ul><li>Monolithic
  163. 164. Leaky
  164. 165. Brittle integrity - manual maintenance </li></ul></ul>
  165. 166. TMS and Inference <ul><li>A rule “logically” inserts an object
  166. 167. When the rule is no longer true, the object is retracted. </li></ul>when $p : Person ( age < 16 ) then logicalInsert ( new IsChild ( $p ) ) end when $p : Person ( age >= 16 ) then logicalInsert ( new IsAdult ( $p ) ) end de-couples the logic Maintains the truth by automatically retracting
  167. 168. TMS and Inference rule &quot;Issue Child Bus Pass&quot; when $p : Person ( ) IsChild ( person =$p ) then logicalInsert ( new ChildBusPass ( $p ) ); end rule &quot;Issue Adult Bus Pass&quot; when $p : Person ( age >= 16 ) IsAdult ( person =$p ) then logicalInsert ( new AdultBusPass ( $p ) ); end The truth maintenance cascades
  168. 169. TMS and Inference rule &quot;Issue Child Bus Pass&quot; when $p : Person ( ) not ( ChildBusPass ( person == $p ) ) then requestChildBusPass( $p ); end The truth maintenance cascades
  169. 170. TMS and Inference <ul><li>Good </li><ul><li>De-couple knowledge responsibilities
  170. 171. Encapsulate knowledge
  171. 172. Provide semantic abstractions for those encapsulation
  172. 173. Integrity robustness – truth maintenance </li></ul></ul>
  173. 174. Agenda <ul><li>Community
  174. 175. History
  175. 176. Declarative Programming
  176. 177. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  177. 178. Conditional elements
  178. 179. Timers and Calendars
  179. 180. Truth maintenance and Inference
  180. 181. Backward chaining </li></ul><li>Roadmap </li></ul>
  181. 182. Backward Chaining query isChild( Person p ) $p : Person ( age <= 16 ) end rule &quot;Issue Child Bus Pass&quot; when $p : Person ( ) ?isChild ( $p ) then logicalInsert ( new ChildBusPass ( $p ) ); end
  182. 183. Backward Chaining query isContainedIn( String x, String y ) Location ( x, y; ) or ( Location ( z, y; ) and ?isContainedIn ( x, z; ) ) end rule reactiveLook when Here ( place : place) ?isContainedIn ( place, &quot;keys&quot; ; ) then System.out.println( &quot;We have found your keys&quot; ); end
  183. 184. Agenda <ul><li>Community
  184. 185. History
  185. 186. Declarative Programming
  186. 187. Drools Expert </li><ul><li>Quick Example Stateless/Stateful
  187. 188. Conditional elements
  188. 189. Timers and Calendars
  189. 190. Truth maintenance and Inference
  190. 191. Backward chaining </li></ul><li>Roadmap </li></ul>
  191. 192. Roadmap <ul><li>Drools </li></ul><ul><li>Improved backward chaining (open queries)
  192. 193. Optimistic backward chaining.
  193. 194. Business Semantics (ontologies)
  194. 195. Simulation Testing
  195. 196. High Availability
  196. 197. Distributed (Grid) platform
  197. 198. Runtime Management
  198. 199. BAM </li></ul>
  199. 200. Questions? Questions? <ul><li>Dave Bowman : All right, HAL; I'll go in through the emergency airlock.
  200. 201. HAL : Without your space helmet, Dave, you're going to find that rather difficult.
  201. 202. Dave Bowman : HAL, I won't argue with you anymore! Open the doors!
  202. 203. HAL : Dave, this conversation can serve no purpose anymore. Goodbye. </li></ul>Joshua: Greetings, Professor Falken. Stephen Falken : Hello, Joshua. Joshua: A strange game. The only winning move is not to play. How about a nice game of chess?

×