<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><DIV>&nbsp;</DIV>
<DIV>Wolfgang, so I don't improperly interpret your suggestion, it may be better if you add your suggestion to the ticket.&nbsp; This is the ticket I logged: <A href="https://jira.jboss.org/browse/JBRULES-2723">https://jira.jboss.org/browse/JBRULES-2723</A></DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,</DIV>
<DIV>Norman<BR></DIV>
<DIV style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 10pt"><BR>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Wolfgang Laun &lt;wolfgang.laun@gmail.com&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Rules Users List &lt;rules-users@lists.jboss.org&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Tue, October 5, 2010 11:34:53 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [rules-users] fireUntilHalt and timing of rule activations<BR></FONT><BR>Norman,<BR><BR>if you create the Jira, please include my suggestion to make this call accept a collection of facts without any intervening Engine activity.<BR><BR>Thanks<BR>-W<BR><BR>
<DIV class=gmail_quote>2010/10/5 Norman C <SPAN dir=ltr>&lt;<A href="mailto:rent_my_time@yahoo.com" rel=nofollow target=_blank ymailto="mailto:rent_my_time@yahoo.com">rent_my_time@yahoo.com</A>&gt;</SPAN><BR>
<BLOCKQUOTE style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>
<DIV>
<DIV style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 12pt">
<DIV>&nbsp;</DIV>
<DIV><FONT size=2>Thanks for the suggestions.&nbsp; They all look like good ways to handle the situation I described.&nbsp; However, they require modifying all of the rules to check for the latch object and its state, which I would prefer not to do and doesn't seem like&nbsp;would be necessary.</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>It seems to me that this is something that Drools can handle internally without the rules having to be written this way.&nbsp; Since the rules engine processes rules in a single thread, it's a concurrency issue.&nbsp; fireUntilHalt should be blocked when a fact is inserted/updated/retracted, until all activations as a result of that change in working memory are completed.&nbsp; </FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Thoughts?</FONT></DIV>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>Norman</FONT></P>
<DIV><BR></DIV>
<DIV style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 12pt"><BR>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Tahoma>
<HR SIZE=1>

