By Anusha Jallipalli
Drools is a collection of tools that allow us to separate and reason over logic and data found within business processes. The two important keywords we need to notice are Logic and Data. Let us understand some terms used in the Drools rules engine , before we run a drool example:
Drools Rule Engine uses the rule-based approach to implement an Expert System.
Expert Systems are knowledge-based systems that use knowledge acquired through process followed converting it into a knowledge base that can be used for reasoning.
Rules are pieces of knowledge often expressed as, “When some conditions occur, then do some tasks.”
KnowledgeBase is an interface that manages a collection of rules, processes, and internal types. It is contained inside the package org.drools.KnowledgeBase. In Drools, these are commonly referred as knowledge definitions or knowledge.
KnowledgeBuilder interface is responsible for building a KnowledgePackage from knowledge definitions (rules, processes, types). It is contained inside the package org.drools.builder. It will report errors through these two methods: hasErrors and getError.
Knowledge Session in Drools is the core component that fires the rules. It is the knowledge session that holds all the rules and other resources.
Facts are inserted into the session and when a specified condition is met, the subsequent rule gets fired. Thus a Knowledge Session is created from the KnowledgeBase.
Sessions are two types:
Stateless Knowledge Session – which can be called like a function, passing into it some data and then receiving some results back.
Stateful Knowledge Session – which lives longer and allows iterative changes over time
Here is an example of drools: