On Mon, Dec 14, 2009 at 8:31 PM, Matias <span dir="ltr">&lt;<a href="mailto:matias.ordonez@globant.com">matias.ordonez@globant.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi, this is my first time with Drools and I would really appreciate if<br>
someone can give me some advice on the following:<br>
<br></blockquote><div>Welcome, and see below.<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Scenario:<br>
* There is a list of objects &#39;A&#39; which is updated periodically (initially<br>
every 1 min.)<br>
* In the meantime I would like to run a set of 40 rules on &#39;A&#39; to modify a<br>
second list &#39;B&#39;.<br>
* &#39;A&#39; may contain more than a thousand objects (its size might grow up to a<br>
few thousands or shrink on every update – i.e. its size is not constant on<br>
each update).<br></blockquote><div><br>Is it essential for the conditions of your rules that A&#39;s elements are in a List&lt;?&gt;<br>or Map&lt;?,?&gt; or whatever? I guess not, so having a Collection&lt;?&gt; as one fat<br>
fact and write your conditions against it is usually not recommended.<br><br>If your conditions deal with properties of A&#39;s elements, then insert individual<br>elements and modify and retract them on the rules&#39; RHS.<br>
<br>If you do need collections A and B for some purpose, you might make them available as<br>additional facts or as globals and operate on them in addition to whatever<br>needs to be done for the elements. For instance, if a RHS would need to remove an<br>
element, you would have<br><br>   rule KillBill<br>   when<br>      $e : ElemA( name == &quot;Bill&quot; )<br>      $a : ListA()<br>   then<br>      retract( $e );<br>      $a.remove( $e );<br>   end <br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
My question to the list is: “What is the best approach I should follow to<br>
insert facts into Drools, i.e. To populate and update the ksession data ?”<br>
Please see my questions in more detail below as Q1, Q2 and Q3.<br>
<br>
In other words, which one of the two following approaches is recommended ?<br>
<br>
1) Insert every single item from &#39;A&#39; and &#39;B&#39; into the ksession.<br>
    Q1: For the objects that changed inside, Do I need to notify Drools ? If<br>
I do, I guess I&#39;ll need a fact-handler for each item on the list.<br></blockquote><div><br>What do you mean by &quot;fact-handler&quot;? Using modify takes care of notifying the<br>Engine.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
2) Insert the lists &#39;A&#39; and &#39;B&#39; in the session<br>
   Q2: &#39;A&#39; is actually a TreeMap&lt;String, Object&gt;. Would it be more<br>
convenient to insert it as a list ?<br>
<br>
Q3) In terms of performance, which of the 2 approaches above is the best –<br>
or shall I definitely avoid one ?<br></blockquote><div><br>This is not an issue of performance. I simply cannot imagine a reasonable<br>set of 40 rules that operate on a List&lt;?&gt; rather than its elements - but, of<br>
course, one never knows ;-) <br><br>-W<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Thanks,<br>
Matias<br>
<font color="#888888">--<br>
View this message in context: <a href="http://n3.nabble.com/Best-approach-for-inserting-facts-into-Drools-tp90473p90473.html" target="_blank">http://n3.nabble.com/Best-approach-for-inserting-facts-into-Drools-tp90473p90473.html</a><br>

Sent from the Drools - User mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>