Drools Expert and Fusion Intro  : London 2012
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Drools Expert and Fusion Intro : London 2012

on

  • 7,976 views

Drools Expert and Fusion introductory talks given at London 2012.

Drools Expert and Fusion introductory talks given at London 2012.

Statistics

Views

Total Views
7,976
Views on SlideShare
7,974
Embed Views
2

Actions

Likes
6
Downloads
302
Comments
0

2 Embeds 2

http://www.docseek.net 1
http://www.slashdocs.com 1

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Drools Expert and Fusion Intro : London 2012 Presentation Transcript

  • 1. Mark Proctor Project LeadThe SkyNet funding bill is passed.The system goes online on August 4th, 1997.Human decisions are removed from strategic defense.SkyNet begins to learn at a geometric rate.It becomes self-aware at 2:14am Eastern time, August 29thIn a panic, they try to pull the plug.And, Skynet fights back
  • 2. Drools Books
  • 3. Sample Industries and UsersInvestment Millennium Investment Group (MIG)Logistics FedexAirline SabreMortgage Franklin AmericanHealthcare OSDE
  • 4. Boot CampsSan Francisco 2009 (40+ attendees) Sponsored by Third Pillar Sun, FAMC, OSDE, Kaseya, Fedex, TU Group, Intermountain Healthcare, Gap, Sony Pictures, Lockheed Martin, Kaiser, HP, Wells Fargo, US Navy Research, FOLIOfn, Boeing .....San Diego 2010 (80+ attendess) Sponsored by US Navy 5 day event, with 2 days focus on the healthcare industry OSDE, AT&T, SAIC, US Navy Research, Kaiser, Clinica, Intermountain Healthcare, GE Healthcare, VA, Boeing, Nationwide ....
  • 5. 5Integrated Systems Rules Rules Workflows Workflows Event Processes Semantic Ontologies Semantic Event Ontologies Processes
  • 6. generic Rules and processes ? Decision ServicesSCOPE Processspecific Rules tightly coupled COUPLING loosely coupled
  • 7. 7Integrated Systems Drools JBPM5 Drools Drools Expert (Drools Flow) Fusion Guvnor Drools Drools Drools Drools Planner Grid Semantics Chance Business Logic integration System
  • 8. Because Not EveryoneIs As Smart As He Is
  • 9. Declarative ProgrammingProduction Rule Systems PRD (forward chaining) Reactive when Alarm( status == “alert” ) then send( “warning” )Logic Programming LP (backward chaining) Query descendant( “mary”, “jane”)Functional Programming FP Map,Fold, Filter avg([12, 16, 4, 6]) Returns single value 9.5 round([10.3, 4.7, 7.8] ) Returns List [10, 5, 8]Description Logic Person Has Name and LivesAt Address
  • 10. Definitionspublic class Applicant { private String name; private int age; private boolean valid; // getter and setter methods here}rule "Is of valid age" when $a : Applicant( age < 18 )then modify( $a ) { valid = false };ends
  • 11. BuildingKnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();kbuilder.add( ResourceFactory .newClassPathResource( "licenseApplication.drl", getClass() ), ResourceType.DRL );if ( kbuilder.hasErrors() ) { System.err.println( kbuilder.getErrors().toString() );}kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
  • 12. Spring Configuration
  • 13. Spring and CamelConfiguration
  • 14. Executingrule "Is of valid age" when $a : Applicant( age < 18 )then modify( $a ) { valid = false };endsStatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();Applicant applicant = new Applicant( "Mr John Smith", 16 );assertTrue( applicant.isValid() );ksession.execute( applicant );assertFalse( applicant.isValid() );
  • 15. Definitionspublic 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 {}
  • 16. Conditional Elementsnot Bus( color = “red” )exists Bus( color = “red” )forall ( $bus : Bus( color == “red” ) )forall ( $bus : Bus( floors == 2 ) Bus( this == $bus, color == “red” ) )
  • 17. Accumulate CErule "accumulate"when accumulate( Bus( color == "red", $t : takings ); $sum : sum( $t ), $min : min( $t ), $max : max( $t ); $min > 100 && $max < 200 && $sum > 500 )then print "sum is “ + $sum;end
  • 18. Classes C a s h f lo w A cco u n t D a te d a telo n g a c c o u n t N o d o u b le a m o u n td o u b le b a la n c e in t t y p e lo n g a c c o u n t N o A c c o u n t in g P e r io d D a te s ta r t D a te e n d
  • 19. Credit Cashflow Rule 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.amountrule “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
  • 20. Rules as a “view” CashFlow AccountingPeriod date amount type accountNo start end 12-Jan-07 100 CREDIT 1 01-Jan-07 31-Mar-07 2-Feb-07 200 DEBIT 1 18-May-07 50 CREDIT 1 Account 9-Mar-07 75 CREDIT 1 accountNo balance 1 0rule “increase balance for AccountPeriod rule “decrease balance for AccountPeriod Credits” Debits” when when ap : AccountPeriod() ap : AccountPeriod() acc : Account( $accountNo : accountNo ) acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, CashFlow( type == DEBIT, accountNo == $accountNo, accountNo == $accountNo, date >= ap.start && <= ap.end, date >= ap.start && <= ap.end, $ammount : ammount ) $ammount : ammount ) then then acc.balance += $amount; acc.balance -= $amount;end CashFlow end CashFlow date amount type date amount type 12-Jan-07 100 CREDIT 2-Feb-07 200 DEBIT 9-Mar-07 75 CREDIT Account accountNo balance 1 -25
  • 21. TMS and Inference rule "Issue Child Bus Pass" when $p : Person( age < 16 ) then insert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" when $p : Person( age >= 16 ) then insert(new AdultBusPass( $p ) ); end
  • 22. TMS and Inference rule "Issue Child Bus Pass" Couples the logic when $p : Person( age < 16 ) then insert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" What happens when the Child stops being 16? when $p : Person( age >= 16 ) then insert(new AdultBusPass( $p ) ); end
  • 23. TMS and InferenceBad Monolithic Leaky Brittle integrity - manual maintenance
  • 24. TMS and Inference A rule “logically” inserts an object When the rule is no longer true, the object is retracted. when $p : Person( age < 16 ) de-couples the logic then logicalInsert( new IsChild( $p ) ) end when Maintains the truth by $p : Person( age >= 16 ) automatically retracting then logicalInsert( new IsAdult( $p ) ) end
  • 25. TMS and Inference rule "Issue Child Bus Pass" when $p : Person( ) IsChild( person =$p ) then logicalInsert(new ChildBusPass( $p ) ); end rule "Issue Adult Bus Pass" The truth maintenance when cascades $p : Person( age >= 16 ) IsAdult( person =$p ) then logicalInsert(new AdultBusPass( $p ) ); end
  • 26. TMS and Inferencerule "Issue Child Bus Pass"when $p : Person( ) not( ChildBusPass( person == $p ) )then The truth maintenance cascades requestChildBusPass( $p );end
  • 27. TMS and InferenceGood De-couple knowledge responsibilities Encapsulate knowledge Provide semantic abstractions for those encapsulation Integrity robustness – truth maintenance
  • 28. Wumpus World
  • 29. Wumpus World
  • 30. Wumpus World Cell Hero Wumpus Pitt Gold int row int row int row int row int row Int col Int col Int col Int col Int col
  • 31. Wumpus WorldDemonstrationhttp://www.youtube.com/watch?v=4CvjKqUOEzM
  • 32. What is Complex Event Processing 1. Detect 2. Correlate 3. React
  • 33. Time is Money Business Event Value Loss Business Value Reaction Time Time Loss Adapted from a presentation by James Taylor, Sep/2011
  • 34. Terminology: CEP and ESPFor the scope of this presentation: “CEP is used as a common term meaning both CEP and ESP.”
  • 35. EDA vs SOAEDA is **not** SOA 2.0Complementary architecturesMetaphorIn our body:SOA is used to build our muscles and organsEDA is used to build our sensory system
  • 36. Event Driven ArchitecturesedBPM + EDM
  • 37. Drools Fusion: Enables…Event Detection:From an event cloud or set of streams, select all themeaningful events, and only them.[Temporal] Event Correlation:Ability to correlate events and facts declaring bothtemporal and non-temporal constraints between them.Ability to reason over event aggregationEvent Abstraction:Ability to compose complex events from atomic eventsAND reason over them
  • 38. Drools FusionFeatures:Event Semantics as First Class CitizensAllow Detection, Correlation and CompositionTemporal ConstraintsSession ClockStream ProcessingSliding WindowsCEP volumes (scalability)(Re)Active RulesData Loaders for Input
  • 39. Drools FusionFeatures:Event Semantics as First Class CitizensAllow Detection, Correlation and CompositionTemporal ConstraintsSession ClockStream ProcessingSliding WindowsCEP volumes (scalability)(Re)Active RulesData Loaders for Input
  • 40. Event Declaration and Semantics// declaring existing classimport some.package.VoiceCall Event semantics:declare VoiceCall Point-in-time and Interval @role( event ) @timestamp( calltime ) @duration( duration ) An event is a fact with a few specialend characteristics:// generating an event class Usually immutable, but not enforceddeclare StockTick @role( event ) Strong temporal relationships Lifecycle may be managed symbol : String price : double Allow use of sliding windowsend “All events are facts, but not all facts are events.”
  • 41. Temporal ReasoningSemantics for:time: discreteevents: point-in-time and intervalAbility to express temporal relationships:Allen’s 13 temporal operatorsJames F. Allen defined the 13 possible temporalrelations between two events.Eiko Yoneki and Jean Bacon defined a unifiedsemantics for event correlation over time and space.
  • 42. Stream Support (entry-points)A scoping abstraction for stream supportRule compiler gather all entry-point declarations andexpose them through the session APIEngine manages all the scoping and synchronizationbehind the scenes.rule “Stock Trade Correlation”when $c : Customer( type == “VIP” ) BuyOrderEvent( customer == $c, $id : id ) from entry-point “Home Broker Stream” BuyAckEvent( sourceEvent == $id ) from entry-point “Stock Trader Stream”then // take some actionend
  • 43. Delaying RulesNegative patterns may require rule firings to be delayed. rule “Order timeout” when $bse : BuyShares ( $id : id ) not BuySharesAck( id == $id, this after[0s,30s] $bse ) then // Buy order was not acknowledged. Cancel operation // by timeout. end
  • 44. Temporal Relationshipsrule “Shipment not picked up in time”when Shipment( $pickupTime : scheduledPickupTime ) not ShipmentPickup( this before $pickupTime )then // shipment not picked up... action required.end
  • 45. Temporal Relationshipsrule “Shipment not picked up in time”when Shipment( $pickupTime : scheduledPickupTime ) not ShipmentPickup( this before $pickupTime )then // shipment not picked up... Action required.end Temporal Relationship
  • 46. Allen’s 13 Temporal Operators Point-Point Point-Interval Interval-Interval A A before B B A A meets B B AA overlaps B B AA finishes B B AA includes B B A A starts B B AA coincides B B
  • 47. Allen’s 13 Temporal Operators Point-Point Point-Interval Interval-Interval A A after B B A A metBy B B AA overlapedBy B B AA finishedBy B B A A during B B A A finishes B B
  • 48. Sliding Window SupportAllows reasoning over a moving window of “interest”TimeLength Sliding window 1 Sliding window 2 Joined window
  • 49. Sliding Window Supportaccumulate( $s : StockTicker( symbol == “RHAT” ) over window:time( 5s ); $avg : avg( $s.price ); $avg > 100 ) Aggregate ticker price for RHAT over last 5 se
  • 50. Sliding Window SupportAllows reasoning over a moving window of “interest”TimeLengthrule “Average Order Value over 12 hours”when $c : Customer() accumulate( BuyOrder( customer == $c, $p : price ) over window:time( 12h ); $a : avg( $p ); $a > 10 )then // do somethingend
  • 51. Calendarsrule "weekdays are high priority" calendars "weekday" timer (int:0 1h) Execute now and after 1 hour durationwhen Alarm()then send( "priority high - we have an alarm” );endrule "weekend are low priority" calendars "weekend" timer (int:0 4h) Execute now and after 4 hour durationwhen Alarm()then send( "priority low - we have an alarm” );end
  • 52. TimersField Name Mandatory? Allowed Values Allowed Special CharactersSeconds YES 0-59 ,-*/Minutes YES 0-59 ,-*/Hours YES 0-23 ,-*/Day of month YES 1-31 ,-*?/LWMonth 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 hourrule “name” timer ( cron: 0 0/15 * * * * )when Alarm( )then sendEmail( ”Alert Alert Alert!!!” )
  • 53. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
  • 54. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009At least 50% of Alerts can be reasoned automatically, promotingstaff savings and improved Customer and Driver experiences.Risk Avoidance via pro-active monitoringReduction in insurance claims and shipment service failuresMinimum 30% efficiency gains in shipment monitoring , saving atleast 15% of Operations staff cost.
  • 55. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009Some numbers (from early 2010):24 x 7 sessions, no downtimeAverage of 500k+ facts/events concurrently in memoryBusiness hours: 1M+ facts/events concurrentlyResponse time for reasoning cycles:Average: 150 msPeak: 1.2 secSeveral hundred rules
  • 56. Differential UpdateDifferential Update (a.k.a. “true modify”)Implements a real “modify/update” operation, instead ofretract+assert.Reuses tuples, reduces GC stress, improves performance
  • 57. Questions? Dave Bowman: All right, HAL; Ill go in through the emergency airlock. HAL: Without your space helmet, Dave, youre going to find that rather difficult. Dave Bowman: HAL, I wont argue with you anymore! Open the doors! HAL: Dave, this conversation can serve no purpose anymore. Goodbye.en.o, Joshua.he only winning move is not to play. How about a nice game of chess?