[rules-users] Initial rule delay

Paul R. reverselogic at gmail.com
Thu Jun 7 14:50:31 EDT 2012


Thanks Wolfgang, that works for me.

On Thu, Jun 7, 2012 at 1:14 PM, Wolfgang Laun <wolfgang.laun at gmail.com>wrote:

> The several distinct activations created from the rule fire once. To
> see this, add this snippet:
>
>    session.addEventListener( new DefaultAgendaEventListener() {
>        public void beforeActivationFired(BeforeActivationFiredEvent event)
> {
>            super.beforeActivationFired( event );
>            System.out.println( "EVENT FIRED: " + event );
>        }
>        public void activationCreated(ActivationCreatedEvent event) {
>            super.activationCreated( event );
>            System.out.println( "EVENT CREATED: " + event );
>        }
>  } );
>
> Also, continue after the loop inserting the events:
>
>   for (long i = 1; i <= 100; i++) {
>            clock.advanceTime(1, TimeUnit.SECONDS);
>            session.setGlobal("time", clock.getCurrentTime());
>            session.fireAllRules();
>    }
>
> Your wish to have the first activation delayed by the timer's initial
> delay is always granted. But you can't have the very same rule firing
> as if there were no timer at all.
>
> So I guess you'll have to use the approach where a trigger fact is
> inserted.
>
> declare Trigger
> end
>
> rule FirstFoo
> timer (int: 5s)
> when
>    not Trigger()
>    Foo() from entry-point EntryPoint
> then
>    insert( new Trigger() );
> end
>
> rule test
> when
>   Trigger()
>   $count : Number() from accumulate(
>       $f : Foo() over window:time(5000ms) from entry-point EntryPoint,
>       count($f) )
> then
>   System.out.println("count = " + $count + ", time = " + time + "ms");
> end
>
> Simple enough, I'd say.
> -W
>
>
> On 07/06/2012, Paul R. <reverselogic at gmail.com> wrote:
> > Hi Wolfgang,
> >
> > I've attached a simple test case, which demonstrates the repetitions. If
> > you run it, you'll see that the rule fires 3 times. [Tested in 5.4]
> >
> > count = 5, time = 5000ms
> > count = 5, time = 10000ms
> > count = 5, time = 15000ms
> >
> > Changing the repeat-interval to 0 has identical results. Changing to a
> > negative number [suggested earlier] causes an infinite loop in Drools.
> >
> > To clarify, what I'm trying to do is block the rule from firing for the
> > first 5 seconds and then fire normally after that ( as if there was no
> > timer ). For example. The output I'm trying to achieve (not necessarily
> > with timers) is:
> >
> > count = 5, time = 5000ms
> > count = 5, time = 6000ms
> > count = 5, time = 7000ms
> > count = 5, time = 8000ms
> > count = 5, time = 9000ms
> > count = 5, time = 10000ms
> > count = 5, time = 11000ms
> > count = 5, time = 12000ms
> > count = 5, time = 13000ms
> > count = 5, time = 14000ms
> > count = 5, time = 15000ms
> >
> > Thanks & Regards,
> >
> > Paul
> >
> > On Thu, Jun 7, 2012 at 7:41 AM, Wolfgang Laun
> > <wolfgang.laun at gmail.com>wrote:
> >
> >> On 07/06/2012, Mark Proctor <mproctor at codehaus.org> wrote:
> >> > On 06/06/2012 18:39, Vincent LEGENDRE wrote:
> >> >> try with a negative number ?
> >> > I would ommit the number all together. I suspect what 0 does is
> >> > schedule
> >> > with intervals of 0s, thus it fires straight away.
> >> > timer(int: 5s)
> >>
> >> @myself: I really should RFTM before proposing risky (if working)
> >> workarounds.
> >>
> >> The OP's claim  "if the repeat interval is omitted, it uses the
> >> initial delay as the repeat interval" is, untrue; DRL timer's
> >> definition is in line with all similar APIs and definitions, i.e.,
> >> when the repeat interval is omitted, then it's a one shot timer.
> >>
> >> @Paul: As I wrote in a previous mail - there's got to be another
> >> effect that causes the repetitions. Note that a live timer is
> >> connected to an *activation*, which isn't the same as being connected
> >> to a *rule*:
> >>   1 rule - n activations - n timers - x firings.
> >>
> >> -W
> >>
> >> >
> >> > Mark
> >> >>
> >> >> ----- Original Message -----
> >> >> From: "Paul R."<reverselogic at gmail.com>
> >> >> To: "Rules Users List"<rules-users at lists.jboss.org>
> >> >> Sent: Mercredi 6 Juin 2012 19:26:22
> >> >> Subject: Re: [rules-users] Initial rule delay
> >> >>
> >> >>
> >> >> Thanks Wolfgang, but setting the repeat-interval to 0 seems to have
> >> >> the
> >> >> same effect as omitting the repeat-interval [Tested in 5.1&  5.4].
> >> >>
> >> >>
> >> >> Thanks Vincent, this seems to work. However I was hoping for a
> simpler
> >> >> solution :)
> >> >>
> >> >>
> >> >> - Paul
> >> >>
> >> >> On Wed, Jun 6, 2012 at 5:06 PM, Vincent LEGENDRE<
> >> >> vincent.legendre at eurodecision.com>  wrote:
> >> >>
> >> >>
> >> >> Yes of course ...
> >> >> Simpler this way ...
> >> >>
> >> >>
> >> >> ----- Original Message -----
> >> >> From: "Wolfgang Laun"<  wolfgang.laun at gmail.com>
> >> >> To: "Rules Users List"<  rules-users at lists.jboss.org>
> >> >>
> >> >>
> >> >> Sent: Mercredi 6 Juin 2012 18:02:40
> >> >> Subject: Re: [rules-users] Initial rule delay
> >> >>
> >> >> Try:
> >> >> timer( int:<initial>  0 )
> >> >> -W
> >> >>
> >> >> On 06/06/2012, Paul R.<  reverselogic at gmail.com>  wrote:
> >> >>> Hi,
> >> >>>
> >> >>> I'm looking for a way to delay a rules initial execution? In the
> >> >>> following
> >> >>> example, I would like to prevent the rule from firing when the first
> >> >>> "Foo"
> >> >>> event is inserted into the working memory.
> >> >>>
> >> >>> rule "DelayTest" when $n : Number() from accumulate( $f : Foo() over
> >> >>> window:time(10s) count($f) ) then // bla end
> >> >>>
> >> >>> The timer attribute seems to almost support what I'm looking for,
> >> >>> i.e.
> >> >>> it
> >> >>> allows for an initial-delay to be specified; but if the repeat
> >> >>> interval
> >> >>> is
> >> >>> omitted, it uses the initial delay as the repeat interval.
> >> >>>
> >> >>> timer ( int:<initial delay>  <repeat interval>? )
> >> >>>
> >> >>> In my case I would like to block the execution of the rule for an
> >> >>> "initial-delay" period, but after that time has elapsed the rule
> >> >>> should
> >> >>> fire when every time a new "Foo" event is inserted into the working
> >> >>> memory.
> >> >>> What is the recommended way to do this?
> >> >>>
> >> >>> Thanks&  Regards,
> >> >>>
> >> >>> Paul
> >> >>>
> >> >> _______________________________________________
> >> >> 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
> >> >>
> >> >>
> >> >> _______________________________________________
> >> >> 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
> >> >
> >> > _______________________________________________
> >> > 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
> >>
> >
> _______________________________________________
> 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/20120607/72fa88d6/attachment-0001.html 


More information about the rules-users mailing list