SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
Introducing




by Mario Fusco
Red Hat – Senior Software Engineer
mario.fusco@gmail.com
twitter: @mariofusco
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)
Drools 5 – Business Logic Integration Platform




 Drools   Drools    Drools    Drools Drools
 Expert    Flow     Fusion    Guvnor Planner


          Business Logic integration System
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                Imperative
         (What to do)
                      Vs. (How to do it)
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
                                    Quotes on Rule names are optional
                                    if the rule name has no spaces.
                  rule “<name>”
                       <attribute> <value>
Pattern-matching       when            salience     <int>
against objects in the                 agenda-group <string>
Working Memory              <LHS>      no-loop      <boolean>
                       then            auto-focus   <boolean>
                                       duration     <long>
                            <RHS>      ....

                  end
                                 Code executed when
                                 a match is found
Imperative vs Declarative
 A method must be called directly                         Specific passing
                                                          of arguments
public void helloMark(Person person) {
       if ( person.getName().equals( “mark” ) {
              System.out.println( “Hello Mark” );
       }
}
             Rules can never be called directly
                                                  Specific instances cannot be
                                                  passed but are automatically
rule “Hello Mark”                                 selected with pattern-matching
       when
             Person( name == “mark” )
       then
             System.out.println( “Hello Mark” );
end
What is a pattern

Person( name == “mark” )
              Field Name         Restriction

Object Type            Field Constraint

                    Pattern
Rule's definition
// Java
public class Applicant {          // DRL
    private String name;          declare Applicant
    private int age;
                                      name : String
    private boolean valid;
                                      age : int
    // getter and setter here         valid : boolean
}                                 end


          rule "Is of valid age" when
              $a : Applicant( age >= 18 )
          then
              modify( $a ) { valid = true };
          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

                                    Hibernate session
$zipCode : ZipCode()
Person( ) from $hbn.getNamedQuery(“Find People”)
                     .setParameters( [ “zipCode” : $zipCode ] )
                     .list()
 'from' can work
 on any expression
Timers & Calendars
      rule R1                     When the light is on, and has been
          timer 1m30s                on for 1m30s then turn it off
      when
          $l : Light( status == “on” )
      then
         modify( $l ) { status = “off” };

                                             rule R3
        Execute now and after                     calendars "weekday"
 1 hour duration only during weekday
                                                  timer (int:0 1h)
                                             when
rule R2                                            Alarm()
    timer ( cron: 0 0/15 * * * * ) then
when                                               sendEmail( ”Alert!” )
     Alarm()
then                                  Send alert every
    sendEmail( ”Alert!” )            quarter of an hour
Truth Maintenance System (1)
rule "Issue Adult Bus Pass" when
      $p : Person( age >= 18 )
then
                                         Coupled logic
      insert(new AdultBusPass( $p ) );
end


rule "Issue Child Bus Pass" when
                                          What happens
      $p : Person( age < 18 )             when the child
                                          becomes adult?
then
      insert(new ChildBusPass( $p ) );
end
Truth Maintenance System (2)
rule "Who Is Child" when          De-couples the logic
    $p : Person( age < 18 )
then
    logicalInsert( new IsChild( $p ) )
end
                                                 Encapsulate
                                             knowledge providing
rule "Issue Child Bus Pass" when
                                            semantic abstractions
    $p : Person( )                          for this encapsulation
    IsChild( person =$p )
then
    logicalInsert(new ChildBusPass( $p ) );
end
                                         Maintains the truth by
                                         automatically retracting
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
   Temporal
 relationships
between events

rule
    "Sound the alarm"
when
    $f : FireDetected( )
    not( SprinklerActivated( this after[0s,10s] $f ) )
then
    // sound the alarm
end
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
Q                                                 A
Mario Fusco                          mario.fusco@gmail.com
Red Hat – Senior Software Engineer     twitter: @mariofusco

Contenu connexe

Tendances

Rule Engine & Drools
Rule Engine & DroolsRule Engine & Drools
Rule Engine & DroolsSandip Jadhav
 
Drools 6 deep dive
Drools 6 deep diveDrools 6 deep dive
Drools 6 deep diveMario Fusco
 
Rules Programming tutorial
Rules Programming tutorialRules Programming tutorial
Rules Programming tutorialSrinath Perera
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info SheetMark Proctor
 
2011-03-29 London - drools
2011-03-29 London - drools2011-03-29 London - drools
2011-03-29 London - droolsGeoffrey De Smet
 
Rules Engine - java(Drools) & ruby(ruleby)
Rules Engine - java(Drools) & ruby(ruleby)Rules Engine - java(Drools) & ruby(ruleby)
Rules Engine - java(Drools) & ruby(ruleby)martincabrera
 
JBoss Drools - Open-Source Business Logic Platform
JBoss Drools - Open-Source Business Logic PlatformJBoss Drools - Open-Source Business Logic Platform
JBoss Drools - Open-Source Business Logic Platformelliando dias
 
JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...
JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...
JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...Juan Cruz Nores
 
Cassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsCassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsChristopher Batey
 
LJC Conference 2014 Cassandra for Java Developers
LJC Conference 2014 Cassandra for Java DevelopersLJC Conference 2014 Cassandra for Java Developers
LJC Conference 2014 Cassandra for Java DevelopersChristopher Batey
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine Aleksandar Prokopec
 
Cassandra is great but how do I test my application?
Cassandra is great but how do I test my application?Cassandra is great but how do I test my application?
Cassandra is great but how do I test my application?Christopher Batey
 
Fault tolerant microservices - LJC Skills Matter 4thNov2014
Fault tolerant microservices - LJC Skills Matter 4thNov2014Fault tolerant microservices - LJC Skills Matter 4thNov2014
Fault tolerant microservices - LJC Skills Matter 4thNov2014Christopher Batey
 

Tendances (20)

Drools
DroolsDrools
Drools
 
Rule Engine & Drools
Rule Engine & DroolsRule Engine & Drools
Rule Engine & Drools
 
Drools 6 deep dive
Drools 6 deep diveDrools 6 deep dive
Drools 6 deep dive
 
JBoss World 2011 - Drools
JBoss World 2011 - DroolsJBoss World 2011 - Drools
JBoss World 2011 - Drools
 
Rules Programming tutorial
Rules Programming tutorialRules Programming tutorial
Rules Programming tutorial
 
Drools & jBPM Info Sheet
Drools & jBPM Info SheetDrools & jBPM Info Sheet
Drools & jBPM Info Sheet
 
Drools BeJUG 2010
Drools BeJUG 2010Drools BeJUG 2010
Drools BeJUG 2010
 
2011-03-29 London - drools
2011-03-29 London - drools2011-03-29 London - drools
2011-03-29 London - drools
 
Rules Engine - java(Drools) & ruby(ruleby)
Rules Engine - java(Drools) & ruby(ruleby)Rules Engine - java(Drools) & ruby(ruleby)
Rules Engine - java(Drools) & ruby(ruleby)
 
Rules With Drools
Rules With DroolsRules With Drools
Rules With Drools
 
JBoss Drools - Open-Source Business Logic Platform
JBoss Drools - Open-Source Business Logic PlatformJBoss Drools - Open-Source Business Logic Platform
JBoss Drools - Open-Source Business Logic Platform
 
Drools
DroolsDrools
Drools
 
JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...
JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...
JavaOne 2016: Code Generation with JavaCompiler for Fun, Speed and Business P...
 
Cassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsCassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra Applications
 
LJC Conference 2014 Cassandra for Java Developers
LJC Conference 2014 Cassandra for Java DevelopersLJC Conference 2014 Cassandra for Java Developers
LJC Conference 2014 Cassandra for Java Developers
 
ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine ScalaDays 2014 - Reactive Scala 3D Game Engine
ScalaDays 2014 - Reactive Scala 3D Game Engine
 
Zen of Akka
Zen of AkkaZen of Akka
Zen of Akka
 
Cassandra is great but how do I test my application?
Cassandra is great but how do I test my application?Cassandra is great but how do I test my application?
Cassandra is great but how do I test my application?
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
Fault tolerant microservices - LJC Skills Matter 4thNov2014
Fault tolerant microservices - LJC Skills Matter 4thNov2014Fault tolerant microservices - LJC Skills Matter 4thNov2014
Fault tolerant microservices - LJC Skills Matter 4thNov2014
 

Similaire à Drools Introduction

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
 
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
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksMongoDB
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonCodemotion
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesMarakana Inc.
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesEdgar Gonzalez
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
Hibernate
Hibernate Hibernate
Hibernate Sunil OS
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingBeyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingEd Kohlwey
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Kerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastKerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastJorge Lopez-Malla
 
Deep Dumpster Diving
Deep Dumpster DivingDeep Dumpster Diving
Deep Dumpster DivingRonnBlack
 

Similaire à Drools Introduction (20)

Stop that!
Stop that!Stop that!
Stop that!
 
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...
 
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
 
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)
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
TWINS: OOP and FP - Warburton
TWINS: OOP and FP - WarburtonTWINS: OOP and FP - Warburton
TWINS: OOP and FP - Warburton
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and Techniques
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Hibernate
Hibernate Hibernate
Hibernate
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel ProcessingBeyond Map/Reduce: Getting Creative With Parallel Processing
Beyond Map/Reduce: Getting Creative With Parallel Processing
 
