[rules-users] Trying to get Sliding Windows to work

ober0n lili339 at hotmail.com
Mon Mar 30 12:56:03 EDT 2009


Hi Ed, thanks for the quick reply, I will try the temporal constraints as
well. 

I haven't completed my testing yet but the sliding windows seems to be
working. Thanks! 

I am getting a strange problem of my program hanging. It gets all the way
past my "dispose()" of the StatefulKnowledgeSession and closing the session
logger and to the end of my main(). Then it just sits there. I'm thinking
it's a bug in my rules but wanted to make sure this wasn't a feature of
Streams (maybe some thread kicked off to accept facts or something). 

If you could just confirm nothing in Drools fusion is supposed to continue
running, that would be great.

Here are the significant snippets of my code:
		...
		WorkingMemoryEntryPoint eventStream = ksession.getWorkingMemoryEntryPoint(
"EventStream" );
		...
		eventStream.insert(goodbye_message);
		Thread.sleep(10000);
		eventStream.insert(hello_message);
		ksession.fireAllRules();
		ksession.dispose();
		logger.close();
	} catch (Throwable t) {
		t.printStackTrace();
	}
} // end main()  <-- tracing through the code, I get past the end of main()
then see a "Source not found." in the Eclipse debugger which seems to be
looking for "Thread.exit() line: 604"
		
		
The updated rule:

declare Message
    @role( event )
end 

rule "Hello World"
	when
		Message( status == Message.HELLO ) from entry-point "EventStream"
		exists(Message( status == Message.GOODBYE ) over window:time( 4s )  from
entry-point "EventStream")
	then
		System.out.println("**************************************************");
		System.out.println( "There was a GOODBYE message near the HELLO message."
);
		System.out.println("**************************************************");
end

Thanks.


Edson Tirelli-3 wrote:
> 
>     Although your rule should work, the best way to write your rule would
> be
> using temporal constraints instead of sliding windows:
> 
> rule "Goodbye before Hello World"
>        when
>                $m : Message( status == Message.HELLO )
>                exists( Message( status == Message.GOODBYE, this
> before[0s,3s] $m ) )
>        then
>                System.out.println( "There was a GOODBYE message before the
> HELLO
> message." );
> end
> 
>     Using "before" operator is not only much cheaper (in terms of used
> resources) than sliding windows, but it also allow the engine to reason
> over
> the temporal constraints looking for special cases, like when you use
> negative patterns.
> 
>     I will look further into your case to check if I missed anything on
> the
> sliding windows support, but using STREAM mode should work.
> 
>     If you can open a JIRA for me to raise a compilation error when
> compiling sliding windows using CLOUD mode, I appreciate. This will allow
> you to follow up my progress.
> 
>     []s
>     Edson
> 
> 
> 2009/3/30 ober0n <lili339 at hotmail.com>
> 
>>
>> Hi Ed, no need to apologize, you have been invaluable in my first steps
>> towards Drooling :-D so thanks for all your help, it is GREATLY
>> appreciated
>> :clap:.
>>
>> We have a few scenarios in mind but aren't really implementing them yet,
>> just trying to see if sliding windows works the way we think it does. In
>> the
>> simple rule I wrote above, I basically want to check if two facts are
>> temporally close.
>>
>> Yes, you are correct. I didn't pay enough attention to the manual and
>> didn't
>> use STREAM mode to enter in my facts. I will use the manual insertion
>> process found in "Example 2.10. Inserting facts into an entry point" of
>> section "2.3. Streams Support" to update my code. And, I will update my
>> rule
>> to specify a "from entry-point <Specific Stream>".
>>
>> Also, could you comment on the simple rule I am using? Does it look like
>> it
>> should work after I do the updates? Or is my logic incorrect?
>>
>> Thanks again.
>>
>>
>>
>>   Ober0n,
>>
>>   Sorry for the delay on answering. I am on a trip with limited internet
>> connection.
>>   I am interested in your experience with the sliding windows, since the
>> tests are working. Maybe it is a scenario not covered by the tests.
>>
>>   In any case, what is probably happening is that you are not configuring
>> the engine to work in STREAM mode. The default mode is CLOUD and it does
>> not
>> support sliding windows. It seems the engine is silently failing in this
>> case, when the compiler raise an error to warn the user.
>>
>>    I just committed some docs on this subject:
>>
>>
>> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/docs/drools-fusion/html/ch02.html#d0e1067
>>
>>    (plz, wait for hudson to rebuild the docs or build docs yourself).
>>
>>    Feedback welcome. I will complement the sliding window docs.
>>
>>    []s
>>    Edson
>>
>> 2009/3/29 ober0n <lili339 at hotmail.com>
>>
>> >
>> > Still trying to get sliding windows to work (basing my code off of the
>> > Eclipse supplied "Hello World" example). I don't think I fully
>> understand
>> > how it works yet so I'm trying to simplify things even further by
>> writing
>> > a
>> > simple rule that is meant to say:
>> >
>> > if (current_message = "Hello" AND exists( goodbye_message within
>> > sliding_window(3 seconds) ))
>> > then print("There was a GOODBYE message before the HELLO message." )
>> >
>> > In other words: This rule should fire if the current Hello World
>> message
>> > was
>> > preceeded within 3 seconds by a goodbye message.
>> >
>> >
>> >
>> ---------------------------------------------------------------------------------------------------
>> > I wrote a new rule for this:
>> >
>> > declare Message
>> >    @role( event )
>> > end
>> >
>> > rule "Goodbye before Hello World"
>> >        when
>> >                Message( status == Message.HELLO )
>> >                exists( Message( status == Message.GOODBYE ) over
>> > window:time( 3s ) )
>> >        then
>> >                System.out.println( "There was a GOODBYE message before
>> the
>> > HELLO
>> > message." );
>> > end
>> >
>> >
>> >
>> ---------------------------------------------------------------------------------------------------
>> >
>> > To send the messages: (ksession is a StatefulKnowledgeSession)
>> >
>> >                        ...
>> >                        ksession.insert(goodbye_message);
>> >                        ksession.fireAllRules();
>> >
>> >                        Thread.sleep(5000);
>> >
>> >                        ksession.insert(hello_message);
>> >                        ksession.fireAllRules();
>> >                        ...
>> >
>> >
>> ---------------------------------------------------------------------------------------------------
>> >
>> > I expect to get nothing back since I sent the Hello message 5 seconds
>> > after
>> > the goodbye message (outside the sliding window of 3 seconds). But, for
>> > some
>> > reason the rule fires and I get one:
>> >
>> > "There was a GOODBYE message before the HELLO message."
>> >
>> > Any help would be greatly appreciated.
>> >
>> > Thanks!
>> > --
>> > View this message in context:
>> >
>> http://www.nabble.com/Trying-to-get-Sliding-Windows-to-work-tp22735051p22770318.html
>> > Sent from the drools - user mailing list archive at Nabble.com.
>> >
>> > _______________________________________________
>> > rules-users mailing list
>> > rules-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/rules-users
>> >
>>
>>
>>
>> --
>>  Edson Tirelli
>>  JBoss Drools Core Development
>>  JBoss, a division of Red Hat @ www.jboss.com
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Trying-to-get-Sliding-Windows-to-work-tp22735051p22785711.html
>> Sent from the drools - user mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
> 
> 
> 
> -- 
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss, a division of Red Hat @ www.jboss.com
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Trying-to-get-Sliding-Windows-to-work-tp22735051p22787700.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list