Академический Документы
Профессиональный Документы
Культура Документы
References
z
R. Olivier, Implement business logic with the Drools rules engine, IBM developerWorks Website, http://www-128.ibm.com/ developerworks/java/library/j-drools/ , May 2006 M. Proctor, M. Neale, P. Lin, M. Frandsen, JBoss Rules User Guide, JBoss Rules Documentation Website, http://labs.jboss.com/portal/jbossrules/docs/i ndex.html , July 2006
Outline
1. 2. 3. 4. 5.
Outline
1. 2. 3. 4. 5.
Introduction
Business logic is the solution of enterprise software for financial planning and managed accounts It is hard to maintain or update an applications business logic with the dynamic changes of market economics
Rule Engine
Rules Engines are the pluggable software components that separate the business rules from the application code
Inference Engine
There are three advantages of using rule engine to implement business logic
Outline
1. 2. 3. 4. 5.
Overview of Drools
Drools 3.0 is an open source rule engine written in the java language
Understandable rules Tool integration (For Eclipse 3.2 or greater) Fast execution speed JSR 94-compliant (Java rule engine API standard) Free
Process Flow
The process flow of Drools can be split into tow main parts :
Authoring Runtime
Authoring
Parser drl xml
Runtime
Working Memory
Working Memory Event Support Agenda
Truth Maintenance Agenda Event Support System 1..n 1 package 1..n 1 Rule base
Package Builder
Compiler Code Generator
Outline
1. 2. 3. 4. 5.
rule
name attribute
Left Hand Side (LHS): a common name for the conditional part of the rule Right Hand Side (RHS): a common name for the consequence or action part of the rule
Rule Attributes
Customer(store==NTUT)
True if there is a object which type is Customer and its field constraint store is equal to NTUT c and d are instances True if there is a object which type is Goods and its field constraints name is equal to Cola and paid is false
c:Customer(d:Discount)
Good(name==Cola, paid==false)
Classes used with field constrain rely on methods of getters and setters such as getObject(), isObject(), setObjectetc If primitive type is used for a field, Drools will autobox them to corresponding object type, and no auto-unbox even using Java 5
Outline
1. 2. 3. 4. 5.
Scenario
Suppose there is a rich man who will buy all goods in FamilyMart, and we want to know if the rules are executed correctly
Step by Step
1. 2. 3. 4.
5.
Create a new rule project Create a class for object model Modify Sample.drl for normal rule Create a new rule resource (Sample2.drl) for special rules Modify DroolsTest.java
Outline
1. 2. 3. 4. 5.
Conclusion
Drools can reduce complexity of components that implement the business rules logic in Java application, and it is easy to maintain or extend the business logic by declarative programming
Q&A?
Conclusion
Drools can reduce complexity of components that implement the business rules logic in Java application, and it is easy to maintain or extend the business logic by declarative programming
Q&A?
Conclusion
Drools can reduce complexity of components that implement the business rules logic in Java application, and it is easy to maintain or extend the business logic by declarative programming
Q&A?
Generate the Rete Tree visualization Help developer to understand the structure of rules in drl file
Rete Tree
ReteNode ObjectTypeNode AlphaNode LeftInputAdapterNode JoinNode TerminalNode
Goods
Customer
paid==false
Sample.drl
"Join network" p
8 nodes q
6 nodes q
5 nodes q
Query
query Cola" Rule g:Goods(name==Cola) end LHS
QueryResults results Source code that uses the rule =workingMemory.getQueryResults(Cola"); for (Iterator it = results.iterator; it.hasNext(); ) { QueryResult result = (QueryResult) it.next(); Goods g = (Goods) result.get(g"); }
It is a way of extending the rule language to your problem domain Support spreadsheet format such as elx and csv
Decision tables
XML
Using for tools that generate rules from some input or from another rule language It defines a simple API to access a rule engine, but doesnt standardize the semantics of rule execution
JSR 94 API
Additional Information