22. It All Started Here Birth of CDSS Clinical Decision Support Systems 1970s 1980s Dendral Baobab Mycin Guidon Neomycin Teiresias Puff Emycin WM Sacon Centaur Wheeze Gravida Clot Oncocin
52. 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
53. 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”
54. 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 { }
55. Definitions rule "When there is a fire turn on the sprinkler" when Fire ($room : room) $sprinkler : Sprinkler ( room == $room, on == false ) then modify ( $sprinkler ) { on = true }; println ( "Turn on the sprinkler for room " + $room.name ); end rule "When the fire is gone turn off the sprinkler" when $room : Room ( ) $sprinkler : Sprinkler ( room == $room, on == true ) not Fire ( room == $room ) then modify ( $sprinkler ) { on = false }; println ( "Turn off the sprinkler for room " + $room.name ); end
56. Definitions rule "Raise the alarm when we have one or more fires" when exists Fire () then insert ( new Alarm () ); println ( "Raise the alarm" ); end rule "Cancel the alarm when all the fires have gone" when not Fire () $alarm : Alarm () then retract ( $alarm ); println ( "Cancel the alarm" ); end
57. Definitions rule "Status output when things are ok" when not Alarm () not Sprinkler ( on == true ) then println ( "Everything is ok" ); end
58. Executing String [] names = new String []{ "kitchen" , "bedroom" , "office" , "livingroom" }; 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
59. Executing Fire kitchenFire = new Fire ( name2room.get( "kitchen" ) ); Fire officeFire = new Fire ( name2room.get( "office" ) ); 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
60. 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 "Status output when things are ok" when not Alarm () not Sprinkler ( on == true ) then println ( "Everything is ok" ); end
61. 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” ) )
62. Accumulate CE rule "accumulate" when $sum : Number( intValue > 100 ) from accumulate ( Bus( color == "red" , $t : takings ) sum( $t ) ) then print "sum is “ + $sum; end
63. Accumulate CE Patterns and CE's can be chained with ' from ' rule "collect" when $zipCode : ZipCode() $sum : Number( intValue > 100 ) from accumulate ( Bus( color == "red" , $t : takings ) from $hbn.getNamedQuery( “Find Buses” ) .setParameters( [ “zipCode” : $zipCode ] ) .list(), sum( $t ) ) then print "sum is “ + $sum; end
64. 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
65. Calendars rule "weekdays are high priority" calendars "weekday" timer (int:0 1h) when Alarm() then send( "priority high - we have an alarm” ); end rule "weekend are low priority" calendars "weekend" timer (int:0 4h) when Alarm() then send( "priority low - we have an alarm” ); end Execute now and after 1 hour duration Execute now and after 4 hour duration
66. 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, "keys" ; ) then System.out.println( "We have found your keys" ); end
74. Event Driven Architecture (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 "a significant change in state"[1]. For example, when a consumer purchases a car, the car's state changes from "for sale" to "sold". 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.”
80. $c : Custumer( type == “VIP ) BuyOrderEvent( customer == $c ) from entry-point “Home Broker Stream” Scalability EntryPoint entryPoint = session. getEntryPoint ( “Home Broker Stream” ); entryPoint.insert( event ) ; So lets allow multiple named entry points for those streams So now we can insert different streams concurrently Patterns can now optional specify their entry-point. When not specified uses the “default” entry-point
81. declare StockTick @role( event ) end declare StockTick @role( event ) @timestamp( timestampAttr ) companySymbol : String stockPrice : double timestampAttr : long end Automatic Life-Cycle Management Just use the declare statement to declare a type as an event and it will be retracted when it is no longer needed The declare statement can also specify an internal model, that external objects/xml/csv map on to. We support Smooks and JAXB
95. $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
96. 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
97. Aggregations acc ( $s : StockTicker( symbol == “RHAT” ) over window:time ( 5s ); $min : min ( $s.price ), $min : min ( $s.price ), $avg : avg ( $s.price ); $min > 10 && $max < 20 && $avg > 16 ) Over 5 seconds functions Accumlate over data Guard constraint
98. 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
103. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
104. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
105. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
106. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
107. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
108. CEP Applied at FedEx Custom Critical * Presented by Adam Mollemkopf at ORF 2009
109.
110.
111.
112.
113.
114. 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 Couples the logic What happens when the Child stops being 16?
119. When the rule is no longer true, the object is retracted. 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
120. 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" when $p : Person ( age >= 16 ) IsAdult ( person == $p ) then logicalInsert ( new AdultBusPass ( $p ) ); end The truth maintenance cascades
121. TMS and Inference rule "Issue Child Bus Pass" when $p : Person ( ) not ( ChildBusPass ( person == $p ) ) then requestChildBusPass( $p ); end The truth maintenance cascades
160. If the same actions exist for rules covering all condition states for a given condition they can be combined and the condition state becomes irrelevant.
239. Self monitoring and adaptive declare ProcessStartedEvent @role( event ) end rule "Number of process instances above threshold" when Number( nbProcesses : intValue > 1000 ) from accumulate( e: ProcessStartedEvent( processInstance.processId == "com.sample.order.OrderProcess" ) over window:size(1h), count(e) ) then System.err.println( "WARNING: Nb of order processes in the last hour > 1000: " + nbProcesses ); end
244. Interception When StockMark status == crash Then Terminate “Buy Request” Process Start “System Shutdown” Process Stock Buy Order Request Buy Order Acknowledgement Buy Order Request Process Payment Confirmation Terminate
245. Interception and Redirection When Origin != USA and Destination == USA Then Suspend “Flight Booking” Process Start “ESTA” Process OnSuccess Resume “Flight Booking” OnFailure Terminate “Flight Booking” Simple Flight Booking Process Get Destination Get Dates Get Origin Process Payment Confirmation Terminate
249. HAL : Without your space helmet, Dave, you're going to find that rather difficult.
250. Dave Bowman : HAL, I won't argue with you anymore! Open the doors!
251. HAL : Dave, this conversation can serve no purpose anymore. Goodbye. 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?