[rules-users] Don't process rules when adding new package to rulebase

Remi Barraquand nospam at barraquand.com
Fri May 30 09:58:17 EDT 2008


Hi Mark and thanks for your reply.

Well i've tried to replace the default RuleBaseUpdateHandler from the
RuleBaseConfiguration but without success... the setter actually take a
string.. which i think should be the class name. But when i set my class, i
get an exception saying that the factory cannot instantiate my custom
class...

Do you have any idea how to do that ? actually i browse all the listener
from the session and remove the one i don't want... which is not a "nice"
way actually. But it works.

By the way, my point is the following, in drools you have DroolsClass and
DroolsClassConfiguration. So a good way will be to add a
StateFullSessionConfiguration, where in this configuration you can set a
FireLimit for example. In this way, everycall to fireAllRule from other
thread will use this default FireLimit.

Rémi 


Mark Proctor wrote:
> 
> 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
>>   
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 


-----
________________________________________
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
-- 
View this message in context: http://www.nabble.com/Don%27t-process-rules-when-adding-new-package-to-rulebase-tp17508315p17559545.html
Sent from the drools - user mailing list archive at Nabble.com.





More information about the rules-users mailing list