Drools Interview Questions
Recommended by 0 users
Drools Interview Questions
What is Drool?
Drools is the Business Rule Management System (BRMS) provided by the JBoss Community for implementing complex applications with automatic behaviors based on rules. The framework is essentially based on an extension of the Rete pattern-matching algorithm.
What are the features of JBoss Enterprise Web Platform?
The JBoss Enterprise Web Platform is the software infrastructure that supports the running of BRMS components.
What is MVEL Dialect?
MVEL is an expression language for Java-based applications. It supports field and method/getter access. It is based on Java syntax.
Why use Drools and not other programming languages ?
The rules logic can be done in a programming language like Java .Consider a Jewellery shop which needs to maintain business logic of calculating discount based on the type of Jewellery. But such rules may change daily and need to be updated regularly in our code which is not good. Also we will always require a Developer for making such changes. So its a good practice to define this logic as rules in a Business Rule Management System. If tomorrow the discount is to be changed this can be done even by a non technical person.
JBoss Enterprise BRMS
JBoss Enterprise BRMS is a business rule management system and reasoning engine for business policy and rules development, access, and change management. JBoss Enterprise BRMS is a productized version of Drools with enterprise-level support available. JBoss Rules is also a productized version of Drools, but JBoss Enterprise BRMS is the flagship product.
Components of the enterprise version:
- JBoss Enterprise Web Platform – the software infrastructure, supported to run the BRMS components only
- JBoss Enterprise Application Platform or JBoss Enterprise SOA Platform – the software infrastructure, supported to run the BRMS components only
- Business Rules Engine – Drools Expert using the Rete algorithm and the Drools Rule Language (DRL)
- Business Rules Manager – Drools Guvnor – Guvnor is a centralised repository for Drools Knowledge Bases, with rich web based GUIs, editors, and tools to aid in the management of large numbers of rules.
- Business Rules Repository – Drools Guvnor
Drools and Guvnor are JBoss Community open source projects. As they are mature, they are brought into the enterprise-ready product JBoss Enterprise BRMS.
Components of the JBoss Community version:
- Drools Guvnor (Business Rules Manager) – a centralized repository for Drools Knowledge Bases
- Drools Expert (rule engine) – uses the rules to perform reasoning
- Drools Flow (process/workflow), or jBPM 5 – provides for workflow and business processes
- Drools Fusion (event processing/temporal reasoning) – provides for complex event processing
- Drools Planner/OptaPlanner (automated planning) – optimizes automated planning, including NP-hard planning problems
This example illustrates a simple rule to print out information about a holiday in July. It checks a condition on an instance of the
Holiday class, and executes Java code if that condition is true.
rule "validate holiday" dialect "mvel" dialect "java" when $h1 : Holiday( month == "july" ) then System.out.println($h1.name + ":" + $h1.month); end
The purpose of dialect “
mvel” is to point the Getter and Setters of the variables of your Plain Old Java Object (POJO) classes. Consider the above example, in which a
Holiday class is used and inside the circular brackets (parentheses) “
month” is used. So with the help dialect “
mvel” the getter and setters of the variable “
month” can be accessed.
java” is used to help us write our Java code in our rules. There is one restriction or characteristic on this. We cannot use Java code inside “when” part of the rule but we can use Java code in “then” part.
We can also declare a Reference variable
$h1 without the
$ symbol. There is no restriction on this. The main purpose of putting the
$ symbol before the variable is to mark the difference between variables of POJO classes and Rules.
What is the restriction in using Java code?
User cannot use Java code inside “when” part of the rules. However, it can be use in the “then” part.
What is a Rule?
Rules are pieces of knowledge often expressed as, “When some conditions occur, then do some tasks.”
When <Condition is true> Then <Take desired Action>
The most important part of a Rule is its when part. If the when part is satisfied, the then part is triggered.
rule <rule_name> <attribute> <value> when <conditions> then <actions> end
What are Drool Workbench, Expert, and Fusion?
Drools Workbench is the web user interface for authoring and management. Drools Expert is the business rule engine and Drools Fusion is the complex event processing feature.
What is meant by accumulate in DRL Drools?
Accumulate is conditional element that was introduced in Drools version 4.0. It is used to iterate over the list of objects and help validation of data in Java operation.
Ex. accumulate (Counter() ; $cnt : count())
What is meant by KIE?
KIE stands for Knowledge is everything. It stands for Knowledge is everything. From Drools 6.0 onwards a new approach is used to create a Knowledge Base and a Knowledge Session. Knowledge base is an interface that manages a set of rules and processes. The main task of the knowledge base is to store and re-use rules because creation of rules is very expensive.Rules are contained inside the package org.drools.KnowledgeBase. These are commonly referred to as knowledge definitions or knowledge. Knowledge base provides methods for creating a Session.
What is the productized version of Drools?
JBoss Enterprise BRMS is the productized version of Drools and it has enterprise level support.
What is Knowledge Session?
The knowledge session is retrieved from the knowledge base. It is the main interface for interacting with the Drools Engine. The knowledge session can be of two types:
- Stateless Knowledge Session
- Stateful Knowledge Session
How to remove object from knowledge session?
Using retract method to remove the object from knowledge session can help.
What is the global variable in Drools?
The global variable in Drools is the keyword. Global is the variable used in Drool and is visible in all rules inside the DRL file.