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