Jump To Close Expand all Collapse all Table of contents JBoss Rules 5 Reference Guide Preface 1. Introduction Expand section "1. Introduction" Collapse section "1. Introduction" 1.1. Intended Audience 1.2. Aim of the Guide 2. Key Terminology Expand section "2. Key Terminology" Collapse section "2. Key Terminology" 2.1. The Basics Expand section "2.1. The Basics" Collapse section "2.1. The Basics" 2.1.1. JBoss Rules 2.1.2. The JBoss Rules Engine 2.1.3. Expert Systems 2.1.4. Production Rules 2.1.5. The Inference Engine 2.1.6. Production Memory 2.1.7. Working Memory 2.1.8. Conflict Resolution Strategy 2.1.9. Hybrid Rule Systems 2.1.10. Forward-Chaining 2.1.11. Backward-Chaining 2.1.12. Reasoning Capabilities 2.2. Rete Algorithm Expand section "2.2. Rete Algorithm" Collapse section "2.2. Rete Algorithm" 2.2.1. The Rete Root Node 2.2.2. The ObjectTypeNode 2.2.3. AlphaNodes 2.2.4. Hashing 2.2.5. BetaNodes 2.2.6. Alpha Memory 2.2.7. Beta Memory 2.2.8. Lookups with BetaNodes 2.2.9. LeftInputNodeAdapters 2.2.10. Terminal Nodes 2.2.11. Node Sharing 2.2.12. Node Sharing Example 2.3. Strong and Loose Coupling Expand section "2.3. Strong and Loose Coupling" Collapse section "2.3. Strong and Loose Coupling" 2.3.1. Loose Coupling 2.3.2. Strong Coupling 2.4. Advantages of a Rule Engine Expand section "2.4. Advantages of a Rule Engine" Collapse section "2.4. Advantages of a Rule Engine" 2.4.1. Declarative Programming 2.4.2. Logic and Data Separation 2.4.3. Knowledge Base 3. Quick Start Expand section "3. Quick Start" Collapse section "3. Quick Start" 3.1. Rule Basics Expand section "3.1. Rule Basics" Collapse section "3.1. Rule Basics" 3.1.1. Stateless Knowledge Sessions 3.1.2. Configuring Rules in a Stateless Session 3.1.3. Configuring Rules with Multiple Objects 3.1.4. Stateful Sessions 3.1.5. Common Use Cases for Stateful Sessions 3.1.6. Stateful Session Monitoring Example 3.1.7. First Order Logic 3.1.8. Configuring Rules with First Order Logic 3.1.9. Rule System Sample Configuration 3.2. JBoss Rules Theory Expand section "3.2. JBoss Rules Theory" Collapse section "3.2. JBoss Rules Theory" 3.2.1. Methods in JBoss Rules 3.2.2. Method Example 3.2.3. Rule Example 3.2.4. Cross-Products 3.2.5. Cross-Product Constraining 3.2.6. The Inference Engine 3.2.7. Inference Example 3.3. Advanced Concepts and Theory Expand section "3.3. Advanced Concepts and Theory" Collapse section "3.3. Advanced Concepts and Theory" 3.3.1. Logical Assertions 3.3.2. Stated Insertions 3.3.3. Justified Insertions 3.3.4. The WM_BEHAVIOR_PRESERVE Setting 3.3.5. Stated Insertion Flowchart 3.3.6. Logical Insertion Flowchart 3.3.7. The Truth Maintenance System 3.3.8. The insertLogical Fact 3.3.9. Using Inference and TMS 4. Processing Expand section "4. Processing" Collapse section "4. Processing" 4.1. Agenda 4.2. Agenda Processing 4.3. Default Conflict Resolution Strategies 4.4. AgendaGroup 4.5. setFocus() 4.6. setFocus() Example 4.7. ActivationGroup 4.8. ActivationGroup Example 4.9. RuleFlowGroup 4.10. RuleFlowGroup Example 4.11. The Difference Between Rules and Methods 4.12. Cross Product Example 4.13. Activations, Agenda and Conflict Sets Example 4.14. Conflict Resolver Strategy 4.15. Conflict Resolver Strategy Example 4.16. Trigger Example 4.17. ruleflow-group Example 4.18. Inference Example 4.19. Implementing Inference and TruthMaintenance 5. The Rule Language Expand section "5. The Rule Language" Collapse section "5. The Rule Language" 5.1. Rule Language Expand section "5.1. Rule Language" Collapse section "5.1. Rule Language" 5.1.1. Overview 5.1.2. A rule file 5.1.3. The structure of a rule file 5.1.4. What is a rule 5.1.5. Hard Keywords 5.1.6. Soft Keywords 5.1.7. List of Soft Keywords 5.1.8. Comments 5.1.9. Single Line Comment Example 5.1.10. Multi-Line Comment Example 5.1.11. Error Messages 5.1.12. Error Message Format 5.1.13. Error Messages Description 5.1.14. Package 5.1.15. Import Statements 5.1.16. Using Globals 5.1.17. The From Element 5.1.18. Using Globals with an e-Mail Service 5.2. KnowledgeBuilder Expand section "5.2. KnowledgeBuilder" Collapse section "5.2. KnowledgeBuilder" 5.2.1. The KnowledgeBuilder 5.2.2. The ResourceFactory 5.2.3. Creating a new KnowledgeBuilder 5.2.4. Adding DRL Resources 5.2.5. KnowledgeBuilder Result Inspection Methods 5.2.6. Getting the KnowledgePackages 5.2.7. Extended KnowledgeBuilder Example 5.2.8. Using KnowledgeBuilder in Batch Mode 5.2.9. Discard the Build of the Last Added DRL 5.3. ChangeSets Expand section "5.3. ChangeSets" Collapse section "5.3. ChangeSets" 5.3.1. Changesets 5.3.2. Changeset Example 5.3.3. Extended Changeset Example 5.3.4. Changesets and Directories Example 5.3.5. Building Using Configuration and the ChangeSet XML 5.3.6. ChangeSet XML Example 5.3.7. ChangeSet Protocols 5.3.8. Loading the ChangeSet XML 5.3.9. ChangeSet XML with Resource Configuration Example 5.3.10. ChangeSet XML and Directories 6. Building Expand section "6. Building" Collapse section "6. Building" 6.1. Result Severity Expand section "6.1. Result Severity" Collapse section "6.1. Result Severity" 6.1.1. Build Result Severity 6.1.2. Setting the Default Build Result Severity 6.2. Building and Deploying Expand section "6.2. Building and Deploying" Collapse section "6.2. Building and Deploying" 6.2.1. KnowledgePackage 6.2.2. Creating a new KnowledgeBase 6.2.3. Add KnowledgePackages to a KnowledgeBase 6.2.4. Building and Deployment in Separate Processes 6.2.5. Writing the KnowledgePackage to an OutputStream 6.2.6. Reading the KnowledgePackage from an InputStream 6.2.7. StatefulknowledgeSessions and KnowledgeBase Modifications 6.3. The Knowledge Agent Expand section "6.3. The Knowledge Agent" Collapse section "6.3. The Knowledge Agent" 6.3.1. Knowledge Agent 6.3.2. KnowledgeAgent Objects 6.3.3. Writing the KnowledgePackage to an OutputStream 6.3.4. ClassLoaders 6.3.5. newInstance 6.3.6. Resource Scanning 6.3.7. Knowledge Bases and applyChangeSet() 6.3.8. Resource Caching 7. Sessions Expand section "7. Sessions" Collapse section "7. Sessions" 7.1. Sessions in JBoss Rules 7.2. Create a StatefulKnowledgeSession From a KnowledgeBase 7.3. KnowledgeRuntime Expand section "7.3. KnowledgeRuntime" Collapse section "7.3. KnowledgeRuntime" 7.3.1. The WorkingMemoryEntryPoint Method 7.3.2. The KnowledgeRuntime Interface 7.3.3. Fact Insertion 7.3.4. The FactHandle Token 7.3.5. Identity and Equality 7.3.6. Retraction 7.3.7. The update() Method 7.4. Working Memory Expand section "7.4. Working Memory" Collapse section "7.4. Working Memory" 7.4.1. Queries 7.4.2. Live Queries 7.4.3. ViewChangedEventListener Implementation Example 7.5. KnowledgeRuntime 8. Objects and Interfaces Expand section "8. Objects and Interfaces" Collapse section "8. Objects and Interfaces" 8.1. Globals 8.2. Working With Globals 8.3. Resolving Globals 8.4. Session Scoped Global Example 8.5. StatefulRuleSessions 8.6. AgendaFilter Objects 8.7. Using the AgendaFilter 8.8. Rule Engine Phases 8.9. The Event Model 8.10. The KnowlegeRuntimeEventManager 8.11. The WorkingMemoryEventManager 8.12. Adding an AgendaEventListener 8.13. Printing Working Memory Events 8.14. KnowlegeRuntimeEvents 8.15. Supported Events for the KnowledgeRuntimeEvent Interface 8.16. The KnowledgeRuntimeLogger 8.17. Enabling a FileLogger 8.18. Using StatelessKnowledgeSession in JBoss Rules 8.19. Performing a StatelessKnowledgeSession Execution with a Collection 8.20. Performing a StatelessKnowledgeSession Execution with the InsertElements Command 8.21. The BatchExecutionHelper 8.22. The CommandExecutor Interface 8.23. Out Identifiers 9. Modes and Methods Expand section "9. Modes and Methods" Collapse section "9. Modes and Methods" 9.1. Sequential Mode 9.2. Sequential Mode Options 9.3. Activating Sequential Mode 9.4. The CommandFactory 9.5. Supported CommandFactory Options 9.6. The Insert Command 9.7. Insert Command Example 9.8. The Execute Method 9.9. Execute Method Example 9.10. The BatchExecution Command 9.11. The FireAllRules Command 9.12. Out Identifiers 9.13. Out Identifier Example 9.14. Execution XML Examples 9.15. Execution Marshalling Examples 9.16. Batch-execution and Command Examples 9.17. The MarshallerFactory 9.18. Marshaller Example 9.19. Marshalling Options 9.20. IdentityMarshallingStrategy Example 9.21. The ObjectMarshallingStrategyAcceptor 9.22. The ClassFilterAcceptor Implementation 9.23. IdentityMarshallingStrategy with Acceptor Example 9.24. Persistence and Transactions in JBoss Rules 9.25. Transaction Example 9.26. Using a JPA 9.27. Loading a StatefulKnowledgeSession with JPA 9.28. Configuring JPA 9.29. Configuring JTA DataSource 9.30. JNDI Properties 9.31. KnowledgeBase Namespaces 10. Functions Expand section "10. Functions" Collapse section "10. Functions" 10.1. Functions 10.2. Function Declaration Example 10.3. Function Declaration with Static Method Example 10.4. Calling a Function Declaration Example 10.5. Type Declarations 10.6. Type Declaration Roles 10.7. Declaring New Types 10.8. Declaring a New Fact Type Example 10.9. Declaring a New Fact Type Additional Example 10.10. Using Import Example 10.11. Generated Java Classes 10.12. Generated Java Class Example 10.13. Using the Declared Types in Rules Example 10.14. Declaring Metadata 10.15. Working with Metadata Attributes 10.16. Declaring a Metadata Attribute with Fact Types Example 10.17. The @position Attribute 10.18. @position Example 10.19. Predefined Class Level Annotations 10.20. @key Attribute Functions 10.21. @key Declaration Example 10.22. Creating an Instance with the Key Constructor Example 10.23. Positional Arguments 10.24. Positional Argument Example 10.25. The @Position Annotation 10.26. Example Patterns 11. Additional Declarations Expand section "11. Additional Declarations" Collapse section "11. Additional Declarations" 11.1. Declaring Metadata for Existing Types 11.2. Declaring Metadata for Existing Types Example 11.3. Declaring Metadata Using a Fully Qualified Class Name Example 11.4. Parametrized Constructors for Declared Types Example 11.5. Non-Typesafe Classes 11.6. Accessing Declared Types from the Application Code 11.7. Declaring a Type 11.8. Handling Declared Fact Types Through the API Example 11.9. Type Declaration Extends 11.10. Type Declaration Extends Example 11.11. Traits 11.12. Traits Example 11.13. Core Objects and Traits 11.14. @Traitable Example 11.15. Writing Rules with Traits 11.16. Rules with Traits Example 11.17. Hidden Fields 11.18. The Two-Part Proxy 11.19. Wrappers 11.20. Wrapper Example 11.21. Wrapper with isA Annotation Example 11.22. Removing Traits 11.23. Rule Syntax Example 11.24. Rule Attributes 11.25. Rule Attribute Example 11.26. Timer Attribute Example 11.27. Timers 11.28. Cron Timer Example 11.29. Calendars 11.30. Quartz Calendar Example 11.31. Registering a Calendar 11.32. Left Hand Side 11.33. Conditional Elements 11.34. Rule Without a Conditional Element Example 12. Patterns Expand section "12. Patterns" Collapse section "12. Patterns" 12.1. Patterns 12.2. Pattern Example 12.3. Pattern Matching 12.4. Pattern Binding 12.5. Pattern Binding with Variable Example 12.6. Constraints 13. Elements and Variables Expand section "13. Elements and Variables" Collapse section "13. Elements and Variables" 13.1. Property Access on Java Beans (POJOs) 13.2. POJO Example 13.3. Working with POJOs 13.4. POJO Fallbacks 13.5. Fallback Example 13.6. Java Expressions 13.7. Comma-Separated Operators 13.8. Comma-Separated Operator Example 13.9. Binding Variables 13.10. Binding Variable Examples 13.11. Unification 13.12. Unification Example 13.13. Options and Operators in JBoss Rules 13.14. Operator Precedence 13.15. Fine Grained Property Change Listeners 13.16. Fine Grained Property Change Listener Example 13.17. Working with Fine Grained Property Change Listeners 13.18. Using Patterns with @watch 13.19. @watch Example 13.20. Using @PropertySpecificOption 13.21. Basic Conditional Elements 13.22. The Conditional Element Forall 13.23. Forall Examples 13.24. The Conditional Element From 13.25. From Examples 13.26. The Conditional Element Collect 13.27. The Conditional Element Accumulate 13.28. Syntax for the Conditional Element Accumulate 13.29. Functions of the Conditional Element Accumulate 13.30. The Conditional Element accumulate and Pluggability 13.31. The Conditional Element accumulate and Pluggability Example 13.32. Code for the Conditional Element Accumulate's Functions 13.33. Accumulate with Inline Custom Code 13.34. Accumulate with Inline Custom Code Examples 13.35. Conditional Element Eval 13.36. Conditional Element Eval Examples 13.37. The Right Hand Side 13.38. RHS Convenience Methods 13.39. Convenience Methods using the Drools Variable 13.40. Convenience Methods using the Kcontext Variable 13.41. The Modify Statement 13.42. Query Examples 13.43. QueryResults Example 13.44. Queries Calling Other Queries 13.45. Queries Calling Other Queries Example 13.46. Unification for Derivation Queries 14. Domain Specific Languages (DSLs) Expand section "14. Domain Specific Languages (DSLs)" Collapse section "14. Domain Specific Languages (DSLs)" 14.1. Domain Specific Languages 14.2. Using DSLs 14.3. DSL Example 14.4. How the DSL Parser Works 14.5. The DSL Compiler 14.6. DSL Syntax Examples 14.7. Chaining DSL Expressions 14.8. Adding Constraints to Facts 14.9. Tips for Developing DSLs 14.10. DSL and DSLR Reference 14.11. The Make Up of a DSL Entry 14.12. Debug Options for DSL Expansion 14.13. DSL Definition Example 14.14. Transformation of a DSLR File 14.15. String Transformation Functions 14.16. Stringing DSL Transformation Functions 15. XML Expand section "15. XML" Collapse section "15. XML" 15.1. The XML Format 15.2. XML Rule Example 15.3. XML Elements 15.4. Detail of a Rule Element 15.5. XML Rule Elements 15.6. Automatic Transforming Between XML and DRL 15.7. Classes for Automatic Transforming Between XML and DRL 16. Decision Tables Expand section "16. Decision Tables" Collapse section "16. Decision Tables" 16.1. Decision Tables 16.2. Decision Tables in Spreadsheets 16.3. Open Office Example 16.4. Rules and Spreadsheets 16.5. The RuleTable Keyword 16.6. The RuleSet Keyword 16.7. Rule Template Example 16.8. Data-Defining Cells 16.9. Rule Table Columns 16.10. Rule Set Entries 16.11. Entries in the Rule Set Area 16.12. Rule Attribute Entries in the Rule Set Area 16.13. The RuleTable Cell 16.14. Column Types 16.15. Column Headers in the Rule Table 16.16. Conditional Elements 16.17. Action Statements 16.18. Metadata Statements 16.19. Interpolating Cell Data Example 16.20. Tips for Working Within Cells 16.21. The SpreadsheetCompiler Class 16.22. Using Spreadsheet-Based Decision Tables 16.23. Lists 16.24. Revision Control 16.25. Tabular Data Sources 17. The Java Rule Engine Application Programming Interface Expand section "17. The Java Rule Engine Application Programming Interface" Collapse section "17. The Java Rule Engine Application Programming Interface" 17.1. JSR94 17.2. Javax.rules Interfaces 17.3. Javax.rules Classes 17.4. Javax.rules Exceptions 17.5. Using a Rule Service Provider 17.6. Javax.rules.admin Interfaces 17.7. Javax.rules.admin Exceptions 17.8. The RuleServiceProvider 17.9. The RuleServiceProviderManager 17.10. Automatic RuleServiceProvider Registration Example 17.11. Registering a LocalRuleExecutionSet with the RuleAdministrator API 17.12. Using Stateful and Stateless RuleSessions 17.13. Using Globals with JSR94 17.14. Using Globals with JSR94 Example 17.15. Further Reading About JSR94 18. JBoss Developer Studio Expand section "18. JBoss Developer Studio" Collapse section "18. JBoss Developer Studio" 18.1. The Rules Integrated Development Environment (IDE) 18.2. Rules IDE Features 18.3. JBoss Rules Runtimes 18.4. Defining a JBoss Rules Runtime 18.5. Selecting a Runtime for JBoss Rules Projects 18.6. Example Rule Files 18.7. The JBoss Rules Builder 18.8. Creating a New Rule 18.9. The Rule Editor 18.10. JBoss Rules Views 18.11. Using JBoss Rules Views 18.12. The Show Logical Structure 18.13. Creating Audit Logs 18.14. Event Icons in Audit View 18.15. Methods for Retrieving Causes 18.16. The DSL Editor 18.17. Rule Language Mapping 18.18. Working with Rule Language Mapping 18.19. DSL Translation Components 18.20. Tips for Working with Large DRL Files 18.21. Creating Breakpoints 18.22. Debugging as a JBoss Rules Application 18.23. Rules IDE Preferences 19. Hello World Example Expand section "19. Hello World Example" Collapse section "19. Hello World Example" 19.1. HelloWorld Example: Creating the KnowledgeBase and Session 19.2. HelloWorld Example: Event Logging and Auditing 19.3. HelloWorld Example: Message Class 19.4. HelloWorld Example: Execution 19.5. HelloWorld Example: System.out in the Console Window 19.6. HelloWorld Example: Rule "Hello World" 19.7. HelloWorld Example: Using the "Debug as..." Option 19.8. HelloWorld Example: Rule "Good Bye" 20. Salience State Example Expand section "20. Salience State Example" Collapse section "20. Salience State Example" 20.1. Salience State Example: State Class Example 20.2. Salience State Example: Execution 20.3. Salience State Example: Executing Applications 20.4. Salience State Example: Using Audit Logging with Operations 20.5. Salience State Example: Rule "Bootstrap" 20.6. Salience State Example: Rule "B to C" 20.7. Salience State Example: Rule "B to D" 20.8. Salience State Example: Inserting a Dynamic Fact 20.9. Salience State Example: Setter with PropertyChangeSupport 20.10. Salience State Example: Agenda Group Rules "B to C" 20.11. Salience State Example: Agenda Group Rules "B to D" 20.12. Salience State Example: Agenda Group Rules "D to E" 21. Fibonacci Example Expand section "21. Fibonacci Example" Collapse section "21. Fibonacci Example" 21.1. Fibonacci Example: The Class 21.2. Fibonacci Example: Execution 21.3. Fibonacci Example: Execution Details 21.4. Fibonacci Example: Recurse Rule 21.5. Fibonacci Example: Bootstrap Rule 21.6. Fibonacci Example: Calculate Rule 22. Banking Example Expand section "22. Banking Example" Collapse section "22. Banking Example" 22.1. Banking Example: RuleRunner 22.2. Banking Example: Rule in Example1.drl 22.3. Banking Example: Java Example 2 22.4. Banking Example: Rule in Example2.drl 22.5. Banking Example: Example3.java 22.6. Banking Example: Rule in Example3.drl 22.7. Banking Example: Class Cashflow 22.8. Banking Example: Example4.java 22.9. Banking Example: Class SimpleDate 22.10. Banking Example: Rule in Example4.drl 22.11. Banking Example: Class TypedCashflow 22.12. Banking Example: Example5.java 22.13. Banking Example: Class Account 22.14. Banking Example: Class AllocatedCashflow 22.15. Banking Example: Extending Example5.java 22.16. Banking Example: Rule in Example6.drl 23. Pricing Rule Example Expand section "23. Pricing Rule Example" Collapse section "23. Pricing Rule Example" 23.1. Pricing Rule Example: Executing the Pricing Rule Example 23.2. Pricing Rule Example: Decision Table Configuration 23.3. Pricing Rule Example: Base Price Calculation Example 23.4. Pricing Rule Example: Discount Calculation Example 24. Pet Store Example Expand section "24. Pet Store Example" Collapse section "24. Pet Store Example" 24.1. Pet Store Example 24.2. Pet Store Example: Creating the PetStore RuleBase in PetStore.main 24.3. Pet Store Example: Firing Rules from CheckoutCallBack.checkout() 24.4. Pet Store Example: Package, Imports, Globals and Dialect from PetStore.drl 24.5. Pet Store Example: Java Functions in the Rules Extracted from PetStore.drl 24.6. Pet Store Example: Putting Items Into Working Memory from PetStore.drl 24.7. Pet Store Example: Show Items in the GUI from PetStore.drl 24.8. Pet Store Example: Evaluate Agenda Group from PetStore.drl 24.9. Pet Store Example: Doing the Checkout Extract from PetStore.drl 24.10. Pet Store Example: Checkout Rules from PetStore.drl 24.11. Pet Store Example: Running PetStore.java 24.12. Pet Store Example: The Do Checkout Rule 25. Sudoku Example Expand section "25. Sudoku Example" Collapse section "25. Sudoku Example" 25.1. Sudoku Example: Loading the Example 25.2. Sudoku Example: Debugging a Broken Example 25.3. Sudoku Example: Java Source and Rules 25.4. Sudoku Example: Cell Objects 25.5. Sudoku Example: Classes and Objects 25.6. Sudoku Example: Validate.drl 25.7. Sudoku Example: Sudoku.drl 26. Number Guess Example Expand section "26. Number Guess Example" Collapse section "26. Number Guess Example" 26.1. Number Guess Example: Loading the Example 26.2. Number Guess Example: Starting the RuleFlow 26.3. Number Guess Example: Classes and Methods 26.4. Number Guess Example: Observing the RuleFlow 26.5. Number Guess Example: RuleFlow Nodes 26.6. Number Guess Example: Firing Rules at a Specific Point in NumberGuess.drl 26.7. Number Guess Example: Viewing RuleFlow Constraints 26.8. Number Guess Example: Console Output A. Revision History Legal Notice Settings Close Language: English Format: Multi-page Single-page PDF Format: Multi-page Single-page PDF Language and Page Formatting Options Language: English Format: Multi-page Single-page PDF Format: Multi-page Single-page PDF 12.4. Pattern Binding Patterns can be bound to a matching object. This is accomplished using a pattern binding variable such as $p. Report a bug Previous Next