[rules-users] Initialize Global

vdelbart delbart.v at mipih.fr
Tue Oct 30 05:08:19 EDT 2007


It's normal.

Globally, the rule engine works in two steps :
 - first : the activation (the "when" statement)
 - second : the execution (the "then" statement) with salience, ruleflow ...

In your test, you have in the first step objectList = null and in the second
step objectList = [1, 2].

If you want to re-activate your rule, you have to do an update/insert/remove
action... But you can't do that with globals. So you need to use the WM
facts.



Waruzjan Shahbazian-2 wrote:
> 
> I have the same "problem", but eval(objectList == null) doesn't work. If 
> I don't execute "drools.getWorkingMemory().setGlobal()" it "works fine", 
> as if the rule activates and the object is null.
> 
> global List objectList;
> 
> rule "Start"
>     salience 101
>     when
>         #conditions
>     then
>         objectList = new ArrayList() ;
>         objectList.add("1");
>         objectList.add("2");   
>         System.out.println("Start objectList:"+objectList); 
>         //drools.getWorkingMemory().setGlobal("objectList", objectList);
> end
> 
> rule "end"
>     salience 97
>     when
>         eval (objectList == null)
>     then
>         System.out.println("End objectList: "+objectList);
> end
>        
> gives:
>    
>     Start objectList:[1, 2]
>     End objectList: null
> 
> Next I uncomment the "drools.getWorkingMemory().setGlobal("objectList", 
> objectList);" and run the rule again an get:
> 
>     Start objectList:[1, 2]
>     End objectList: [1, 2]
> 
> so the objectList isn't null, but the rule still activates...
> 
> Kris Verlaenen schreef:
>>> That initialized my global but the rule still runs every execution.  
>>> Can I
>>> disable the rule after the first execution?
>> What do you mean by "every execution".  A rule should only be executed 
>> once, unless it gets reactivated (which should not be the case in this 
>> situation).
>>
>>> I would like to use (if (objectList==null)).  My list is not 
>>> immutable. Can
>>> I make a similar rule for the LHS?
>> You can test whether the global is null using eval( objectList == null 
>> )  in the LHS of the rule.
>>
>> Kris
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Initialize-Global-tf4685186.html#a13484734
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list