JBoss Drools is rule engine
Rule engine provides a standard way to handle your business logic.
Drools
is split into two main parts: Authoring and
Runtime.
Authoring:
The Authoring process involves the
creation Rules files (.DRL or excel file) which contain the rules which are fed
into a parser.
The parser checks for correctly syntax
of the rules and produces an intermediate structure that "describes"
the rules.
This is then passed to the Package
Builder which produces Packagesand undertakes any code generation and
compilation that is necessary for the creation of the Package.
RuleBase is a runtime component made up
of one or more Packages.
A RuleBase can instantiate one or more
WorkingMemories at any time.
The Working Memory consists of a number of sub components, including Working Memory Event Support, Truth Maintenance System, Agenda and Agenda Event Support.
The Working Memory consists of a number of sub components, including Working Memory Event Support, Truth Maintenance System, Agenda and Agenda Event Support.
===================================
S/W installation:
copy the plugin .jar file in the
"plugin" directory of your Eclipse. Last thing to do, copy the
directory org.drools.eclipse.feature_5.0.0 (containing the feature.xml file) in
the features directory.
decision tables
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl",
HelloWorldExample.class), ResourceType.DRL);
// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Unable to compile \"HelloWorld.drl\".");
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
By default, all rules are in the agenda group "MAIN".
The "agenda-group" attribute lets you specify a
different agenda group for the rule.
salience
The execution of rule "A to B" changes the state of B
to
FINISHED
,
which activates both, rules "B to C" and "B to D", placing
their Activations onto the Agenda. From this moment on, both rules may fire
and, therefore, they are said to be "in conflict". The
conflict resolution strategy allows the engine's Agenda to decide which rule to
fire. As rule "B to C" has the higher salience value (10 versus the default salience
value of 0), it fires first, modifying object C to state FINISHED
. The Audit view shown above
reflects the modification of the State
object in the rule "A to B", which results in two activations being
in conflict.
Example:
================================
5.4. Error
Messages
Drools 5 introduces
standardized error messages. This standardization aims to help users to find
and resolve problems in a easier and faster way. In this section you will learn
how to identify and interpret those error messages, and you will also receive some
tips on how to solve the problems associated with them.
5.4.1. Message
format
The standardization
includes the error message format and to better explain this format, let's use
the following example:
=================================
Figure 5.3. Error
Message Format
1st Block: This area identifies the
error code.
2nd Block: Line and column
information.
3rd Block: Some text describing the
problem.
4th Block: This is the first
context. Usually indicates the rule, function, template or query where the
error occurred. This block is not mandatory.
5th Block: Identifies the pattern
where the error occurred. This block is not mandatory.
5.8.1. Rule
Attributes
Rule attributes provide a
declarative way to influence the behavior of the rule. Some are quite simple,
while others are part of complex subsystems such as ruleflow. To get the most
from Drools you should make sure you have a proper understanding of each attribute.
=====================================
No comments:
Post a Comment