[rules-users] Time Sliding Window Question
Wolfgang Laun
wolfgang.laun at gmail.com
Mon May 28 09:10:50 EDT 2012
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
>
More information about the rules-users
mailing list