04 Data Access
04 Data Access04 Data Access
04 Data Access
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Kerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit eastKerberizing spark. Spark Summit east
Kerberizing spark. Spark Summit east
 
JavaScript Looping Statements
JavaScript Looping StatementsJavaScript Looping Statements
JavaScript Looping Statements
 
Deep Dumpster Diving
Deep Dumpster DivingDeep Dumpster Diving
Deep Dumpster Diving
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 

Plus de JBug Italy

JBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBug Italy
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBossJBug Italy
 
Intro jbug milano_26_set2012
Intro jbug milano_26_set2012Intro jbug milano_26_set2012
Intro jbug milano_26_set2012JBug Italy
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzJBug Italy
 
Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMJBug Italy
 
JBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBug Italy
 
JBoss AS7 Overview
JBoss AS7 OverviewJBoss AS7 Overview
JBoss AS7 OverviewJBug Italy
 
Intro JBug Milano - January 2012
Intro JBug Milano - January 2012Intro JBug Milano - January 2012
Intro JBug Milano - January 2012JBug Italy
 
JBoss AS7 Webservices
JBoss AS7 WebservicesJBoss AS7 Webservices
JBoss AS7 WebservicesJBug Italy
 
Intro JBug Milano - September 2011
Intro JBug Milano - September 2011Intro JBug Milano - September 2011
Intro JBug Milano - September 2011JBug Italy
 
