[rules-users] having counter in drl

Steven Williams stevearoonie at gmail.com
Tue Dec 9 21:32:07 EST 2008


How about adding a flag to Event to indicate it has been processed?
You could then use:

when
  Event(processed == false)
  ...


On Wed, Dec 10, 2008 at 10:56 AM, techy <techluver007 at gmail.com> wrote:

>
> Thanks all for the reply.
> I executed following rules after adding Event fact id ranges from 1 to 8.
> Output is given below. counter rule was not executed for distinct event
> fact. some help please.
>
> output :
> -----------------------------
> adding counter
> new count value: 4 , event : 8
> new count value: 3 , event : 7
> new count value: 2 , event : 8
> new count value: 1 , event : 7
> -------------------------------
>
> rule "init"
> lock-on-active true
> when
>        then
>                System.out.println("adding counter");
>                        Counter c = new Counter(4);// init with max count
> value
>                        insert(c);
>
> end
>
> rule "counter"
> no-loop true
>        when
>        event : Event()
>        counter : Counter(count > 0)
>        then
>        System.out.println("new count value: "+counter.getCount()+" , event
> :
> "+event.getEventId());
>        counter.setCount(counter.getCount()-1);
>        update(counter);
> end
>
>
>
>
> dave sinclair wrote:
> >
> > Make counter an object
> >
> > when
> >     $counter : Counter(value <= 100)
> > ...
> >
> >
> > On Mon, Dec 8, 2008 at 5:05 PM, techy <techluver007 at gmail.com> wrote:
> >
> >>
> >> Hello,
> >> I would like to take 100 sampling facts for rule and persist it in the
> db
> >> and ignore other data.
> >> How Can I maintain the counter? as global variable? Please clarify with
> >> sample code.
> >> I tried following way and but it does not work as expected.
> >>
> >> Ex:
> >> global Integer counter;
> >> rule "get sampling data"
> >>   when fact : Foo(some condition) && eval(counter <= 100)
> >>   then
> >>    counter++
> >>   // do some condition
> >> end
> >> --
> >> View this message in context:
> >> http://www.nabble.com/having-counter-in-drl-tp20904469p20904469.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
> >>
> >
> > _______________________________________________
> > 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/having-counter-in-drl-tp20904469p20926420.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
>



-- 
Steven Williams

Supervising Consultant

Object Consulting
Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501
steven.williams at objectconsulting.com.au
www.objectconsulting.com.au

consulting | development | training | support
our experience makes the difference
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20081210/8f312307/attachment.html 


More information about the rules-users mailing list