[rules-users] Creating objects in WHEN clause

Greg Barton greg_barton at yahoo.com
Mon Mar 2 13:17:58 EST 2009


Well, since the StatelessSession is basically a convenience wrapper around a StatefulSession I figure it should be possible.  On StatefulSession, which extends WorkingMemory, you just call setFocus() before firing the rules.  I'm not sure what the best way to do this with a StatelessSession would be.  I can think of some hacks, but would rather not lead you down a garden path. :)  Dev d00ds, any comment?

--- On Sun, 3/1/09, David Boaz <davidb at dbmotion.com> wrote:

> From: David Boaz <davidb at dbmotion.com>
> Subject: Re: [rules-users] Creating objects in WHEN clause
> To: rules-users at lists.jboss.org
> Date: Sunday, March 1, 2009, 5:03 AM
> Thanks Greg,
> I tried to apply your solution proposed bellow, but had
> problem setting the
> initial "agenda-group". I'm using Drools
> 5.0.0.M4 version, and working with
> a StatelessSession API.
> Can you please give an example how to set the initial
> "agenda-group" from
> the StatelessSession API?
> 
> BTW, regarding the discussion we had, whether to use FROM
> or WorkingMemory
> objects, is it applicable also when using a stateless
> session?
> 
> Thanks, David
> 
> 
> Greg Barton wrote:
> > 
> > I'd second this idea, and to get around the
> inconcenience of inserting the
> > Quantity objects from the calling application, use a
> rule that fires once
> > on initialization.
> > 
> > rule
> > no-loop true
> > when
> > //No condition
> > then 
> >   insert(new Quantity("m", 2));
> > end
> > 
> > This rule should fire first.  You could also put it in
> it's own
> > agenda-group (call it "initialization" or
> some such) and set focus to that
> > group when starting.
> > 
> > rule
> > agenda-group "initialization"
> > no-loop true
> > when
> > //No condition
> > then 
> >   insert(new Quantity("m", 2));
> >  
> drools.setFocus("whatever_your_next_group_is");
> > end
> > 
> > --- On Wed, 2/25/09, Mauricio Salatino
> <salaboy at gmail.com> wrote:
> > 
> >> From: Mauricio Salatino <salaboy at gmail.com>
> >> Subject: Re: [rules-users] Creating objects in
> WHEN clause
> >> To: "Rules Users List"
> <rules-users at lists.jboss.org>
> >> Date: Wednesday, February 25, 2009, 11:40 AM
> >> How about :
> >>  WHEN
> >> $quantity: Quantity(value == 2, unit ==
> "m")
> >> $Person($height == $quantity:)
> >> then
> >> ...
> >> 
> >> 
> >> 
> >> On Wed, Feb 25, 2009 at 2:27 PM, David Boaz
> >> <davidb at dbmotion.com> wrote:
> >> >
> >> > In my application, we often compare the
> fact's
> >> field values against a known
> >> > object. For example:
> >> > WHEN person(height> new Quantity(2,
> "m"))
> >> // the height is greater than 2
> >> > meters.
> >> > will DROOLS create a "singleton"
> Quantity
> >> object, or will it create one
> >> > object for each fact evaluation?
> >> >
> >> > We consider using anoter approach, using
> GLOBALS.
> >> Then, the Quantity object
> >> > will be created applicatively, and passed by
> the API
> >> to the engine.
> >> > something like:
> >> > GLOBAL Quantity 2meters
> >> > WHEN person(height > 2meters)
> >> > But this approach is combersom, because the
> rule
> >> author has to define part
> >> > of the information in the calling
> application, and
> >> part in the rule.
> >> >
> >> > Do you have a good practice how to handle
> these
> >> situations?
> >> >
> >> > Thanks, David
> >> > --
> >> > View this message in context:
> >>
> http://www.nabble.com/Creating-objects-in-WHEN-clause-tp22207616p22207616.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
> >> >
> >> 
> >> 
> >> 
> >> -- 
> >>  - Salatino Mauricio -
> >> _______________________________________________
> >> 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
> > 
> > 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Creating-objects-in-WHEN-clause-tp22207616p22271386.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


      



More information about the rules-users mailing list