tags:

views:

54

answers:

2

Hi, 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 how 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.

A: 

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.

BenM
Ok, cheers Ben. That makes sense.
Mike
A: 

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.

Kris Verlaenen