<DIV class=im><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Wolfgang Laun &lt;<A href="mailto:wolfgang.laun@gmail.com" rel=nofollow target=_blank ymailto="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</A>&gt;<BR></DIV>
<DIV class=im><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Rules Users List &lt;<A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A>&gt;<BR></DIV><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Sun, October 3, 2010 10:51:08 PM 
<DIV>
<DIV></DIV>
<DIV class=h5><BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [rules-users] fireUntilHalt and timing of rule activations<BR></DIV></DIV></FONT>
<DIV>
<DIV></DIV>
<DIV class=h5><BR>2010/10/4 Greg Barton <SPAN dir=ltr>&lt;<A href="mailto:greg_barton@yahoo.com" rel=nofollow target=_blank ymailto="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</A>&gt;</SPAN><BR>
<DIV class=gmail_quote>
<BLOCKQUOTE style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>If you don't have some way of associating the data with a particular Latch it's easy to get overlap when processing datasets. &nbsp;In general you need some way to group the data together. &nbsp;You can avoid a back reference to the Latch by having a Set of some sort in the Latch to which you add all data in the batch.</BLOCKQUOTE>
<DIV><BR>Which burdens all inserts and retracts to be accompanied by correpsonding updates of the Set/Map.<BR>&nbsp;</DIV>
<BLOCKQUOTE style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>&nbsp;If you use a Set backed by an IdentityHashMap the overhead is pretty small, and rules look like this:<BR>
<DIV><BR>rule "CountAs"<BR>&nbsp; &nbsp; &nbsp; &nbsp;dialect "java"<BR>&nbsp; &nbsp; &nbsp; &nbsp;salience -1<BR>&nbsp; &nbsp; &nbsp; &nbsp;when<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;l : Latch()<BR></DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a : A( this memberOf l.dataSet )<BR>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp;then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retract(a);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;l.incACount();<BR></DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("Found an A in " + l);<BR>end<BR><BR>See attached project.<BR><BR>THough I like the cleverness of using the "data in matched objects alters rule properties" trick, you could have just as easily had a "Latch(value == true)" conditional, and that would be more clear,</BLOCKQUOTE>
<DIV><BR>It was meant to emphasize the role of Latch.value as an enabler for the rule in contrast to a regular constraint being part of the application logic. YMMV ;-)<BR><BR>&nbsp;</DIV>
<BLOCKQUOTE style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>IMO. &nbsp;I'm curious to see of the enabled trick would perform better, though.<BR></BLOCKQUOTE>
<DIV><BR>Whichever way, there is a considerable burden associated with writing the rules and, possibly, inserts and retracts. I wonder what the benefits of having the session run all the time are as opposed to simply let it fire until it stops; then do the inserts and then fireUntilHalt again? If there is, I'd opt for the addition of an atomic insertAll(Object... objects) and then none of this hocus-pocus would be necessary.<BR><BR>-W<BR>&nbsp;</DIV>
<BLOCKQUOTE style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote><BR>GreG<BR><BR>--- On Sun, 10/3/10, Wolfgang Laun &lt;<A href="mailto:wolfgang.laun@gmail.com" rel=nofollow target=_blank ymailto="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</A>&gt; wrote:<BR><BR>From: Wolfgang Laun &lt;<A href="mailto:wolfgang.laun@gmail.com" rel=nofollow target=_blank ymailto="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</A>&gt;<BR>Subject: Re: [rules-users] fireUntilHalt and timing of rule activations<BR>To: "Rules Users List" &lt;<A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A>&gt;<BR>Date: Sunday, October 3, 2010, 4:23 AM<BR>
<DIV>
<DIV></DIV>
<DIV><BR>There is another way of associating a Latch object with rules, without having to store a reference to a Latch in objects:<BR><BR>rule "CountAs"<BR>enabled ( $v )<BR>when<BR>&nbsp;&nbsp;&nbsp;&nbsp; Latch( $v : value )<BR>&nbsp;&nbsp;&nbsp;&nbsp; X( ... )<BR><BR>then ... end<BR><BR>At the beginning, insert Latch( false ), which blocks all rules with this construction, or modify the Latch object to false before inserting more facts. Then, insert the facts, and, at the end, modify Latch to true.<BR><BR><BR>&nbsp;&nbsp;&nbsp; Latch latch = new Latch( true );<BR>&nbsp;&nbsp;&nbsp; FactHandle fh = kSession.insert( latch );<BR>&nbsp;&nbsp;&nbsp; kSession.fireAllRules();<BR>&nbsp;&nbsp;&nbsp; latch.setValue( false );<BR>&nbsp;&nbsp;&nbsp; kSession.update( fh, latch );<BR><BR>Of course, you can use multiple Latch objects, adding a name field with a specific value, so that a latch applies to a subset of rules only:<BR><BR><BR>rule "CountAs"<BR><BR>enabled
 ( $v )<BR><BR>when<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; Latch( name == "CountAs", $v : value )<BR>&nbsp;&nbsp;&nbsp;&nbsp; ...<BR><BR>But be aware that changes to Latch objects will retrigger rules that have fired previously; so with this approach you'll have to make sure to retract facts when they have been processed.<BR><BR><BR>-W<BR><BR><BR>2010/10/3 Greg Barton &lt;<A href="mailto:greg_barton@yahoo.com" rel=nofollow target=_blank ymailto="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</A>&gt;<BR><BR>Nope, you're not missing anything. &nbsp;What you need is a control object of some sort thst's inserted after all of the "real" data is inserted. (See attached project for an example.) Rules will look like this, if the control object is called BatchLatch and data objects A:<BR><BR><BR><BR><BR>rule "CountAs"<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dialect "java"<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;salience -1<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp;
 &nbsp;when<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;l : Latch()<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a : A( latch == l )<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;then<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retract(a);<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;l.incACount();<BR><BR>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println("Found an A in " + bl);<BR><BR>end<BR><BR><BR><BR>Note that the A object being processed is tied back to the latch. &nbsp;This is so multiple latches can be processed simultaneously and their processing won't be intermingled. &nbsp;This is necessary because there's no guarantee that two Latch objects aren't in working memory at once. (Though you could create a rule that enforces this.)<BR><BR><BR><BR><BR>GreG<BR><BR><BR><BR>--- On Sat, 10/2/10, Norman C &lt;<A
 href="mailto:rent_my_time@yahoo.com" rel=nofollow target=_blank ymailto="mailto:rent_my_time@yahoo.com">rent_my_time@yahoo.com</A>&gt; wrote:<BR><BR><BR><BR>&gt; From: Norman C &lt;<A href="mailto:rent_my_time@yahoo.com" rel=nofollow target=_blank ymailto="mailto:rent_my_time@yahoo.com">rent_my_time@yahoo.com</A>&gt;<BR><BR>&gt; Subject: [rules-users] fireUntilHalt and timing of rule activations<BR><BR>&gt; To: <A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><BR>&gt; Date: Saturday, October 2, 2010, 10:22 AM<BR><BR>&gt; Hi All,<BR><BR>&gt;<BR><BR>&gt; In my app, I have a separate thread calling fireUntilHalt()<BR><BR>&gt; continuously.&nbsp; I<BR><BR>&gt; have quite a few rules, and I am using salience extensively<BR><BR>&gt; to control the order<BR><BR>&gt;<BR><BR>&gt; in which rules are executed.&nbsp; What I have seen (by adding<BR><BR>&gt; an
 event listener) is<BR><BR>&gt; that as a new fact is inserted, various rules are<BR><BR>&gt; activated.&nbsp; Often, the<BR><BR>&gt; fireUntilHalt will start executing fireNextItem in<BR><BR>&gt; DefaultAgenda before all of<BR><BR>&gt; the activations are complete.&nbsp; So if&nbsp;the rule with the<BR><BR>&gt; highest salience<BR><BR>&gt; value&nbsp;hasn't been activated at this point, then the first<BR><BR>&gt; rule to be fired isn't<BR><BR>&gt;<BR><BR>&gt; the correct one.<BR><BR>&gt;<BR><BR>&gt; This can be worked around by waiting for insert to return<BR><BR>&gt; and then calling<BR><BR>&gt; fireAllRules().&nbsp; But it seems like the session should<BR><BR>&gt; block fireUntilHalt from<BR><BR>&gt; trying to execute activated rules until all activations are<BR><BR>&gt; complete.&nbsp; Or am I<BR><BR>&gt; missing something here?<BR><BR>&gt;<BR><BR>&gt; thanks,<BR><BR>&gt; Norman<BR><BR>&gt;<BR><BR>&gt;<BR><BR>&gt; &nbsp; &nbsp;
 &nbsp;<BR><BR>&gt;<BR><BR>&gt;<BR><BR>&gt; _______________________________________________<BR><BR>&gt; rules-users mailing list<BR><BR>&gt; <A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><BR>&gt; <A href="https://lists.jboss.org/mailman/listinfo/rules-users" rel=nofollow target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR>&gt;<BR><BR><BR><BR><BR><BR>&nbsp;&nbsp; &nbsp; &nbsp;<BR>_______________________________________________<BR><BR>rules-users mailing list<BR><BR><A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><BR><A href="https://lists.jboss.org/mailman/listinfo/rules-users" rel=nofollow target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR><BR><BR><BR><BR></DIV></DIV>-----Inline Attachment
 Follows-----<BR>
<DIV>
<DIV></DIV>
<DIV><BR>_______________________________________________<BR>rules-users mailing list<BR><A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/rules-users" rel=nofollow target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR><BR><BR>&nbsp; &nbsp; &nbsp;</DIV></DIV><BR>_______________________________________________<BR>rules-users mailing list<BR><A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/rules-users" rel=nofollow target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR></BLOCKQUOTE></DIV><BR></DIV></DIV></DIV></DIV></DIV><BR></DIV><BR>_______________________________________________<BR>rules-users mailing
 list<BR><A href="mailto:rules-users@lists.jboss.org" rel=nofollow target=_blank ymailto="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/rules-users" rel=nofollow target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR></BLOCKQUOTE></DIV><BR></DIV></DIV></div><br>

      </body></html>