[rules-users] Problem with update(fact)

Felipe Piccolini felipe.piccolini at bluesoft.cl
Thu Jul 5 10:08:47 EDT 2007


Chris,

   No the issue was that updating the $list so it should make the  
constraint of rule "test update A" not fire again, when updating the  
$fact
the rule is added to the agenda (activation-list) anyway...

I haven proved yet (I hope to do so today), but Edson said it is  
fixed on trunk.

On 05-07-2007, at 7:50, Chris Woodrow wrote:

> Hi,
> This doesn't seem to be a bug, IMHO, since no-loop is supposed  
> (according to the doc). In this case, factA is called once (thanks  
> to "no-loop", than fact2 is called once, and so on. Do you mean no- 
> loop should still be on if it has been used once for a given rule?
>
> Chris
>
> 2007/7/3, Felipe Piccolini <felipe.piccolini at bluesoft.cl>:
> I know I already asked this in a previous email, but no answer and  
> diferent subject... so I'll ask again
>
> I have an issue using update in 2 rules that update the same  
> object... a loop is created even when I try to
> avoid the loop adding an extra condition to each rule... Im  
> inserting an ArrayList as a fact too, so I can check
> the extra condition...
>
> Can anyone tell me how to fix this?
>
> Consider this:
> //-------RULES-----------------------------
> package cl.bluesoft.test
>
> #list any import classes here.
> import java.util.List
> import java.util.ArrayList
>
> import cl.bluesoft.test.rules.Fact
>
> #declare any global variables here
>
> rule "test update A"
>     salience 699
>     no-loop
> 	 when
> 		 $f : Fact($n: number > 0)
> 		$list: ArrayList( this excludes "key1")
> 	 then
> 		 System.out.println("A-fact number1:"+$f.getNumber()+ " list 1:"+ 
> $list);
> 		$list.add( "key1");
> 		 $f.setNumber($n + 1);
> 		 update ($f);
> 	 	update ($list);
>  		System.out.println("A-fact number2:" +$f.getNumber()+" list 2:" + 
> $list);
> end
>
>
> rule "test update B"
>     salience 699
>     no-loop
> 	when
>  		$f : Fact($n: number > 1)
> 	 	$list: ArrayList( this excludes "key2" )
> 	then
> 		System.out.println( "B-fact number1:"+$f.getNumber()+" list 1:" + 
> $list);
> 		 $list.add("key2" );
> 		$f.setNumber($n + 1);
> 		update ($f);
> 		 update ($list);
> 		 System.out.println("B-fact number2:" +$f.getNumber()+" list 2:"+ 
> $list);
> end
>
> //-------FACT-----------------------------
> public class Fact implements Serializable {
> 	private static final long serialVersionUID = 331627137981862975L;
> 	
> 	private int number;
> 	
> 	public Fact(int number){
> 	 	this.number	= number;
> 	}
>  	
> 	public Fact(){
> 		this(0);
> 	}
>
> 	/**
> 	 * @return the number
> 	 */
> 	public int getNumber() {
> 		return number;
> 	}
>
> 	/**
> 	 * @param number the number to set
>  	 */
> 	public void setNumber(int number) {
> 	 	this.number = number;
> 	}
> 	
> }
>
> //------TEST---------
> public class TestUpdateFact implements Serializable {
>
> 	private static final long serialVersionUID = -574789596641083743L;
>
> 	/**
> 	 * @param args
>  	 */
> 	public static void main(String[] args) {
> 	 	RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> 	 	Package pkg = builder.getPackage();
> 	 	....
> 		WorkingMemory session = ruleBase.getStatefulSession();
> 		...etc etc...
>
> 		List list = new ArrayList();
> 	 	
> 		Fact fact1 = new Fact(1);
>
> 		session.fireAllRules();
>
>  		....etc, etc...
> 		
> 	}
>
> }
>
> //--------OUTPUT------------
> A-fact number1:1 list 1:[]
> A-fact number2:2 list 2:[key1]
> B-fact number1:2 list 1:[key1]
> B-fact number2:3 list 2:[key1, key2]
> A-fact number1:3 list 1:[key1, key2]
> A-fact number2:4 list 2:[key1, key2, key1]
> B-fact number1:4 list 1:[key1, key2, key1]
> B-fact number2:5 list 2:[key1, key2, key1, key2]
> A-fact number1:5 list 1:[key1, key2, key1, key2]
> A-fact number2:6 list 2:[key1, key2, key1, key2, key1]
> B-fact number1:6 list 1:[key1, key2, key1, key2, key1]
> B-fact number2:7 list 2:[key1, key2, key1, key2, key1, key2]
> A-fact number1:7 list 1:[key1, key2, key1, key2, key1, key2]
> A-fact number2:8 list 2:[key1, key2, key1, key2, key1, key2, key1]
> B-fact number1:8 list 1:[key1, key2, key1, key2, key1, key2, key1]
>
> .... for ever.....
>
> So I have a loop... only when I use update and both rules...   
> condition about the
> list not containing "key1" and "key2" seems not properly chequed...  
> I dont know...
>
> Can somebody help me? Am I missing something here?
>
> Thanks.
>
>
> Felipe Piccolini M.
> felipe.piccolini at bluesoft.cl
>
>
>
>
>
> _______________________________________________
> 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



Atentamente,
______________________
Felipe Piccolini Marfull
Jefe de Proyectos
Agustina 1141 Piso 8-B
Santiago

Fono    +(56 2) 68830837
E-mail felipe.piccolini at bluesoft.cl





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070705/8c937d63/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.tiff
Type: image/tiff
Size: 262986 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20070705/8c937d63/attachment.tiff 


More information about the rules-users mailing list