On 28 May 2012 19:30, Bernhard Unger <span dir="ltr"><<a href="mailto:mail@bernhardunger.de" target="_blank">mail@bernhardunger.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello Wolfgang,<br>
<br>
thanks for the answer.<br>
Does that mean the description on page 32 of the Drools Fusion User Guide is<br>
not correct?<br></blockquote><div><br>No, but possibly easy to misunderstand.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
"...<br>
2.6.1. Sliding Time Windows<br>
Sliding Time Windows allow the user to write rules that will only match<br>
events occurring in the<br>
last X time units.<br>
For instance, if the user wants to consider only the Stock Ticks that<br>
happened in the last 2 minutes,<br>
the pattern would look like this:<br>
StockTick() over window:time( 2m )<br>
Drools uses the "over" keyword to associate windows to patterns.<br>
..."<br></blockquote><div><br>The window:time() must be understood as something hooked on "now", as it is understood by<br>the Engine, and it is evaluated once, at the time a fact/event is inserted.<br><br>
<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Do you know a way for my simulation to get only the latest events in between<br>
10 minutes?<br>
Do I need an additional constraint for the rule?<br></blockquote><div><br>Event processing in real time should either be done with an Engine being run<br>by a thread executing "fireUntilHalt()", which needn't ever be called, or by<br>
calling fireAllRules() from the same thread doing the insertions. <br><br>The simple rule you posted isn't different from the same rule <br>without "over window:time(x)", because both are instantaneously fulfilled<br>
due to an insert.<br><br>-W<br><br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Thanks,<br>
<br>
Bernhard<br>
<br>
-----Ursprüngliche Nachricht-----<br>
Von: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] Im Auftrag von Wolfgang Laun<br>
Gesendet: Montag, 28. Mai 2012 15:11<br>
An: Rules Users List<br>
Betreff: Re: [rules-users] Time Sliding Window Question<br>
<br>
<br>
Whenever you insert an event, a simple rule like<br>
ruel x when Event() over window:time(x) then...end<br>
immediately results in an activation. Your for loop merely postpones<br>
firings.<br>
<br>
A selection of an event due to a window:time() is different from a<br>
selection due to a constraint. The latter may result in cancelling the<br>
activation if the fact is modified accordingly. But there's no<br>
reevaluation due to the passage of time.<br>
<br>
-W<br>
<br>
<br>
On 28/05/2012, Bernhard Unger <<a href="mailto:mail@bernhardunger.de">mail@bernhardunger.de</a>> wrote:<br>
> Hello,<br>
><br>
> I am fairly new to Drools and tried my first steps with Drools Fusion and<br>
> was running into the following problem:<br>
><br>
> According to the Drools Fusion User Guide Version 5.4.0.Final on page 32<br>
> the<br>
> following pattern should work and select events in between the last 10<br>
> minutes:<br>
> ...<br>
> StockTick() over window:time( 2m )<br>
> ...<br>
> I tried the following example, simulating RHQ EventComposite Events with a<br>
> simple Junit test:<br>
><br>
> ...<br>
> KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
> kbuilder.add(new ClassPathResource("rhqrules.drl", getClass()),<br>
> ResourceType.DRL);<br>
> KnowledgeBaseConfiguration config =<br>
> KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
> config.setOption(EventProcessingOption.STREAM);<br>
> nowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);<br>
> kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
> KnowledgeSessionConfiguration conf =<br>
> KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
> conf.setOption(ClockTypeOption.get("pseudo"));<br>
> ksession = kbase.newStatefulKnowledgeSession(conf, null);<br>
> ...<br>
> inside the test method:<br>
> ...<br>
> For-Loop inserts new Events and increases the pseudo clock in one minute<br>
> steps:<br>
> ...<br>
> for (int i = 0; i < 100; i++) {<br>
> timestamp = clock.advanceTime(1, TimeUnit.MINUTES);<br>
> ksession.insert(new EventComposite("EventDetail" + i, resourceId,<br>
> "resourceName" + i, "resourceAncestry" + i, resourceTypeId,<br>
> eventId, severity, "sourceLocation" + i, timestamp));<br>
> }<br>
> ...<br>
> ksession.fireAllRules();<br>
> ...<br>
><br>
> The .drl definition should fire only events of the last 10 minutes,<br>
however<br>
> all inserted 100 events are fired:<br>
> declare EventComposite<br>
> @role( event )<br>
> end<br>
> rule "Rule1 events in between last 10 minutes"<br>
> when<br>
> $event : EventComposite() over window:time( 10m )<br>
> then<br>
> System.out.println("Event in between the last 10 minutes:: " +<br>
$event);<br>
> end<br>
><br>
> On the other hand this rule works as expected and selects only events<br>
older<br>
> than 10 minutes:<br>
><br>
> rule "Rule2 events not in between the last 10 minutes"<br>
> when<br>
> $eventA : EventComposite( )<br>
> not EventComposite( this.resourceId == $eventA.resourceId ) over<br>
> window:time( 10m )<br>
><br>
> then<br>
> System.out.println("Event not in between the last 10 minutes: " +<br>
> $eventA);<br>
> end<br>
><br>
><br>
> My question is:<br>
> What did I wrong in the definition of Rule-1, what is the correct<br>
statement<br>
> for finding the last 10 minutes events?<br>
><br>
> Background information:<br>
> I am doing some research on implementing using the drools framework inside<br>
> the RHQ framework for complex event processing. I would like to show that<br>
> this is possible and could be uses reasonable for RHQ event processing.<br>
><br>
> Any help is highly appreceated!<br>
><br>
> Thanks and kind regards<br>
><br>
> Bernhard<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> rules-users mailing list<br>
> <a href="mailto:rules-users@lists.jboss.org">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">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">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>
</blockquote></div><br>