<div>Thanks for your help, Edson. </div> <div>collect works in my simple test now, but not when I integrate with my code. Is there an easy way to debug LHS to see if collect stmt is evaluated? I notice IllegalAccessError<BR> since my app will load a selected list of jars upfront, so my questions are:</div> <div>1) Can this error break collect?</div> <div>2) How can I fix this error still using our own classLoader?</div> <div> </div> <div>Here is the stack trace:</div> <div>2007 Aug 15, 09:08:13:193 Exception IllegalAccessError<BR>java.lang.IllegalAccessError: class org.drools.reteoo.InitialFactImplShadowProxy cannot access its superclass org.drools.reteoo.Init<BR>ialFactImpl<BR> at java.lang.ClassLoader.defineClass1(Native Method)<BR> at java.lang.ClassLoader.defineClass(Unknown
Source)<BR> at org.drools.rule.MapBackedClassLoader.fastFindClass(MapBackedClassLoader.java:60)<BR> at org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:79)<BR> at java.lang.ClassLoader.loadClass(Unknown Source)<BR> at org.drools.reteoo.Rete$ObjectTypeConf.loadOrGenerateProxy(Rete.java:379)<BR> at org.drools.reteoo.Rete$ObjectTypeConf.defineShadowProxyData(Rete.java:344)<BR> at org.drools.reteoo.Rete$ObjectTypeConf.<init>(Rete.java:320)<BR> at org.drools.reteoo.Rete.assertObject(Rete.java:145)<BR> at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)<BR>
at org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:163)<BR> at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1241)<BR> at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)<BR> at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:822)<BR> at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:623)<BR></div> <div> </div> <div>Thanks,</div> <div>-av</div> <div> </div> <div><BR><B><I>Edson Tirelli <tirelli@post.com></I></B> wrote:</div> <BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><BR> No single simple answer here. You need to check what would better fit
your use case. <BR> The thing is: it is not possible to limit the number of matches to a collect statement... all matching instances WILL match it and be collected. <BR><BR> No really "clean" way I can think about, but a few possible options (haven't executed them, but shall work):<BR><BR>1. Simply execute the actions multiple times in the consequence:<BR><BR> <DIV>when </DIV><FONT size=2><FONT size=2> <DIV align=left> eventList : LinkedList( $size : size >= 5 ) from collect( Event(text matches ".*rule5.*"<FONT size=2> )) <BR></FONT><B><FONT color=#960000 size=2>then<BR> for( int i = 0; i < $size/5; i++ )<BR></FONT></B></DIV></FONT></FONT><FONT size=2> <DIV> System.out.println(<FONT color=#008000 size=2>"rule5 is fired "</FONT><FONT size=2> + eventList.size ());</FONT> <BR></DIV></FONT>end<BR><BR>2. Flag used facts:<BR><BR> <DIV>when</DIV><FONT size=2><FONT size=2> <DIV
align=left> eventList : LinkedList( size >= 5 ) from collect( Event(text matches ".*rule5.*", processed == false<FONT size=2> )) <BR></FONT><B><FONT color=#960000 size=2>then<BR></FONT></B><FONT size=+0><FONT size=2> System.out.println(<FONT color=#008000 size=2>"rule5 is fired "</FONT><FONT size=2> + eventList.size());</FONT> <BR></FONT></FONT><B><FONT color=#960000 size=2> for( int i = 0; i < 5; i++ ) {<BR><SPAN style="FONT-WEIGHT: bold"> Event e = </SPAN></FONT></B><FONT size=2><FONT size=2><B><FONT color=#960000 size=2><SPAN style="FONT-WEIGHT: bold">(Event) eventList.get ( i );</SPAN></FONT></B></FONT></FONT><B><FONT color=#960000 size=2><SPAN style="FONT-WEIGHT: bold"></SPAN><BR><SPAN style="FONT-WEIGHT: bold"> e.setProcessed( true );<BR> update( e ); <BR></SPAN></FONT></B></DIV></FONT></FONT><FONT size=2>
<DIV> }<BR></DIV></FONT>end<BR><BR>2. Retract used facts:<BR><BR> <DIV>when</DIV><FONT size=2><FONT size=2> <DIV align=left> eventList : LinkedList( size >= 5 ) from collect( Event(text matches ".*rule5.*"<FONT size=2> )) <BR></FONT><B><FONT color=#960000 size=2>then<BR></FONT></B><FONT size=+0><FONT size=2> System.out.println(<FONT color=#008000 size=2>"rule5 is fired "</FONT><FONT size=2> + eventList.size());</FONT> <BR></FONT></FONT><B><FONT color=#960000 size=2> for( int i = 0; i < 5; i++ ) {<BR><SPAN style="FONT-WEIGHT: bold"> Event e = </SPAN></FONT></B><FONT size=2><FONT size=2><B><FONT color=#960000 size=2><SPAN style="FONT-WEIGHT: bold">(Event) eventList.get( i );</SPAN></FONT></B></FONT></FONT> <B><FONT color=#960000 size=2><SPAN style="FONT-WEIGHT: bold"></SPAN><BR><SPAN style="FONT-WEIGHT: bold"> retract( e );
<BR></SPAN></FONT></B></DIV></FONT></FONT><FONT size=2> <DIV> }<BR></DIV></FONT>end<BR><BR> Hope it helps.<BR><BR> Edson<BR><SPAN class=gmail_quote></SPAN><BR> <DIV><SPAN class=gmail_quote>2007/8/10, Anh Vuong <<A href="mailto:anhtvuong@yahoo.com">anhtvuong@yahoo.com</A>>:</SPAN> <BLOCKQUOTE class=gmail_quote style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid"> <DIV>Hi,</DIV> <DIV>I'd like to use keyword collect to do my filtering but its behaviour confused me, please advise. I greatly appreciate your help.</DIV> <DIV> </DIV> <DIV>Problem 1:</DIV> <DIV> </DIV> <DIV>when </DIV><FONT size=2><FONT size=2> <DIV align=left>eventList : LinkedList(size == 5)</DIV> <DIV align=left>from collect( Event(text matches </DIV></FONT><FONT color=#008000 size=2>".*rule5.*"</FONT><FONT size=2> )) <DIV align=left></DIV> <DIV align=left></DIV></FONT><B><FONT color=#960000
size=2>then</FONT></B></FONT><FONT size=2> <DIV>System.out.println(</DIV></FONT><FONT color=#008000 size=2>"rule5 is fired " </FONT><FONT size=2>+ eventList.size());</FONT> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>I still do not see any log msg after adding 5+ events. Is something wrong with my rule?</FONT></DIV> <DIV> </DIV> <DIV>Problem 2:</DIV> <DIV> </DIV> <DIV>when</DIV> <DIV>event: Event(text matches <FONT color=#008000 size=2>".*rule5.*"</FONT><FONT size=2> ))</FONT></DIV><FONT size=2><FONT size=2> <DIV align=left>eventList : LinkedList(size == 5)</DIV> <DIV align=left>from collect( Event(text == event.text)</DIV></FONT><FONT size=2> <DIV align=left></DIV> <DIV align=left></DIV></FONT><B><FONT color=#960000 size=2>then </FONT></B></FONT><FONT size=2> <DIV>System.out.println(</DIV></FONT><FONT color=#008000 size=2>"rule5 is fired "</FONT><FONT size=2> + eventList.size());</FONT> <DIV> </DIV> <DIV><FONT size=2>After
adding 5 events, I see 5 log msg instead of one as I'd expect. </FONT></DIV> <DIV>If I add more events, I will see more log. How do I tell LHS to reset the count from 0.</DIV> <DIV>Basically, I want to take 1 event out of 5 similar events (suppressing filtering). So if there are 10 similar events, my RHS should activate 2 times, not 10 times. </DIV> <DIV> </DIV> <DIV>Thanks,</DIV><SPAN class=sg> <DIV>-av</DIV></SPAN><SPAN class=ad> <DIV><FONT size=2></FONT> </DIV> <div></div> <HR SIZE=1> Ready for the edge of your seat? <A onclick="return top.js.OpenExtLink(window,event,this)" href="http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/" target=_blank>Check out tonight's top picks</A> on Yahoo! TV. <div></div></SPAN><BR>_______________________________________________<BR>rules-users mailing list<BR><A onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org </A><BR><A
onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.jboss.org/mailman/listinfo/rules-users" target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR></BLOCKQUOTE></DIV><BR><BR clear=all><BR>-- <BR> Edson Tirelli<BR> Software Engineer - JBoss Rules Core Developer<BR> Office: +55 11 3529-6000<BR> Mobile: +55 11 9287-5646<BR> JBoss, a division of Red Hat @ <A href="http://www.jboss.com/">www.jboss.com</A> _______________________________________________<BR>rules-users mailing list<BR>rules-users@lists.jboss.org<BR>https://lists.jboss.org/mailman/listinfo/rules-users<BR></BLOCKQUOTE><BR><p> 
<hr size=1>Park yourself in front of a world of choices in alternative vehicles.<br><a href="http://us.rd.yahoo.com/evt=48246/*http://autos.yahoo.com/green_center/;_ylc=X3oDMTE5cDF2bXZzBF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDZ3JlZW4tY2VudGVy">Visit the Yahoo! Auto Green Center.</a>