All the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSAll the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSJBug Italy
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridJBug Italy
 
September 2010 - Arquillian
September 2010 - ArquillianSeptember 2010 - Arquillian
September 2010 - ArquillianJBug Italy
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - GateinJBug Italy
 
May 2010 - Infinispan
May 2010 - InfinispanMay 2010 - Infinispan
May 2010 - InfinispanJBug Italy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasyJBug Italy
 
May 2010 - Drools flow
May 2010 - Drools flowMay 2010 - Drools flow
May 2010 - Drools flowJBug Italy
 

Plus de JBug Italy (20)

JBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testingJBoss Wise: breaking barriers to WS testing
JBoss Wise: breaking barriers to WS testing
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
 
AS7 and CLI
AS7 and CLIAS7 and CLI
AS7 and CLI
 
Intro jbug milano_26_set2012
Intro jbug milano_26_set2012Intro jbug milano_26_set2012
Intro jbug milano_26_set2012
 
Faster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzzFaster & Greater Messaging System HornetQ zzz
Faster & Greater Messaging System HornetQ zzz
 
Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGM
 
AS7
AS7AS7
AS7
 
JBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logicJBoss BRMS - The enterprise platform for business logic
JBoss BRMS - The enterprise platform for business logic
 
JBoss AS7 Overview
JBoss AS7 OverviewJBoss AS7 Overview
JBoss AS7 Overview
 
Intro JBug Milano - January 2012
Intro JBug Milano - January 2012Intro JBug Milano - January 2012
Intro JBug Milano - January 2012
 
JBoss AS7 Webservices
JBoss AS7 WebservicesJBoss AS7 Webservices
JBoss AS7 Webservices
 
JBoss AS7
JBoss AS7JBoss AS7
JBoss AS7
 
