[rules-users] Best approach for inserting facts into Drools

Wolfgang Laun wolfgang.laun at gmail.com
Tue Dec 15 05:22:29 EST 2009


On Mon, Dec 14, 2009 at 8:31 PM, Matias <matias.ordonez at globant.com> wrote:

>
> Hi, this is my first time with Drools and I would really appreciate if
> someone can give me some advice on the following:
>
> Welcome, and see below.



> Scenario:
> * There is a list of objects 'A' which is updated periodically (initially
> every 1 min.)
> * In the meantime I would like to run a set of 40 rules on 'A' to modify a
> second list 'B'.
> * 'A' may contain more than a thousand objects (its size might grow up to a
> few thousands or shrink on every update – i.e. its size is not constant on
> each update).
>

Is it essential for the conditions of your rules that A's elements are in a
List<?>
or Map<?,?> or whatever? I guess not, so having a Collection<?> as one fat
fact and write your conditions against it is usually not recommended.

If your conditions deal with properties of A's elements, then insert
individual
elements and modify and retract them on the rules' RHS.

If you do need collections A and B for some purpose, you might make them
available as
additional facts or as globals and operate on them in addition to whatever
needs to be done for the elements. For instance, if a RHS would need to
remove an
element, you would have

   rule KillBill
   when
      $e : ElemA( name == "Bill" )
      $a : ListA()
   then
      retract( $e );
      $a.remove( $e );
   end


> My question to the list is: “What is the best approach I should follow to
> insert facts into Drools, i.e. To populate and update the ksession data ?”
> Please see my questions in more detail below as Q1, Q2 and Q3.
>
> In other words, which one of the two following approaches is recommended ?
>
> 1) Insert every single item from 'A' and 'B' into the ksession.
>    Q1: For the objects that changed inside, Do I need to notify Drools ? If
> I do, I guess I'll need a fact-handler for each item on the list.
>

What do you mean by "fact-handler"? Using modify takes care of notifying the
Engine.


>
> 2) Insert the lists 'A' and 'B' in the session
>   Q2: 'A' is actually a TreeMap<String, Object>. Would it be more
> convenient to insert it as a list ?
>
> Q3) In terms of performance, which of the 2 approaches above is the best –
> or shall I definitely avoid one ?
>

This is not an issue of performance. I simply cannot imagine a reasonable
set of 40 rules that operate on a List<?> rather than its elements - but, of
course, one never knows ;-)

-W


>
> Thanks,
> Matias
> --
> View this message in context:
> http://n3.nabble.com/Best-approach-for-inserting-facts-into-Drools-tp90473p90473.html
> Sent from the Drools - User mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091215/c6e5c5ea/attachment.html 


More information about the rules-users mailing list