Using Drools to provide error processing and consequence management
I am working on a module whose purpose is to process Java exceptions and decide upon a strategy for dealing with them. The exceptions could be things I know about (explicit business exceptions eg TransformationException) or more general environmental stuff (JMS errors, IO errors etc)
The facts inserted into the knowledge base are all the same class, and wrap (contain) an Exception.
I want to write a rule that will explicitly match the exceptions I know h开发者_开发百科ow to deal with (eg TransformationException) and have another rule that catches 'everything else'
The problem seems to me to be that for a fact containing a TransformationException, both rules will fire and the output will be uncertain.
How would I go about writing such exclusive rules without relying on salience to steer the order of execution (this seems to be bad practice from what I have read)?
I have a solution in place that I am not happy with whereby the outcome depends on the order in which the rules are defined in my .drl.
I'd suggest using a high salience for the exception specific rules and a lower salience for the generic rules. Alternatively you could use agenda groups to run the specific rules first followed by the catch-all rule.
To prevent multiple executions you can retract the fact in the action of the higher salience rules.
Take a look at activation groups, they allow you to put a set of rules into an exclusive group so that at most one of them fires. That, incombination with a lower salience for your default rule, semms to do the trick here.
精彩评论