JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE  Tihomir Surdilovic  [email_address] JBoss, a Division of Red Hat
Agenda Project (Drools) vs. Product (BRMS)
Drools Vision
Drools History
Drools at a glance Expert
Guvnor
JBPM5 Focus on Drools Fusion (CEP Extensions) Event Declaration and Semantics
Event Cloud, Streams and the Session Clock
Temporal Reasoning
Sliding Window Support
Streams Support
Memory Management Questions & Answers
Project vs. Product Repository Rules and Metadata JBoss Enterprise BRMS Platform JBoss Rules Rules Engine/ Execution Rules Development & Management CEP Complex Events Jboss EWP
Project vs. Product Cont. Stand-alone Framework
Innovation
Fast and Frequent Releases
Tested on developer environments
Suitable for development and prototype
No Patches – On to next big thing
Non SLA bound forum support Fully Integrated Platform
Same Innovated Code + Stability
Stability – Includes usability, performance and security issues identified during productization
Certified for Multi-OS, Multi-DB
Best for Development and Production
5 Yr lifecycle – Includes patches, updates, backward compatibility
SLA based full support from dedicated support engineers
Open Source Assurance – legal protection derived
Jboss community and Enterprise  Changes Community / Enterprise Platform Delta BRMS Drools Enterprise Platforms - Performance, Scalability, Security and Quality improves 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
Evolution of Jboss BRMS 05/08   04/09   12/10   ?  Lightweight Business Rules Engine Business Rules Engine
Authoring and Management App
Repository
EAP Certified
DBs, JVMs  Business Rules Engine
Authoring and Management App
Choice of Repository
Integrated Container
CEP – Tech Preview
EAP, EWS, EWP, JVMs, Dbs and more
Performance Repository JBoss Enterprise BRMS Platform 5.0 JBoss Rules BRM Repository JBoss Enterprise BRMS Platform 5.1 JBoss Rules BRM CEP Jboss EWP
“ A  common platform  to  model  and  govern  the business  logic  of the enterprise.” Drools Vision
Drools Vision Cont. Event Processes Semantic  Ontologies Workflows Rules Rules  Workflows Event Processes Semantic  Ontologies
Drools History – Business Rule Engines 1980s 2010s 1990s 2000s OPS5 ART Clips Jess Drools 2 JRules Drools 3 Drools 4 Drools 5
Drools History Drools 2 Rete like XML Scripting language Drools 3  Based on Clips functionality
Iterative improves to JRules syntax with Clips functionality Drools 4 More declarative
Basic functional programming feature with “from”
Basic Rule Flow
Basic BRMS Drools 5 Improved functional programming with 'accumulate'
More Advanced Rule Flow integration
Complex Event Process Temporal Comparators
Sliding Time Windows Production ready BRMS (Guvnor)
Drools History Cont. Drools 5.1 Differential Diff (true modify) Drools 5.2 (this month, 5.2.0.CR1 available for download) Freeform expressions between patterns
Multi-function accumulates
Prolog like derivation queries
Decision tables and rule templates (Guvnor)
Pure GWT (Guvnor)
Sample Industries and Users Investment Millennium Investment Group (MIG)   Logistics Fedex   Airline Sabre Mortgage Franklin American Healthcare OSDE
Drools at a glance - Declarative programming Production 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 (model concepts, roles, and individuals) Person Has Name and    lives at Address
Drools Expert at a glance – Example A - SQL comparison example 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 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
Drools Expert at a glance –  Rules as a view 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
Drools Expert at a glance – Example A - Building and executing rules
Drools Expert at a glance – Example A Building and executing rules cont. Building Executing
Drools Expert at a glance – Example B - Building and executing rules
Drools Expert at a glance – Example B cont. No Fires Add some  Fires
Drools Expert at a glance – Example B cont. Fires are put out after a while
Drools Expert at a glance – Conditional Elements
Drools Expert at a glance – Accumulate CE Bus Example Accumulate general syntax Bus Example Revisited (no accumulate functions)
Drools Expert at a glance – Conditional Elements From
Drools Expert at a glance – Timers and Calendars Interval Timers 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    , - * /  Cron-based Timers
Drools Expert at a glance – Timers and Calendars Calendars Using Timers and Calendars together Execute now and after  1 hour duration on week days Execute now and after  4 hour duration on weekend days
Drools Expert at a glance – Truth maintenance and Inference Issuing Buss passes – typical rule implementation Good practice to do: De-couple knowledge responsibilities
Encapsulate knowledge
Provide semantic abstractions for those encapsulation
Integrity robustness – truth maintenance These types of implementations are considered Bad
Monolithic
Leaky

JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE

  • 1.
    JBoss Drools andDrools Fusion (CEP): Making Business Rules react to RTE Tihomir Surdilovic [email_address] JBoss, a Division of Red Hat
  • 2.
    Agenda Project (Drools)vs. Product (BRMS)
  • 3.
  • 4.
  • 5.
    Drools at aglance Expert
  • 6.
  • 7.
    JBPM5 Focus onDrools Fusion (CEP Extensions) Event Declaration and Semantics
  • 8.
    Event Cloud, Streamsand the Session Clock
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
    Project vs. ProductRepository Rules and Metadata JBoss Enterprise BRMS Platform JBoss Rules Rules Engine/ Execution Rules Development & Management CEP Complex Events Jboss EWP
  • 14.
    Project vs. ProductCont. Stand-alone Framework
  • 15.
  • 16.
  • 17.
    Tested on developerenvironments
  • 18.
  • 19.
    No Patches –On to next big thing
  • 20.
    Non SLA boundforum support Fully Integrated Platform
  • 21.
  • 22.
    Stability – Includesusability, performance and security issues identified during productization
  • 23.
  • 24.
    Best for Developmentand Production
  • 25.
    5 Yr lifecycle– Includes patches, updates, backward compatibility
  • 26.
    SLA based fullsupport from dedicated support engineers
  • 27.
    Open Source Assurance– legal protection derived
  • 28.
    Jboss community andEnterprise Changes Community / Enterprise Platform Delta BRMS Drools Enterprise Platforms - Performance, Scalability, Security and Quality improves 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
  • 29.
    Evolution of JbossBRMS 05/08 04/09 12/10 ? Lightweight Business Rules Engine Business Rules Engine
  • 30.
  • 31.
  • 32.
  • 33.
    DBs, JVMs Business Rules Engine
  • 34.
  • 35.
  • 36.
  • 37.
    CEP – TechPreview
  • 38.
    EAP, EWS, EWP,JVMs, Dbs and more
  • 39.
    Performance Repository JBossEnterprise BRMS Platform 5.0 JBoss Rules BRM Repository JBoss Enterprise BRMS Platform 5.1 JBoss Rules BRM CEP Jboss EWP
  • 40.
    “ A common platform to model and govern the business logic of the enterprise.” Drools Vision
  • 41.
    Drools Vision Cont.Event Processes Semantic Ontologies Workflows Rules Rules Workflows Event Processes Semantic Ontologies
  • 42.
    Drools History –Business Rule Engines 1980s 2010s 1990s 2000s OPS5 ART Clips Jess Drools 2 JRules Drools 3 Drools 4 Drools 5
  • 43.
    Drools History Drools2 Rete like XML Scripting language Drools 3 Based on Clips functionality
  • 44.
    Iterative improves toJRules syntax with Clips functionality Drools 4 More declarative
  • 45.
    Basic functional programmingfeature with “from”
  • 46.
  • 47.
    Basic BRMS Drools5 Improved functional programming with 'accumulate'
  • 48.
    More Advanced RuleFlow integration
  • 49.
    Complex Event ProcessTemporal Comparators
  • 50.
    Sliding Time WindowsProduction ready BRMS (Guvnor)
  • 51.
    Drools History Cont.Drools 5.1 Differential Diff (true modify) Drools 5.2 (this month, 5.2.0.CR1 available for download) Freeform expressions between patterns
  • 52.
  • 53.
  • 54.
    Decision tables andrule templates (Guvnor)
  • 55.
  • 56.
    Sample Industries andUsers Investment Millennium Investment Group (MIG) Logistics Fedex Airline Sabre Mortgage Franklin American Healthcare OSDE
  • 57.
    Drools at aglance - Declarative programming Production Rule Systems PRD (forward chaining) Reactive
  • 58.
    when Alarm( status== “alert” ) then send( “warning” ) Logic Programming LP (backward chaining) Query
  • 59.
    descendant( “mary”, “jane”)Functional Programming FP Map,Fold, Filter
  • 60.
    avg([12, 16, 4,6]) Returns single value 9.5 round([10.3, 4.7, 7.8] ) Returns List [10, 5, 8] Description Logic (model concepts, roles, and individuals) Person Has Name and lives at Address
  • 61.
    Drools Expert ata glance – Example A - SQL comparison example 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 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
  • 62.
    Drools Expert ata glance – Rules as a view 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
  • 63.
    Drools Expert ata glance – Example A - Building and executing rules
  • 64.
    Drools Expert ata glance – Example A Building and executing rules cont. Building Executing
  • 65.
    Drools Expert ata glance – Example B - Building and executing rules
  • 66.
    Drools Expert ata glance – Example B cont. No Fires Add some Fires
  • 67.
    Drools Expert ata glance – Example B cont. Fires are put out after a while
  • 68.
    Drools Expert ata glance – Conditional Elements
  • 69.
    Drools Expert ata glance – Accumulate CE Bus Example Accumulate general syntax Bus Example Revisited (no accumulate functions)
  • 70.
    Drools Expert ata glance – Conditional Elements From
  • 71.
    Drools Expert ata glance – Timers and Calendars Interval Timers 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 , - * / Cron-based Timers
  • 72.
    Drools Expert ata glance – Timers and Calendars Calendars Using Timers and Calendars together Execute now and after 1 hour duration on week days Execute now and after 4 hour duration on weekend days
  • 73.
    Drools Expert ata glance – Truth maintenance and Inference Issuing Buss passes – typical rule implementation Good practice to do: De-couple knowledge responsibilities
  • 74.
  • 75.
    Provide semantic abstractionsfor those encapsulation
  • 76.
    Integrity robustness –truth maintenance These types of implementations are considered Bad
  • 77.
  • 78.
  • 79.
    Brittle integrity -manual maintenance Couples the logic What happens when the Child becomes 16?
  • 80.
    Drools Expert ata glance – Truth maintenance and Inference cont. De-coupling knowledge responsibilities De-couples the logic Maintains the truth by automatically retracting. Rule “logically” inserts an object. When the rule is no longer true, the object is retracted. The truth maintenance cascades
  • 81.
    Drools Expert ata glance – Truth maintenance and Inference cont. Notification upon automatic fact retraction Executing The truth maintenance cascades
  • 82.
    Drools Expert ata glance – Roadmap Improved backward chaining (open queries)
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
    Runtime Management BAM(Business Activity Monitoring)
  • 89.
    Drools Guvnor ata glance Technology JCR 2.0 (JSR-170) backend
  • 90.
    Seam 2 +GWT frontend
  • 91.
  • 92.
  • 93.
    Role based securityAuthoring Decision Tables
  • 94.
    Guided Editor QAScenario Testing + Rule Verification
  • 95.
    Drools Guvnor ata glance – Business asset storage
  • 96.
    Drools Guvnor ata glance – Guided Editor
  • 97.
    Drools Guvnor ata glance – Decision Tables
  • 98.
    Drools Guvnor ata glance – Scenario Testing
  • 99.
    Drools Guvnor ata glance – BPMN2 processes
  • 100.
    Drools Guvnor ata glance – Compiling and exposing rule packages
  • 101.
    jBPM5 at aglance – What is BPM? Business Process Management A business process is a process that describes the order in which a series of steps need to be executed, using a flow chart.
  • 102.
    jBPM5 at aglance – Why BPM? Visibility
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
    jBPM5 at aglance – Key Characteristics Open-source business process management project offering: generic process engine supporting native BPMN 2.0 execution
  • 108.
  • 109.
    collaboration, management andmonitoring using web-based consoles
  • 110.
    powerful rules andevent integration Core engine is a workflow engine in pure Java state transitions
  • 111.
  • 112.
  • 113.
  • 114.
    jBPM5 at aglance – Core Engine // (1) Create knowledge base and add process definition KnowledgeBuilder kbuilder = ... kbuilder.add( ..., &quot;sample.bpmn&quot;, ResourceType.BPMN2); KnowledgeBase kbase = kbuilder.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); // (2) Create new stateful knowledge session StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); // (3) Start a new process instance ksession.startProcess(“com.sample.bpmn.hello”); Knowledge Base Stateful Knowledge Session Process Definition Process Instance
  • 115.
    jBPM5 at aglance – BPMN 2.0 OMG specification Model
  • 116.
  • 117.
  • 118.
  • 119.
    Extensible < definitions ... > < process id=&quot;com.sample.bpmn.hello&quot; name=&quot;Hello World&quot; > < startEvent id=&quot;_1&quot; name=&quot;StartProcess&quot; /> < sequenceFlow sourceRef=&quot;_1&quot; targetRef=&quot;_2&quot; /> < scriptTask id=&quot;_2&quot; name=&quot;Hello&quot; > < script >System.out.println(&quot;Hello World&quot;);</ script > </ scriptTask > < sequenceFlow sourceRef=&quot;_2&quot; targetRef=&quot;_3&quot; /> < endEvent id=&quot;_3&quot; name=&quot;EndProcess&quot; /> </ process > </ definitions > Core Engine BPMN 2.0 XML
  • 120.
    jBPM5 at aglance – Persistence and Transactions Persistence (JPA, pluggable) Runtime persistence
  • 121.
  • 122.
    Services Transactions (JTA,pluggable) Command-scoped
  • 123.
    User-defined Core EngineBPMN 2.0 XML Persistence Trans- actions JPA JTA
  • 124.
    jBPM5 at aglance – Console Web-based management
  • 125.
  • 126.
  • 127.
  • 128.
    Reporting Core EngineBPMN 2.0 XML Persistence Trans- actions Events History Log Management Console BAM
  • 129.
    jBPM5 at aglance – Console Domain-specific Processes: Extend palette with
  • 130.
  • 131.
    service nodes defineinput / output parameters
  • 132.
  • 133.
    Human task service(WS-HT) Task lists
  • 134.
    Task life cycleTask clients Task forms Core Engine BPMN 2.0 XML Persistence Trans- actions Events Integration Domain-specific Processes Human Task Service ESB
  • 135.
    jBPM5 at aglance – Roadmap jBPM 5.0: February 2011
  • 136.
    jBPM 5.1: NOW... Improve Oryx BPMN2 designer to support full round-tripping
  • 137.
  • 138.
    Lots of smallfeature improvements and bug fixes jBPM 5.2 – jBPM 6.x Simulation / testing / replay
  • 139.
  • 140.
  • 141.
    Focus on DroolsFusion (CEP) Brief introduction on CEP and Terminology
  • 142.
  • 143.
    Drools Fusion: ComplexEvent Processing extensions Event Declaration and Semantics
  • 144.
    Event Cloud, Streamsand the Session Clock
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
    Drools Fusion –What is an Event? “ An event is an observable occurrence .”
  • 150.
    “ An eventin the Unified Modelling Language is a notable occurrence at a particular point in time .”
  • 151.
  • 152.
    “ Anything that happens , or is contemplated as happening .”
  • 153.
    “ An object that represents, encodes or records an event , generally for the purpose of computer processing ”
  • 154.
    http://complexevents.com For thescope of this presentation:
  • 155.
    “ An eventis a significant change of state at a particular point in time ”
  • 156.
    Drools Fusion –What is a Complex Event? “ Complex Event , is an abstraction of other events called its members.” Examples : The 1929 stock market crash – an abstraction denoting many thousands of member events, including individual stock trades)
  • 157.
    The 2004 IndonesianTsunami – an abstraction of many natural events
  • 158.
    A completed stockpurchase -an abstraction of the events in a transaction to purchase the stock
  • 159.
    A successful on-lineshopping cart checkout – an abstraction of shopping cart events on an on-line website Source: http://complexevents.com
  • 160.
    Drools Fusion –What is Complex Event Processing (CEP)? “ Complex Event Processing , or CEP, is primarily an event processing concept that deals with the task of processing multiple events with the goal of identifying the meaningful events within the event cloud.
  • 161.
    CEP employstechniques such as detection of complex patterns of many events, event correlation and abstraction , event hierarchies, and relationships between events such as causality, membership, and timing, and event-driven processes.”
  • 162.
  • 163.
    Drools Fusion –CEP Scenarios Examples: Emergency Response Systems
  • 164.
  • 165.
  • 166.
    Neonatal ICU: infantvital signs monitoring A few characteristics of common CEP scenarios: Huge volume of events, but only a few of real interest Usually events are immutable
  • 167.
    Usually queries/rules haveto run in reactive mode
  • 168.
    Strong temporalrelationships between events Individual events are usually not important The composition and aggregation of events is important
  • 169.
    Drools Fusion –CEP vs. ESP Complex Event Processing , or CEP, and Event Stream Processing , or ESP, are two technologies that were born separate, but converged . An oversimplification : In their origins... Event Stream Processing focused on the ability to process high volume streams of events.
  • 170.
    Complex Event Processing focused on defining, detecting and processing the relationships among events. For the scope of this presentation:
  • 171.
    “ CEP is used as a common term meaning both CEP and ESP .”
  • 172.
    Drools Fusion –EDA “ Event Driven Architecture (EDA) is a software architecture pattern promoting the production , detection , consumption of, and reaction to events. An event can be defined as &quot;a significant change in state&quot;[1]. For example, when a consumer purchases a car, the car's state changes from &quot;for sale&quot; to &quot;sold&quot;. A car dealer's system architecture may treat this state change as an event to be produced, published, detected and consumed by various applications within the architecture.” http://en.wikipedia.org/wiki/Event_Driven_Architecture CEP is a component of the EDA
  • 173.
    Drools Fusion –EDA vs SOA EDA is **not** SOA 2.0
  • 174.
  • 175.
    Metaphor In our body : SOA is used to build our muscles and organs (what's needed to DO things)
  • 176.
    EDA is usedto build our sensory system (what's needed to REACT TO things)
  • 177.
    Drools Fusion –CEP Characteristics A few characteristics of common CEP scenarios: Huge volume of events, but only a few of real interest Usually events are immutable
  • 178.
    Usually queries/rules haveto run in reactive mode
  • 179.
    Strong temporalrelationships between events Individual events are usually not important The composition and aggregation of events is important
  • 180.
    Drools Fusion –Enables... Event Detection: From an event cloud or set of streams, select all the meaningful events, and only them. [Temporal] Event Correlation: Ability to correlate events and facts declaring both temporal and non-temporal constraints between them.
  • 181.
    Ability to reasonover event aggregation Event Abstraction: Ability to compose complex events from atomic events AND reason over them
  • 182.
    Drools Fusion –Features Features: Event Semantics as First Class Citizens
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
    Drools Fusion –Demo Twitter Stream CEP Demo: Listen to the Twitter Stream API Twitter4J API
  • 192.
    Listens to arandom sample of tweets Detects patterns and reacts Drools Fusion Simple one process (multi-thread) demo Focus on specific features
  • 193.
    Drools Fusion –Event Declaration and Semantics Event semantics: Point-in-time and Interval An event is a fact with a few special characteristics: Usually immutable , but not enforced
  • 194.
    Strong temporal relationships Lifecycle may be managed Allow use of sliding windows “ All events are facts , but not all facts are events.”
  • 195.
    Demo twitter rulespart 1, 2, 3) // declaring existing class import some.package.VoiceCall declare VoiceCall @role ( event ) @timestamp ( calltime ) @duration ( duration ) end // generating an event class declare StockTick @role ( event ) symbol : String price : double end
  • 196.
    Drools Fusion –Temporal Reasoning Semantics for: time: discrete
  • 197.
    events: point-in-time and interval Ability to express temporal relationships: Allen’s 13 temporal operators James F. Allen defined the 13 possible temporal relations between two events.
  • 198.
    Eiko Yoneki and Jean Bacon defined a unified semantics for event correlation over time and space.
  • 199.
    Drools Fusion –Temporal Relationships rule “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
  • 200.
    Drools Fusion –Allen’s 13 Temporal Operators Point-Point Point-Interval Interval-Interval A before B A meets B A overlaps B A finishes B A includes B A starts B A coincides B A B A B A B A B A B A B A B
  • 201.
    Drools Fusion –Allen’s 13 Temporal Operators Point-Point Point-Interval Interval-Interval A after B A metBy B A overlapedBy B A finishedBy B A during B A finishes B Demo twitter rules part 4 A B A B A B A B A B A B
  • 202.
    Drools Fusion –Streams : Simple Example Scenario
  • 203.
    Drools Fusion –Stream Support (entry-points) A scoping abstraction for stream support Rule compiler gather all entry-point declarations and expose them through the session API
  • 204.
    Engine manages allthe scoping and synchronization behind the scenes. rule “Stock Trade Correlation” when
  • 205.
    $c :Customer( type == “VIP” )
  • 206.
    BuyOrderEvent( customer == $c , $id : id ) from entry-point “Home Broker Stream”
  • 207.
    BuyAckEvent( sourceEvent == $id ) from entry-point “Stock Trader Stream”
  • 208.
  • 209.
  • 210.
  • 211.
    No notionof “flow of time” : the engine sees all facts without regard to time
  • 212.
  • 213.
    No requirementson event ordering
  • 214.
    No automatic event lifecycle management
  • 215.
    No sliding window support Notion of “flow of time” : concept of “now”
  • 216.
    Session Clock has an active role synchronizing the reasoning
  • 217.
  • 218.
    Automatic eventlifecycle management
  • 219.
  • 220.
    Automatic ruledelaying on absence of facts Drools Fusion – Cloud Mode, Stream Mode, Session Clock CLOUD STREAM
  • 221.
    Drools Fusion –Reference Clock Reference clock defines the flow of time Named Session Clock is assigned to each session created Synchronizes time sensitive operations duration rules
  • 222.
  • 223.
  • 224.
  • 225.
    Drools Fusion –Session Clock Uses the strategy pattern and multiple implementations: Real-time operation
  • 226.
  • 227.
  • 228.
  • 229.
    Drools Fusion –Session Clock Selecting the session clock: API: KnowledgeSessionConfiguration conf = ...
  • 230.
    conf.setOption( ClockTypeOption.get( “realtime”) ); System Property or Configuration File: drools.clockType = pseudo
  • 231.
    Drools Fusion –Sliding Window Support Allows reasoning over a moving window of “interest” Time
  • 232.
    Length Sliding window1 Sliding window 2
  • 233.
    Drools Fusion –Sliding Window Support Allows reasoning over a moving window of “interest” Time
  • 234.
    Length Sliding window1 Sliding window 2 Joined window
  • 235.
    Drools Fusion –Sliding Window Support Allows reasoning over a moving window of “interest” Time
  • 236.
    Length Demo twitterrules part 5 rule “Average Order Value over 12 hours” when $c : Customer() $a : Number() from accumulate ( BuyOrder( customer == $c , $p : price ) over window:time ( 12h ),
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
    Drools Fusion –Delaying Rules Negative 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 Forces the rule to wait for 30 seconds before firing, because the acknowledgement may arrive at any time!
  • 242.
    Drools Fusion –Temporal Dimension Requires the support to the temporal dimension A rule/query might match in a given point in time, and not match in the subsequent point in time That is the single most difficult requirement to support in a way that the engine: stays deterministic
  • 243.
    stays a high-performanceengine Achieved mostly by compile time optimizations that enable: constraint tightening
  • 244.
  • 245.
  • 246.
    Drools Fusion –Temporal Dimension Support CEP scenarios are stateful by nature.
  • 247.
    Events usually areonly interesting during a short period of time .
  • 248.
    Hard for applicationsto know when events are not necessary anymore Temporal constraints and sliding windows describe such “ window of interest ”
  • 249.
    Drools Fusion –Simple Example Rule rule “Bag was lost” when $b : BagScannedEvent() from entry-point “check-in” not BagScannedEvent( id == $b.id , this after[0s,5m] $b ) from entry-point “pre-load”
  • 250.
  • 251.
    // Bag waslost, do something
  • 252.
    end Easy to“see” that the only temporal relationship between the events defines a 5 minutes interest window.
  • 253.
    Drools Fusion –Abstract Example Rule rule “Abstract event relationship example” when $a : A() $b : B( this after[-2, 2] $a ) $c : C( this after[-3, 4] $a ) $d : D( this after[ 1, 2] $b, this after[2,3] $c ) not E( this after[ 1,10] $d ) then // Bag was lost, do something end How about now? What is the temporal relationship between A and E?
  • 254.
    Drools Fusion –Temporal Dependency Matrix A B C D E A [ 0, 0 ] [ -2, 2 ] [ -3, 2 ] [ -1, 4 ] [ 0, 14 ] B [ -2, 2 ] [ 0, 0 ] [ -2, 0 ] [ 1, 2 ] [ 2, 12 ] C [ -2, 3 ] [ 0, 2 ] [ 0, 0 ] [ 2, 3 ] [ 3, 13 ] D [ -4, 1 ] [ -2, -1 ] [ -3, -2 ] [ 0, 0 ] [ 1, 10 ] E [ -14, 0 ] [ -12, -2 ] [ -13, -3 ] [-10,-1 ] [ 0, 0 ] Constraint tightening Demo twitter rules part 6 [-2,2] [-3,4] [2,3] [1,2] [1,10] A D B E C
  • 255.
    Q&A Drools projectsite: http://www.drools.org ( http://www.jboss.org/drools/ ) Documentation: http://www.jboss.org/drools/documentation.html Tihomir Surdilovic – tsurdilo @redhat.com