Hi,

I have recently started using drools and I am having some issues. 

 

I have two classes Rule1 and Rule2 which extends the class Rule. (I am not
using drl files. Lets just say we cannot use drl files).

I set the salience for Rule1 as 10 and Rule2 as 20 in the constructor of
these classes.

When I fire all rules Rule1 is getting triggered first. Here is the snippet
of my testcase :

 

        RuleSet ruleSet = new RuleSet( "Testing Salience feature" );

        Rule1 rule1 = new Rule1();

        Rule2 rule2 = new Rule2();

        ruleSet.addRule(rule1);

        ruleSet.addRule(rule2);

        RuleBaseBuilder builder = new RuleBaseBuilder( );

        builder.addRuleSet( ruleSet );

        RuleBase ruleBase = builder.build( );

        WorkingMemory workingMemory = ruleBase.newWorkingMemory( );

        workingMemory.assertObject( new SomeObject());

        workingMemory.fireAllRules( );

 

However if I interchange adding rules to the rule set as follows then Rule2
is fired first.

        ruleSet.addRule(rule2);

        ruleSet.addRule(rule1);

 

that is,  the load order is dictating the firing. I tried all combinations
and rules are getting triggered on how I add them to rule base.

I thought it has something to do with the conflict resolver and added the
following code with no success.

builder.setConflictResolver(SalienceConflictResolver.getInstance());

 

I tried this on drools 2.1 as well as 2.5-final with the same results.

How can I make sure that the rules are triggered depending on their salience
value and not the load order ?

 

Any help is highly appreciated.

Mohan

 

 

 

 

Reply via email to