Quantcast

[rules-users] Initial rule delay

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[rules-users] Initial rule delay

reverselogic
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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

laune
Try:
   timer( int: <initial> 0 )
-W

On 06/06/2012, Paul R. <[hidden email]> 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

Vincent Legendre
In reply to this post by reverselogic
In 5.4 timers support expressions for values.
You can thus use a fact used to hold timer values (init and delay). This fact is created with some non-zero values, and reset all to zero once a first rule has triggered

rule "delayAtFirstTime" timer(expr: $timerSpec.getDelay()+"s" , "0s")
when
   $timerSpec : TimerSpec()
   ....

then
   ....
   $timerSpec.setDelay(0);
   update($timerSpec);
end


Another solution is to create a fact that enable rule triggering that you insert "later" (may be that's the problematic aspect ...), something like that

rule "DoSomethingWhenYouCan"
when
    exists( OkToGo() )
    ....
then
    ...
end

Note that the OkToGo() fact can be inserted by a rule too ...
rule "OkToGoAfter10s" timer(10s 0)
when
   not( OkToGo() )
then
   insert( new OkToGo() );
end


----- Original Message -----
From: "Paul R." <[hidden email]>
To: "Rules Users List" <[hidden email]>
Sent: Mercredi 6 Juin 2012 16:47:03
Subject: [rules-users] Initial rule delay



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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

Vincent Legendre
In reply to this post by laune
Yes of course ...
Simpler this way ...

----- Original Message -----
From: "Wolfgang Laun" <[hidden email]>
To: "Rules Users List" <[hidden email]>
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. <[hidden email]> 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

reverselogic
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 <[hidden email]> wrote:
Yes of course ...
Simpler this way ...

----- Original Message -----
From: "Wolfgang Laun" <[hidden email]>
To: "Rules Users List" <[hidden email]>
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. <[hidden email]> 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

Vincent Legendre
try with a negative number ?

----- Original Message -----
From: "Paul R." <[hidden email]>
To: "Rules Users List" <[hidden email]>
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 < [hidden email] > wrote:


Yes of course ...
Simpler this way ...


----- Original Message -----
From: "Wolfgang Laun" < [hidden email] >
To: "Rules Users List" < [hidden email] >


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. < [hidden email] > 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users 
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users 


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

laune
In reply to this post by reverselogic


On 6 June 2012 19:26, Paul R. <[hidden email]> wrote:
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].

There's bound to be some other effect that recreates the activation. I've tested this (using 5.4.0) with a simple rule triggering on the presence of a single object, and it fires once, not repeatedly.
-W

 

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 <[hidden email]> wrote:
Yes of course ...
Simpler this way ...

----- Original Message -----
From: "Wolfgang Laun" <[hidden email]>
To: "Rules Users List" <[hidden email]>
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. <[hidden email]> 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
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

Mark Proctor
In reply to this post by Vincent Legendre
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)

Mark

>
> ----- Original Message -----
> From: "Paul R."<[hidden email]>
> To: "Rules Users List"<[hidden email]>
> 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<  [hidden email]>  wrote:
>
>
> Yes of course ...
> Simpler this way ...
>
>
> ----- Original Message -----
> From: "Wolfgang Laun"<  [hidden email]>
> To: "Rules Users List"<  [hidden email]>
>
>
> 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.<  [hidden email]>  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
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

laune
On 07/06/2012, Mark Proctor <[hidden email]> 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."<[hidden email]>
>> To: "Rules Users List"<[hidden email]>
>> 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<
>> [hidden email]>  wrote:
>>
>>
>> Yes of course ...
>> Simpler this way ...
>>
>>
>> ----- Original Message -----
>> From: "Wolfgang Laun"<  [hidden email]>
>> To: "Rules Users List"<  [hidden email]>
>>
>>
>> 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.<  [hidden email]>  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
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

reverselogic
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 <[hidden email]> wrote:
On 07/06/2012, Mark Proctor <[hidden email]> 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."<[hidden email]>
>> To: "Rules Users List"<[hidden email]>
>> 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<
>> [hidden email]>  wrote:
>>
>>
>> Yes of course ...
>> Simpler this way ...
>>
>>
>> ----- Original Message -----
>> From: "Wolfgang Laun"<  [hidden email]>
>> To: "Rules Users List"<  [hidden email]>
>>
>>
>> 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.<  [hidden email]>  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
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users

TimerTest.java (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

laune
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. <[hidden email]> 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
> <[hidden email]>wrote:
>
>> On 07/06/2012, Mark Proctor <[hidden email]> 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."<[hidden email]>
>> >> To: "Rules Users List"<[hidden email]>
>> >> 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<
>> >> [hidden email]>  wrote:
>> >>
>> >>
>> >> Yes of course ...
>> >> Simpler this way ...
>> >>
>> >>
>> >> ----- Original Message -----
>> >> From: "Wolfgang Laun"<  [hidden email]>
>> >> To: "Rules Users List"<  [hidden email]>
>> >>
>> >>
>> >> 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.<  [hidden email]>  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
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >>
>> >>
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> > _______________________________________________
>> > rules-users mailing list
>> > [hidden email]
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] Initial rule delay

reverselogic
Thanks Wolfgang, that works for me.

On Thu, Jun 7, 2012 at 1:14 PM, Wolfgang Laun <[hidden email]> 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. <[hidden email]> 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
> <[hidden email]>wrote:
>
>> On 07/06/2012, Mark Proctor <[hidden email]> 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."<[hidden email]>
>> >> To: "Rules Users List"<[hidden email]>
>> >> 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<
>> >> [hidden email]>  wrote:
>> >>
>> >>
>> >> Yes of course ...
>> >> Simpler this way ...
>> >>
>> >>
>> >> ----- Original Message -----
>> >> From: "Wolfgang Laun"<  [hidden email]>
>> >> To: "Rules Users List"<  [hidden email]>
>> >>
>> >>
>> >> 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.<  [hidden email]>  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
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >>
>> >>
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >> _______________________________________________
>> >> rules-users mailing list
>> >> [hidden email]
>> >> https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> > _______________________________________________
>> > rules-users mailing list
>> > [hidden email]
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Loading...