Drools Ecosystem
-
Upload
saumitra-srivastav -
Category
Technology
-
view
179 -
download
3
description
Transcript of Drools Ecosystem
Drools Ecosystem
Saumitra Srivastav@_saumitra_
1
2
Components
1. Drools Expert2. Drools Guvnor3. Drools Fusion4. KIE Workbench5. jBPM6. Optaplanner
3
Drools Expert
4
Drools Expert
• Provides a declarative, rule based, coding environment
• Rules(.drl files) can be combined in packages• allows imports, globals, functions, queries, rules
rule "name" attributes when LHS then RHSend
5
Custom Types
• Create new Types and use them
declare Person name : String dateOfBirth : java.util.Date address : Addressend
rule "Using a declared Type"when $p : Person( name == "Bob" )then Person mark = new Person(); mark.setName("Mark"); insert( mark );end
6
Defining DSL• Supports defining DSL • Syntax:
• Example: Using this DSL,
One can define a rule as:
[when]Something is {colour} = Something(colour=="{colour}")
[when]There is a person with name of "{name}"=Person(name=="{name}")[when]Person is at least {age} years old and lives in "{location}"= Person(age >= {age}, location=="{location}")[then]Log "{message}"=System.out.println("{message}");[when]And = and
There is a person with name of "Kitty" ==> Person(name="Kitty")Person is at least 42 years old and lives in "Atlanta" ==> Person(age >= 42, location="Atlanta")Log "boo" ==> System.out.println("boo");There is a person with name of "Bob" and Person is at least 30 years old and lives in "Utah" ==> Person(name="Bob") and Person(age >= 30, location="Utah")
7
Drools Guvnor
8
Drools Guvnor
• Centralized repository for Drools Knowledge Bases
• Provide GUI tools to aid in management of large number of rules.
• Guvnor helps in:1. Access control2. Version control3. Provide GUI for non-programmers to edit rules
9
Drools Fusion
10
Drools Fusion
• Adds event processing capabilities into the drools platform
• Provides 2 modes:• Cloud Mode• Stream Mode
• Sliding window support
• Stream support• allows defining entry points
• Memory management
• Temporal Reasoning
11
Event Processing – Cloud Mode
• Its default processing mode
• when running in CLOUD mode, no notion of flow of time
• it is not possible for the engine to determine how "old" the event is, because there is no concept of "now".
• The engine looks at the events as an unordered cloud against which the engine tries to match rules.
• no automatic life-cycle management for events• application must explicitly delete events when they are no longer
necessary
12
Event Processing – Stream Mode
• In this mode, engine uses a session clock to force synchronization between streams
• session clock is responsible for keeping the current timestamp, while helps in:• determining event age• do temporal calculations• synchronizes streams from multiple sources• schedules future tasks
• Two types of clocks:• Realtime
• Uses system clock• Pseudo
• Controlled by app, useful for dev
13
Negative Patterns in Stream Mode
• In STREAM mode, negative patterns(with time constraints) may require the engine to wait for a time period before activating a rule.
• Without time constraints
• With time constraints
rule "Sound the alarm"when $f : FireDetected( ) not( SprinklerActivated( ) )then // sound the alarmend
rule "Sound the alarm"when $f : FireDetected( ) not( SprinklerActivated( this after[0s,10s] $f ) )then // sound the alarmend
14
Negative Patterns in Stream Mode
• A rule that expects every 10 seconds at least one “Heartbeat” event, if not the rule fires.
rule "Sound the alarm" duration( 10s )when $f : FireDetected( ) not( SprinklerActivated( this after[0s,10s] $f ) )then // sound the alarmend
15
Entry points
• Entry points can be used so that a rules matches only selective events
rule "Sound the alarm in Bangalore"when $f : FireDetected( ) from “Bangalore-Office” not( SprinklerActivated())then // sound the alarmend
rule "Sound the alarm in US"when $f : FireDetected( ) from “US-Office” not( SprinklerActivated())then // sound the alarmend
WorkingMemoryEntryPoint entryPoint1 = session.getWorkingMemoryEntryPoint(“US-office");entryPoint1.insert(fact);
16
Sliding Windows
• Supports 2 sliding window implementations:• Sliding time windows• Sliding length windows
• Time - Fire rules on events which occurred in last 2 mins
whenEvent() over window:time( 2m )
then
rule "Sound the alarm in case temperature rises above threshold"when TemperatureThreshold( $max : max ) Number( doubleValue > $max ) from accumulate( SensorReading( $temp : temperature ) over window:time( 10m ), average( $temp ) )then // sound the alarmend
17
Sliding Time Windows
• Fire rules on events which occurred in last 2 mins
• sound an alarm in case the average temperature over the last 10 minutes read from a sensor is above the threshold value
whenEvent() over window:time( 2m )
then
rule "Sound the alarm in case temperature rises above threshold"when TemperatureThreshold( $max : max ) Number( doubleValue > $max ) from accumulate( SensorReading( $temp : temperature ) over window:time( 10m ), average( $temp ) )then // sound the alarmend
18
Sliding Length Windows
• Sliding length implementation consider events based on order of their insertion into the session
• sound an alarm in case the average temperature for last 100 entries from sensor is above the threshold value
whenEvent(type == “securitylogs”) over window:length( 10 )
then
rule "Sound the alarm in case temperature rises above threshold"when TemperatureThreshold( $max : max ) Number( doubleValue > $max ) from accumulate( SensorReading( $temp : temperature ) over window:length( 100 ), average( $temp ) )then // sound the alarmend
19
Memory Management for Events
1. Explicit expiration offset
2. Inferred expiration offset
declare Event @expires( 30m )end
rule "correlate orders"when $bo : BuyOrderEvent( $id : id ) $ae : AckEvent( id == $id, this after[0,10s] $bo )then // do somethingend
20
Temporal Reasoning operators
• Drools implements all 13 temporal operators defined in Allen’s paper
• Example:match if and only if the temporal distance between the time when, eventB finished and the time when $eventA started is between ( 3 minutes and 30 seconds ) and ( 4 minutes ).
After, before, coincides, during, finishes, finished by, includes, meets, met by, overlaps, overlapped by, starts, started by
$eventA : EventA( this after[ 3m30s, 4m ] $eventB )
21
jBPM
22
jBPM
• a flexible Business Process Management (BPM) Suite.
• offers process management features suited for both business users and developers
• allows you to model your business goals using flowcharts
• Domain-specific nodes can be plugged to make the processes more easily understood by business users.
• Eclipse-based and web-based editor
• History logging (for querying / monitoring / analysis)
• Optional process repository to deploy your process (and other related knowledge)
23
KIE Workbench Demo
24
Thanks
• http://www.jboss.org/drools.html• http://
docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html/index.html
Questions?