Yes thats a good point, if the engine assertions recurse indefinitely
the rules will never be removed or added. The
FireAllRulesRuleBaseUpdateListener is pluggable, see the
RuleBaseConfiguration so you replace that with alternative logic. We
will look to see if there is a better way for the next major release.
Mark
Remi Barraquand wrote:
Issue:
By looking in the Drools source code i found something interesting...
When you call session.getRuleBase().addPackage(yourPackage) event of the
type AfterPackageAddedEvent are sent to all RuleBaseListener of the
RuleBase. It appear that one of this listener is added by default, which is
: org.drools.base.FireAllRulesRuleBaseUpdateListener.
This listener when receiving an event of this type, call the following
method:
public void beforeRuleBaseUnlocked(BeforeRuleBaseUnlockedEvent event) {
if ( session.getRuleBase().getAdditionsSinceLock() > 0 ) {
session.fireAllRules();
}
}
and so call fireAllRules(); !! this imply that if you have cycling rules
inside you rule package you will never leave the
session.getRuleBase().addPackage(yourPackage) call.....
Solution:
- One solution would be to remove this listener by defaut and add one with
an overloading of the beforeRuleBaseUnlocked method.
- A better solution i think, would be to be able to set a default fireLimit
option on session, so a call to fireAllRule would use this defaultFireLimit.
What do you think ?
- is there a better solution ? do i miss something ?
Give me your point on it,
Rémi
Remi Barraquand wrote:
> Hi there,
>
> I'm developing a library that uses drools as a REAL-TIME rule engine. What
> i'm a doing right now is to have a thread that wakes up each 100ms and do
> a fireAllRules(1000).
>
> I need to be able to load Facts and Rules on the fly, even after the
> statefullsession is created. The problem is that when i add a new
> RulePackage to the current rulebase's session, all the rules inside this
> package are evaluated ! and so i never exit from this addPackage function
> !!
>
> System.out.println("Start loading rules");
>
> // build builder package configuration
> PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
> conf.setClassLoader(factionary);
>
> // Load file
> File file = new File(chooser.getSelectedFile().getPath());
> PackageBuilder builder = new PackageBuilder(conf);
>
> builder.addPackageFromDrl(new FileReader(file));
>
> // Load package to session
> session.getRuleBase().addPackage(builder.getPackage()); // GET STUCK HERE
> !!!!!!!!!!!
>
> // Print success
> jTextArea2.append(chooser.getSelectedFile().getPath()+"\n");
> jTextArea2.setCaretPosition(jTextArea1.getDocument().getLength());
>
> System.out.println("Done loading rules");
>
> What i want is just to add the rules from the package that's all.... Since
> i've a thread that call fireAllRules(1000) each 100ms the rules will get
> proceced next time :)
>
> Do you have any idea of how to do that ?
>
> Thanks.
>
> Barraquand Rémi
>
>
>
Issue
-----
________________________________________
Rémi Barraquand, PhD I.N.P.G
Projet PRIMA - Laboratoire LIG
INRIA Grenoble Rhones-Alpes Research Centre
655 Ave de l'Europe
38330 Montbonnot, France