Intro JBug Milano - September 2011
Intro JBug Milano - September 2011Intro JBug Milano - September 2011
Intro JBug Milano - September 2011
 
All the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMSAll the cool stuff of JBoss BRMS
All the cool stuff of JBoss BRMS
 
Infinispan and Enterprise Data Grid
Infinispan and Enterprise Data GridInfinispan and Enterprise Data Grid
Infinispan and Enterprise Data Grid
 
September 2010 - Arquillian
September 2010 - ArquillianSeptember 2010 - Arquillian
September 2010 - Arquillian
 
September 2010 - Gatein
September 2010 - GateinSeptember 2010 - Gatein
September 2010 - Gatein
 
May 2010 - Infinispan
May 2010 - InfinispanMay 2010 - Infinispan
May 2010 - Infinispan
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
May 2010 - Drools flow
May 2010 - Drools flowMay 2010 - Drools flow
May 2010 - Drools flow
 

Dernier

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 

Dernier (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 

Drools Introduction

  • 1. Introducing by Mario Fusco Red Hat – Senior Software Engineer mario.fusco@gmail.com twitter: @mariofusco
  • 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. Drools 5 – Business Logic Integration Platform Drools Drools Drools Drools Drools Expert Flow Fusion Guvnor Planner Business Logic integration System
  • 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 Imperative (What to do) Vs. (How to do it)
  • 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 Quotes on Rule names are optional if the rule name has no spaces. rule “<name>” <attribute> <value> Pattern-matching when salience <int> against objects in the agenda-group <string> Working Memory <LHS> no-loop <boolean> then auto-focus <boolean> duration <long> <RHS> .... end Code executed when a match is found
  • 8. Imperative vs Declarative A method must be called directly Specific passing of arguments public void helloMark(Person person) { if ( person.getName().equals( “mark” ) { System.out.println( “Hello Mark” ); } } Rules can never be called directly Specific instances cannot be passed but are automatically rule “Hello Mark” selected with pattern-matching when Person( name == “mark” ) then System.out.println( “Hello Mark” ); end
  • 9. What is a pattern Person( name == “mark” ) Field Name Restriction Object Type Field Constraint Pattern
  • 10. Rule's definition // Java public class Applicant { // DRL private String name; declare Applicant private int age; name : String private boolean valid; age : int // getter and setter here valid : boolean } end rule "Is of valid age" when $a : Applicant( age >= 18 ) then modify( $a ) { valid = true }; 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 Hibernate session $zipCode : ZipCode() Person( ) from $hbn.getNamedQuery(“Find People”) .setParameters( [ “zipCode” : $zipCode ] ) .list() 'from' can work on any expression
  • 15. Timers & Calendars rule R1 When the light is on, and has been timer 1m30s on for 1m30s then turn it off when $l : Light( status == “on” ) then modify( $l ) { status = “off” }; rule R3 Execute now and after calendars "weekday" 1 hour duration only during weekday timer (int:0 1h) when rule R2 Alarm() timer ( cron: 0 0/15 * * * * ) then when sendEmail( ”Alert!” ) Alarm() then Send alert every sendEmail( ”Alert!” ) quarter of an hour
  • 16. Truth Maintenance System (1) rule "Issue Adult Bus Pass" when $p : Person( age >= 18 ) then Coupled logic insert(new AdultBusPass( $p ) ); end rule "Issue Child Bus Pass" when What happens $p : Person( age < 18 ) when the child becomes adult? then insert(new ChildBusPass( $p ) ); end
  • 17. Truth Maintenance System (2) rule "Who Is Child" when De-couples the logic $p : Person( age < 18 ) then logicalInsert( new IsChild( $p ) ) end Encapsulate knowledge providing rule "Issue Child Bus Pass" when semantic abstractions $p : Person( ) for this encapsulation IsChild( person =$p ) then logicalInsert(new ChildBusPass( $p ) ); end Maintains the truth by automatically retracting
  • 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 Temporal relationships between events rule "Sound the alarm" when $f : FireDetected( ) not( SprinklerActivated( this after[0s,10s] $f ) ) then // sound the alarm end
  • 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. Q A Mario Fusco mario.fusco@gmail.com Red Hat – Senior Software Engineer twitter: @mariofusco