SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
by Mario Fusco
Red Hat – Senior Software Engineer
mario.fusco@gmail.com
twitter: @mariofusco
Introducing
Drools Vision
Drools was born as a rule engine, but following the vision of
becoming a single platform for business modelling, it realized
it could achieve this goal only by leveraging 3 complementary
business modelling techniques:
• Business Rule Management (Drools Expert)
• Business Process Management (Drools Flow)
• Complex Event Processing (Drools Fusion)
Business Logic integration System
Drools 5 – Business Logic Integration Platform
Drools
Guvnor
Drools
Fusion
Drools
Flow
Drools
Expert
Drools
Planner
What a rule-based program is
• A rule-based program is made up of discrete rules, each of
which applies to some subset of the problem
• It is simpler, because you can concentrate on the rules for one
situation at a time
• It can be more flexible in the face of fragmentary or poorly
conditioned inputs
• Used for problems involving control, diagnosis, prediction,
classification, pattern recognition … in short, all problems
without clear algorithmic solutions
Declarative
(What to do)
Imperative
(How to do it)
Vs.
When should you use a Rule Engine?
• The problem is beyond any obvious algorithmic solution or
it isn't fully understood
• The logic changes often
• Domain experts (or business analysts) are readily available,
but are nontechnical
• You want to isolate the key parts of your business logic,
especially the really messy parts
How a rule-based system works
Rule's anatomy
rule “<name>”
<attribute> <value>
when
<LHS>
then
<RHS>
end
Quotes on Rule names are optional
if the rule name has no spaces.
salience <int>
agenda-group <string>
no-loop <boolean>
auto-focus <boolean>
duration <long>
....
Pattern-matching
against objects in the
Working Memory
Code executed when
a match is found
Imperative vs Declarative
public void helloMark(Person person) {
if ( person.getName().equals( “mark” ) {
System.out.println( “Hello Mark” );
}
}
rule “Hello Mark”
when
Person( name == “mark” )
then
System.out.println( “Hello Mark” );
end
A method must be called directly Specific passing
of arguments
Rules can never be called directly Specific instances cannot be
passed but are automatically
selected with pattern-matching
What is a pattern
Person( name == “mark” )
Pattern
Object Type Field Constraint
Field Name Restriction
Rule's definition
// Java
public class Applicant {
private String name;
private int age;
private boolean valid;
// getter and setter here
}
rule "Is of valid age" when
$a : Applicant( age >= 18 )
then
modify( $a ) { valid = true };
end
// DRL
declare Applicant
name : String
age : int
valid : boolean
end
Building
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(
ResourceFactory.newClassPathResource("Rules.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (kbuilder.hasErrors()) {
System.err.println(kbuilder.getErrors().toString());
}
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
Executing
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
Applicant applicant = new Applicant( "Mr John Smith", 21 );
assertFalse( applicant.isValid() );
ksession.execute( applicant );
assertTrue( applicant.isValid() );
More Pattern Examples
Person( $age : age )
Person( age == ( $age + 1 ) )
Person(age > 30 && < 40 || hair in (“black”, “brown”) )
Person(pets contain $rover )
Person(pets[’rover’].type == “dog”)
Conditional Elements
not Bus( color = “red” )
exists Bus( color = “red” )
forall ( $bus : Bus( color == “red” ) )
$owner : Person( name == “mark” )
Pet( name == “rover” ) from $owner.pets
$zipCode : ZipCode()
Person( ) from $hbn.getNamedQuery(“Find People”)
.setParameters( [ “zipCode” : $zipCode ] )
.list()
Hibernate session
'from' can work
on any expression
Timers & Calendars
rule R1
timer 1m30s
when
$l : Light( status == “on” )
then
modify( $l ) { status = “off” };
When the light is on, and has been
on for 1m30s then turn it off
Send alert every
quarter of an hour
Execute now and after
1 hour duration only during weekday
rule R3
calendars "weekday"
timer (int:0 1h)
when
Alarm()
then
sendEmail( ”Alert!” )
rule R2
timer ( cron: 0 0/15 * * * * )
when
Alarm()
then
sendEmail( ”Alert!” )
Truth Maintenance System (1)
rule "Issue Adult Bus Pass" when
$p : Person( age >= 18 )
then
insert(new AdultBusPass( $p ) );
end
rule "Issue Child Bus Pass" when
$p : Person( age < 18 )
then
insert(new ChildBusPass( $p ) );
end
Coupled logic
What happens
when the child
becomes adult?
Truth Maintenance System (2)
rule "Who Is Child" when
$p : Person( age < 18 )
then
logicalInsert( new IsChild( $p ) )
end
rule "Issue Child Bus Pass" when
$p : Person( )
IsChild( person =$p )
then
logicalInsert(new ChildBusPass( $p ) );
end
De-couples the logic
Maintains the truth by
automatically retracting
Encapsulate
knowledge providing
semantic abstractions
for this encapsulation
Drools Eclipse
DEMO
Complex Event Processing
Event
A record of state change in the application domain at a
particular point in time
Complex Event
An abstraction of other events called its members
Complex Event Processing
Processing multiple events with the goal of identifying
the meaningful events within the event cloud
Drools Fusion
• Drools modules for Complex Event Processing
• Understand and handle events as a first class
platform citizen (actually special type of Fact)
• Select a set of interesting events in a cloud or
stream of events
• Detect the relevant relationship (patterns)
among these events
• Take appropriate actions based on the
patterns detected
Events as Facts in Time
rule
"Sound the alarm"
when
$f : FireDetected( )
not( SprinklerActivated( this after[0s,10s] $f ) )
then
// sound the alarm
end
Temporal
relationships
between events
Workflows as Business Processes
A workflow is a process that describes the
order in which a series of steps need to be
executed, using a flow chart.
Drools Flow (aka jBPM5)
• Allows to model business processes
• Eclipse-based editor to support workflows
graphical creation
• Pluggable persistence and transaction based
on JPA / JTA
• Based on BPMN 2.0 specification
• Can be used with Drools to model your
business logic as combination of processes,
events and rules
Drools Guvnor
• Centralised repository for Drools Knowledge
Bases
• Web based GUIs
• ACL for rules and other artifacts
• Version management
• Integrated testing
Drools Planner
• Works on all kinds of planning problems
– NP-complete
– Hard & soft constraints
– Huge search space
• Planning constraints can be weighted and are
written as declarative score rules
• The planner algorithm is configurable. It searches
through the solutions within a given amount of
time and returns the best solution found
Mario Fusco
Red Hat – Senior Software Engineer
mario.fusco@gmail.com
twitter: @mariofusco
Q A

Mais conteúdo relacionado

Mais procurados

Drools Expert and Fusion Intro : London 2012
Drools Expert and Fusion Intro  : London 2012Drools Expert and Fusion Intro  : London 2012
Drools Expert and Fusion Intro : London 2012Mark Proctor
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Rule Engine: Drools .Net
Rule Engine: Drools .NetRule Engine: Drools .Net
Rule Engine: Drools .NetGuo Albert
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript BasicsMindfire Solutions
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...Edureka!
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginnersjeroenvdmeer
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects WebStackAcademy
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 

Mais procurados (20)

Drools Expert and Fusion Intro : London 2012
Drools Expert and Fusion Intro  : London 2012Drools Expert and Fusion Intro  : London 2012
Drools Expert and Fusion Intro : London 2012
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
django
djangodjango
django
 
Introducing Kogito
Introducing KogitoIntroducing Kogito
Introducing Kogito
 
Rule Engine: Drools .Net
Rule Engine: Drools .NetRule Engine: Drools .Net
Rule Engine: Drools .Net
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Drools expert-docs
Drools expert-docsDrools expert-docs
Drools expert-docs
 
Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Json Tutorial
Json TutorialJson Tutorial
Json Tutorial
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 

Semelhante a Introducing Drools

Drools Introduction
Drools IntroductionDrools Introduction
Drools IntroductionJBug Italy
 
Developing applications with rules, workflow and event processing (it@cork 2010)
Developing applications with rules, workflow and event processing (it@cork 2010)Developing applications with rules, workflow and event processing (it@cork 2010)
Developing applications with rules, workflow and event processing (it@cork 2010)Geoffrey De Smet
 
Drools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP IntroductionDrools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP IntroductionMauricio (Salaboy) Salatino
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...Mario Fusco
 
10 ways to make your code rock
10 ways to make your code rock10 ways to make your code rock
10 ways to make your code rockmartincronje
 
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTEJBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTEtsurdilovic
 
Buenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationBuenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationMark Proctor
 
Crash Wars - The handling awakens
Crash Wars  - The handling awakensCrash Wars  - The handling awakens
Crash Wars - The handling awakensŽeljko Plesac
 
Droolsand Rule Based Systems 2008 Srping
Droolsand Rule Based Systems 2008 SrpingDroolsand Rule Based Systems 2008 Srping
Droolsand Rule Based Systems 2008 SrpingSrinath Perera
 
JBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule EngineJBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule EngineAnil Allewar
 
Real time stream processing presentation at General Assemb.ly
Real time stream processing presentation at General Assemb.lyReal time stream processing presentation at General Assemb.ly
Real time stream processing presentation at General Assemb.lyVarun Vijayaraghavan
 
Drools New York City workshop 2011
Drools New York City workshop 2011Drools New York City workshop 2011
Drools New York City workshop 2011Geoffrey De Smet
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patternsPascal Larocque
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonCodemotion
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info SheetMark Proctor
 

Semelhante a Introducing Drools (20)

Drools Introduction
Drools IntroductionDrools Introduction
Drools Introduction
 
Developing applications with rules, workflow and event processing (it@cork 2010)
Developing applications with rules, workflow and event processing (it@cork 2010)Developing applications with rules, workflow and event processing (it@cork 2010)
Developing applications with rules, workflow and event processing (it@cork 2010)
 
Drools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP IntroductionDrools5 Community Training Module#1: Drools5 BLiP Introduction
Drools5 Community Training Module#1: Drools5 BLiP Introduction
 
Complex Event Processing
Complex Event ProcessingComplex Event Processing
Complex Event Processing
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
10 ways to make your code rock
10 ways to make your code rock10 ways to make your code rock
10 ways to make your code rock
 
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTEJBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
 
Buenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationBuenos Aires Drools Expert Presentation
Buenos Aires Drools Expert Presentation
 
Crash Wars - The handling awakens
Crash Wars  - The handling awakensCrash Wars  - The handling awakens
Crash Wars - The handling awakens
 
Droolsand Rule Based Systems 2008 Srping
Droolsand Rule Based Systems 2008 SrpingDroolsand Rule Based Systems 2008 Srping
Droolsand Rule Based Systems 2008 Srping
 
JBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule EngineJBoss Drools - Pure Java Rule Engine
JBoss Drools - Pure Java Rule Engine
 
Real time stream processing presentation at General Assemb.ly
Real time stream processing presentation at General Assemb.lyReal time stream processing presentation at General Assemb.ly
Real time stream processing presentation at General Assemb.ly
 
Drools New York City workshop 2011
Drools New York City workshop 2011Drools New York City workshop 2011
Drools New York City workshop 2011
 
Stop that!
Stop that!Stop that!
Stop that!
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patterns
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info Sheet
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 

Mais de Mario Fusco

Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automationMario Fusco
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APIMario Fusco
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerMario Fusco
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Mario Fusco
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVMMario Fusco
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondMario Fusco
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingMario Fusco
 
Real world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same languageReal world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same languageMario Fusco
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardMario Fusco
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife SpringMario Fusco
 
No more loops with lambdaj
No more loops with lambdajNo more loops with lambdaj
No more loops with lambdajMario Fusco
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 

Mais de Mario Fusco (20)

Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java API
 
OOP and FP
OOP and FPOOP and FP
OOP and FP
 
Lazy java
Lazy javaLazy java
Lazy java
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVM
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Monadic Java
Monadic JavaMonadic Java
Monadic Java
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
 
Real world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same languageReal world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same language
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
 
No more loops with lambdaj
No more loops with lambdajNo more loops with lambdaj
No more loops with lambdaj
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Introducing Drools

  • 1. by Mario Fusco Red Hat – Senior Software Engineer mario.fusco@gmail.com twitter: @mariofusco Introducing
  • 2. Drools Vision Drools was born as a rule engine, but following the vision of becoming a single platform for business modelling, it realized it could achieve this goal only by leveraging 3 complementary business modelling techniques: • Business Rule Management (Drools Expert) • Business Process Management (Drools Flow) • Complex Event Processing (Drools Fusion)
  • 3. Business Logic integration System Drools 5 – Business Logic Integration Platform Drools Guvnor Drools Fusion Drools Flow Drools Expert Drools Planner
  • 4. What a rule-based program is • A rule-based program is made up of discrete rules, each of which applies to some subset of the problem • It is simpler, because you can concentrate on the rules for one situation at a time • It can be more flexible in the face of fragmentary or poorly conditioned inputs • Used for problems involving control, diagnosis, prediction, classification, pattern recognition … in short, all problems without clear algorithmic solutions Declarative (What to do) Imperative (How to do it) Vs.
  • 5. When should you use a Rule Engine? • The problem is beyond any obvious algorithmic solution or it isn't fully understood • The logic changes often • Domain experts (or business analysts) are readily available, but are nontechnical • You want to isolate the key parts of your business logic, especially the really messy parts
  • 6. How a rule-based system works
  • 7. Rule's anatomy rule “<name>” <attribute> <value> when <LHS> then <RHS> end Quotes on Rule names are optional if the rule name has no spaces. salience <int> agenda-group <string> no-loop <boolean> auto-focus <boolean> duration <long> .... Pattern-matching against objects in the Working Memory Code executed when a match is found
  • 8. Imperative vs Declarative public void helloMark(Person person) { if ( person.getName().equals( “mark” ) { System.out.println( “Hello Mark” ); } } rule “Hello Mark” when Person( name == “mark” ) then System.out.println( “Hello Mark” ); end A method must be called directly Specific passing of arguments Rules can never be called directly Specific instances cannot be passed but are automatically selected with pattern-matching
  • 9. What is a pattern Person( name == “mark” ) Pattern Object Type Field Constraint Field Name Restriction
  • 10. Rule's definition // Java public class Applicant { private String name; private int age; private boolean valid; // getter and setter here } rule "Is of valid age" when $a : Applicant( age >= 18 ) then modify( $a ) { valid = true }; end // DRL declare Applicant name : String age : int valid : boolean end
  • 11. Building KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newClassPathResource("Rules.drl"), ResourceType.DRL); KnowledgeBuilderErrors errors = kbuilder.getErrors(); if (kbuilder.hasErrors()) { System.err.println(kbuilder.getErrors().toString()); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
  • 12. Executing StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession(); Applicant applicant = new Applicant( "Mr John Smith", 21 ); assertFalse( applicant.isValid() ); ksession.execute( applicant ); assertTrue( applicant.isValid() );
  • 13. More Pattern Examples Person( $age : age ) Person( age == ( $age + 1 ) ) Person(age > 30 && < 40 || hair in (“black”, “brown”) ) Person(pets contain $rover ) Person(pets[’rover’].type == “dog”)
  • 14. Conditional Elements not Bus( color = “red” ) exists Bus( color = “red” ) forall ( $bus : Bus( color == “red” ) ) $owner : Person( name == “mark” ) Pet( name == “rover” ) from $owner.pets $zipCode : ZipCode() Person( ) from $hbn.getNamedQuery(“Find People”) .setParameters( [ “zipCode” : $zipCode ] ) .list() Hibernate session 'from' can work on any expression
  • 15. Timers & Calendars rule R1 timer 1m30s when $l : Light( status == “on” ) then modify( $l ) { status = “off” }; When the light is on, and has been on for 1m30s then turn it off Send alert every quarter of an hour Execute now and after 1 hour duration only during weekday rule R3 calendars "weekday" timer (int:0 1h) when Alarm() then sendEmail( ”Alert!” ) rule R2 timer ( cron: 0 0/15 * * * * ) when Alarm() then sendEmail( ”Alert!” )
  • 16. Truth Maintenance System (1) rule "Issue Adult Bus Pass" when $p : Person( age >= 18 ) then insert(new AdultBusPass( $p ) ); end rule "Issue Child Bus Pass" when $p : Person( age < 18 ) then insert(new ChildBusPass( $p ) ); end Coupled logic What happens when the child becomes adult?
  • 17. Truth Maintenance System (2) rule "Who Is Child" when $p : Person( age < 18 ) then logicalInsert( new IsChild( $p ) ) end rule "Issue Child Bus Pass" when $p : Person( ) IsChild( person =$p ) then logicalInsert(new ChildBusPass( $p ) ); end De-couples the logic Maintains the truth by automatically retracting Encapsulate knowledge providing semantic abstractions for this encapsulation
  • 19. Complex Event Processing Event A record of state change in the application domain at a particular point in time Complex Event An abstraction of other events called its members Complex Event Processing Processing multiple events with the goal of identifying the meaningful events within the event cloud
  • 20. Drools Fusion • Drools modules for Complex Event Processing • Understand and handle events as a first class platform citizen (actually special type of Fact) • Select a set of interesting events in a cloud or stream of events • Detect the relevant relationship (patterns) among these events • Take appropriate actions based on the patterns detected
  • 21. Events as Facts in Time rule "Sound the alarm" when $f : FireDetected( ) not( SprinklerActivated( this after[0s,10s] $f ) ) then // sound the alarm end Temporal relationships between events
  • 22. Workflows as Business Processes A workflow is a process that describes the order in which a series of steps need to be executed, using a flow chart.
  • 23. Drools Flow (aka jBPM5) • Allows to model business processes • Eclipse-based editor to support workflows graphical creation • Pluggable persistence and transaction based on JPA / JTA • Based on BPMN 2.0 specification • Can be used with Drools to model your business logic as combination of processes, events and rules
  • 24. Drools Guvnor • Centralised repository for Drools Knowledge Bases • Web based GUIs • ACL for rules and other artifacts • Version management • Integrated testing
  • 25.
  • 26. Drools Planner • Works on all kinds of planning problems – NP-complete – Hard & soft constraints – Huge search space • Planning constraints can be weighted and are written as declarative score rules • The planner algorithm is configurable. It searches through the solutions within a given amount of time and returns the best solution found
  • 27.
  • 28. Mario Fusco Red Hat – Senior Software Engineer mario.fusco@gmail.com twitter: @mariofusco Q A