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