Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 14. Seam and JBoss Rules
Seam makes it easy to call JBoss Rules (Drools) rulebases from Seam components or jBPM process definitions.
14.1. Installing rules Link kopierenLink in die Zwischenablage kopiert!
Link kopierenLink in die Zwischenablage kopiert!
The first step is to make an instance of
org.drools.RuleBase
available in a Seam context variable. For testing purposes, Seam provides a built-in component that compiles a static set of rules from the classpath. You can install this component via components.xml
:
This component compiles rules from a set of DRL (
.drl
) or decision table (.xls
) files and caches an instance of org.drools.RuleBase
in the Seam APPLICATION
context. Note that you will likely need to install multiple rule bases in a rule-driven application.
If you want to use a Drools DSL, you must also specify the DSL definition:
If you want to register a custom consequence exception handler through the RuleBaseConfiguration, you need to write the handler. This is demonstrated in the following example:
and register it:
In most rules-driven applications, rules must be dynamically deployable. A Drools RuleAgent is useful to manage the RuleBase. The RuleAgent can connect to a Drools rule server (BRMS), or hot-deploy rules packages from a local file repository. The RulesAgent-managed RuleBase is also configurable via
components.xml
:
<drools:rule-agent name="insuranceRules" configurationFile="/WEB-INF/deployedrules.properties" />
<drools:rule-agent name="insuranceRules"
configurationFile="/WEB-INF/deployedrules.properties" />
The properties file contains properties specific to the RulesAgent. The following is an example configuration file from the Drools example distribution:
It is also possible to configure the options on the component directly, bypassing the configuration file.
Next, make an instance of
org.drools.WorkingMemory
available to each conversation. (Each WorkingMemory
accumulates facts relating to the current conversation.)
<drools:managed-working-memory name="policyPricingWorkingMemory" auto-create="true" rule-base="#{policyPricingRules}"/>
<drools:managed-working-memory name="policyPricingWorkingMemory"
auto-create="true" rule-base="#{policyPricingRules}"/>
Notice that we referred the
policyPricingWorkingMemory
back to our rule base via the ruleBase
configuration property.
We can also add means to be notified of rule engine events, including, for example, rules firing or objects being asserted by adding event listeners to WorkingMemory.