Re: [rules-users] counter in slidingTime window with restriction
Please open a JIRA ticket and post your test case, we'll investigate Davide On 09/08/2013 11:31 PM, amarok wrote: > I tried to narrow it down a little but have no idea where the erroneous > firing of "slidingTimeCount" comes from. It annoys me especially because I > want to know when rules fire and why. I tried debugging with eclipse but it > doesnt bring me much further (the debugger stops at least 3 times for each > event in this rule, whereas it is fired only once - I never got too many > outputs when debugging, but I sometimes get the "0" output (apparently when > I am slow) -> this is weird behaviour > > how can the condition be evaluated before the accumulation is reduced? > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Getting-data-from-a-database-My-SQL-to-Guvnor-tp4025814p4025869.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counter in slidingTime window with restriction
I tried to narrow it down a little but have no idea where the erroneous firing of "slidingTimeCount" comes from. It annoys me especially because I want to know when rules fire and why. I tried debugging with eclipse but it doesnt bring me much further (the debugger stops at least 3 times for each event in this rule, whereas it is fired only once - I never got too many outputs when debugging, but I sometimes get the "0" output (apparently when I am slow) -> this is weird behaviour how can the condition be evaluated before the accumulation is reduced? -- View this message in context: http://drools.46999.n3.nabble.com/Getting-data-from-a-database-My-SQL-to-Guvnor-tp4025814p4025869.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counter in slidingTime window with restriction
It's interesting to compare Thread.sleep(1000*60*1); with for(int i=0; i<60; i++ ){ kSession.fireAllRules(); Thread.sleep(1005); } where the spurious erroneous firing of "slidingTimeCount" does not fire. What (I think) happens, is that one additional activation of "slidingTimeCount" is created while the count is still > 0, but it never fires. Then, the accumulate/window reduces the accumulated collection but the constraint intValue > 0 is not tested. Due to the deplorable lack of documentation I can't say that you shouldn't run sessions in STREAM mode with repeated fireAllRules() and random sleeps to let the time pass. In addition to calling fireAllRules() repeatedly, it is also preferable to run the session using fireUntilHalt(), inserting from parallel threads. Again, no light is shed on this by even a shred of documentation... Cheers -W On 06/09/2013, Alexander Wolf wrote: > Drools Version 5.5.0 FINAL > > Here's the code for session setup: > > KnowledgeBuilder kbuilder = > KnowledgeBuilderFactory.newKnowledgeBuilder(); > kbuilder.add(ResourceFactory.newClassPathResource("myrule.drl"), > ResourceType.DRL); > > // Check the builder for errors > if (kbuilder.hasErrors()) { > System.out.println(kbuilder.getErrors().toString()); > throw new RuntimeException("Unable to compile \"myrule.drl\"."); > } > > KnowledgeBase kbase = kbuilder.newKnowledgeBase(); > //configure knowledge base > KnowledgeBaseConfiguration baseConfig = > KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); > baseConfig.setOption( EventProcessingOption.STREAM ); > > //init session clock > KnowledgeSessionConfiguration sessionConfig = > KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); > sessionConfig.setOption( ClockTypeOption.get("realtime") ); > //init stateful knowledge session > StatefulKnowledgeSession ksession = > kbase.newStatefulKnowledgeSession(sessionConfig, null); > > > And here's how I inserted the events for testing purpose: > > > //get Knowledge Base > StatefulKnowledgeSession ksession = initKnowledgeSession(); > > //entry point for sensor events > WorkingMemoryEntryPoint sensorEventStream = > ksession.getWorkingMemoryEntryPoint( "SensorEventStream" ); > > Room room = new Room(24); > ksession.insert(room); > System.out.println("1. fireAllRules()"); > ksession.fireAllRules(); > //insert events > for(int i=2;i<8;i++){ > SensorEvent event = new SensorEvent("inc" + (i-1)); > sensorEventStream.insert( event ); > > System.out.println(i + ". fireAllRules()"); > ksession.fireAllRules(); > Thread.sleep(1005); > } > > //let thread sleep for another 1m to see if dereffered rules fire > (timers, > (not) after rules) > Thread.sleep(1000*60*1); > > ksession.dispose(); > > > > On 05.09.2013, at 12:02, Wolfgang Laun wrote: > >> Hard to believe, but who knows. >> >> Drools version and session setup, please. >> >> -W >> >> >> On 05/09/2013, Alexander Wolf wrote: >>> Hey guys, >>> >>> I wrote a rule to count the SensorEvents in my KnowledgeSession that >>> have >>> been inserted via entry-point SensorEventStream over the last 3 seconds >>> - >>> but I only want the event to fire, if there were any events in the last >>> 3 >>> seconds at all. >>> >>> Problem: if there were no recent events, i still get the output: >>> Events in last 3 seconds: 0 >>> >>> I don't really get why?! This is my rule code: >>> >>> >>> rule "slidingTimeCount" >>> when >>> $n: Number (intValue > 0) from accumulate ( $e: SensorEvent() over >>> window:time(3s) from entry-point SensorEventStream, count($e)) >>> then >>> System.out.println("Events in last 3 seconds: " + $n); >>> end >>> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users > > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counter in slidingTime window with restriction
Ah sorry: the output: 1. fireAllRules() 2. fireAllRules() Events in last 3 seconds: 1 3. fireAllRules() Events in last 3 seconds: 2 4. fireAllRules() Events in last 3 seconds: 3 5. fireAllRules() Events in last 3 seconds: 3 6. fireAllRules() Events in last 3 seconds: 3 7. fireAllRules() Events in last 3 seconds: 3 20sec after room was modified Events in last 3 seconds: 0 -- there is another rule in drl file that fires 20s after the room was inserted: rule "timerRuleAfterAllEvents" timer ( int: 20s ) when $room : Room( ) then System.out.println("20sec after room was modified"); end Somehow this rule triggers the "slidingTimeCount" rule activation again. On 06.09.2013, at 10:39, Alexander Wolf wrote: > Drools Version 5.5.0 FINAL > > Here's the code for session setup: > >KnowledgeBuilder kbuilder = > KnowledgeBuilderFactory.newKnowledgeBuilder(); >kbuilder.add(ResourceFactory.newClassPathResource("myrule.drl"), > ResourceType.DRL); > >// Check the builder for errors >if (kbuilder.hasErrors()) { > System.out.println(kbuilder.getErrors().toString()); > throw new RuntimeException("Unable to compile \"myrule.drl\"."); >} > >KnowledgeBase kbase = kbuilder.newKnowledgeBase(); >//configure knowledge base >KnowledgeBaseConfiguration baseConfig = > KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); >baseConfig.setOption( EventProcessingOption.STREAM ); > >//init session clock >KnowledgeSessionConfiguration sessionConfig = > KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); >sessionConfig.setOption( ClockTypeOption.get("realtime") ); >//init stateful knowledge session >StatefulKnowledgeSession ksession = > kbase.newStatefulKnowledgeSession(sessionConfig, null); > > > And here's how I inserted the events for testing purpose: > > > //get Knowledge Base > StatefulKnowledgeSession ksession = initKnowledgeSession(); > >//entry point for sensor events >WorkingMemoryEntryPoint sensorEventStream = > ksession.getWorkingMemoryEntryPoint( "SensorEventStream" ); > >Room room = new Room(24); >ksession.insert(room); >System.out.println("1. fireAllRules()"); >ksession.fireAllRules(); >//insert events >for(int i=2;i<8;i++){ > SensorEvent event = new SensorEvent("inc" + (i-1)); > sensorEventStream.insert( event ); > > System.out.println(i + ". fireAllRules()"); > ksession.fireAllRules(); > Thread.sleep(1005); >} > > //let thread sleep for another 1m to see if dereffered rules fire > (timers, (not) after rules) >Thread.sleep(1000*60*1); > >ksession.dispose(); > > > > On 05.09.2013, at 12:02, Wolfgang Laun wrote: > >> Hard to believe, but who knows. >> >> Drools version and session setup, please. >> >> -W >> >> >> On 05/09/2013, Alexander Wolf wrote: >>> Hey guys, >>> >>> I wrote a rule to count the SensorEvents in my KnowledgeSession that have >>> been inserted via entry-point SensorEventStream over the last 3 seconds - >>> but I only want the event to fire, if there were any events in the last 3 >>> seconds at all. >>> >>> Problem: if there were no recent events, i still get the output: >>> Events in last 3 seconds: 0 >>> >>> I don't really get why?! This is my rule code: >>> >>> >>> rule "slidingTimeCount" >>> when >>> $n: Number (intValue > 0) from accumulate ( $e: SensorEvent() over >>> window:time(3s) from entry-point SensorEventStream, count($e)) >>> then >>> System.out.println("Events in last 3 seconds: " + $n); >>> end >>> >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users > signature.asc Description: Message signed with OpenPGP using GPGMail ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counter in slidingTime window with restriction
Drools Version 5.5.0 FINAL Here's the code for session setup: KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("myrule.drl"), ResourceType.DRL); // Check the builder for errors if (kbuilder.hasErrors()) { System.out.println(kbuilder.getErrors().toString()); throw new RuntimeException("Unable to compile \"myrule.drl\"."); } KnowledgeBase kbase = kbuilder.newKnowledgeBase(); //configure knowledge base KnowledgeBaseConfiguration baseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); baseConfig.setOption( EventProcessingOption.STREAM ); //init session clock KnowledgeSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption( ClockTypeOption.get("realtime") ); //init stateful knowledge session StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(sessionConfig, null); And here's how I inserted the events for testing purpose: //get Knowledge Base StatefulKnowledgeSession ksession = initKnowledgeSession(); //entry point for sensor events WorkingMemoryEntryPoint sensorEventStream = ksession.getWorkingMemoryEntryPoint( "SensorEventStream" ); Room room = new Room(24); ksession.insert(room); System.out.println("1. fireAllRules()"); ksession.fireAllRules(); //insert events for(int i=2;i<8;i++){ SensorEvent event = new SensorEvent("inc" + (i-1)); sensorEventStream.insert( event ); System.out.println(i + ". fireAllRules()"); ksession.fireAllRules(); Thread.sleep(1005); } //let thread sleep for another 1m to see if dereffered rules fire (timers, (not) after rules) Thread.sleep(1000*60*1); ksession.dispose(); On 05.09.2013, at 12:02, Wolfgang Laun wrote: > Hard to believe, but who knows. > > Drools version and session setup, please. > > -W > > > On 05/09/2013, Alexander Wolf wrote: >> Hey guys, >> >> I wrote a rule to count the SensorEvents in my KnowledgeSession that have >> been inserted via entry-point SensorEventStream over the last 3 seconds - >> but I only want the event to fire, if there were any events in the last 3 >> seconds at all. >> >> Problem: if there were no recent events, i still get the output: >> >>> Events in last 3 seconds: 0 >> >> I don't really get why?! This is my rule code: >> >> >> rule "slidingTimeCount" >> when >> $n: Number (intValue > 0) from accumulate ( $e: SensorEvent() over >> window:time(3s) from entry-point SensorEventStream, count($e)) >> then >> System.out.println("Events in last 3 seconds: " + $n); >> end >> > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users signature.asc Description: Message signed with OpenPGP using GPGMail ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counter in slidingTime window with restriction
Hard to believe, but who knows. Drools version and session setup, please. -W On 05/09/2013, Alexander Wolf wrote: > Hey guys, > > I wrote a rule to count the SensorEvents in my KnowledgeSession that have > been inserted via entry-point SensorEventStream over the last 3 seconds - > but I only want the event to fire, if there were any events in the last 3 > seconds at all. > > Problem: if there were no recent events, i still get the output: > >> Events in last 3 seconds: 0 > > I don't really get why?! This is my rule code: > > > rule "slidingTimeCount" > when > $n: Number (intValue > 0) from accumulate ( $e: SensorEvent() over > window:time(3s) from entry-point SensorEventStream, count($e)) > then > System.out.println("Events in last 3 seconds: " + $n); > end > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] counter in slidingTime window with restriction
Hey guys, I wrote a rule to count the SensorEvents in my KnowledgeSession that have been inserted via entry-point SensorEventStream over the last 3 seconds - but I only want the event to fire, if there were any events in the last 3 seconds at all. Problem: if there were no recent events, i still get the output: > Events in last 3 seconds: 0 I don't really get why?! This is my rule code: rule "slidingTimeCount" when $n: Number (intValue > 0) from accumulate ( $e: SensorEvent() over window:time(3s) from entry-point SensorEventStream, count($e)) then System.out.println("Events in last 3 seconds: " + $n); end signature.asc Description: Message signed with OpenPGP using GPGMail ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users