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

Nestor Tarin Burriel nestabur at gmail.com
Thu Apr 2 11:06:33 EDT 2009


Sorry Edson ... I can't declare the fact type with the parameter @role(
event ) in guvnor throw creating a declarative model :( could you explain it
better?

2009/4/2 Edson Tirelli <tirelli at post.com>

>
>    Declare your fact type with @role( event ).
>
> 2009/4/2 Nestor Tarin Burriel <nestabur at gmail.com>
>
> And how can I create events from guvnor?
>>
>> 2009/4/2 Edson Tirelli <tirelli at post.com>
>>
>>
>>>    Need to fix the error message, but it seems you are trying to use the
>>> sliding window on regular facts... sliding window only makes sense for
>>> events...
>>>
>>>    Also, the property you are using to set the event processing mode
>>> seems wrong. Check here:
>>>
>>>
>>> https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/docs/drools-fusion/html/ch02.html#d0e1067
>>>
>>>     []s
>>>     Edson
>>>
>>> 2009/4/2 nestabur <nestabur at gmail.com>
>>>
>>>
>>>>
>>>> Hi All,
>>>>
>>>> I'm trying to use sliding windows with guvnor, I deploy the package in
>>>> my
>>>> rule engine as:
>>>>
>>>>               Properties props = new Properties();
>>>>                props.put("url", rulePackagePath);
>>>>                props.put("eventProcessingMode", "stream");
>>>>
>>>>                agent = RuleAgent.newRuleAgent(props);
>>>>                session = agent.getRuleBase().newStatefulSession();
>>>>
>>>> When I insert a fact into the working memory as:
>>>>                session.insert(fact);
>>>>                session.fireAllRules();
>>>>
>>>> I get the following error:
>>>>
>>>> Exception while processing message: java.lang.ClassCastException:
>>>> org.drools.common.DefaultFactHandle cannot be cast to
>>>> org.drools.common.EventFactHandle
>>>> java.lang.ClassCastException: org.drools.common.DefaultFactHandle cannot
>>>> be
>>>> cast to org.drools.common.EventFactHandle
>>>>        at
>>>>
>>>> org.drools.rule.SlidingTimeWindow.updateNextExpiration(SlidingTimeWindow.java:192)
>>>>        at
>>>>
>>>> org.drools.rule.SlidingTimeWindow.assertRightTuple(SlidingTimeWindow.java:119)
>>>>        at
>>>>
>>>> org.drools.rule.BehaviorManager.assertRightTuple(BehaviorManager.java:87)
>>>>        at org.drools.reteoo.ExistsNode.assertObject(ExistsNode.java:172)
>>>>        at
>>>>
>>>> org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:366)
>>>>        at
>>>>
>>>> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:349)
>>>>        at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:147)
>>>>        at
>>>>
>>>> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)
>>>>        at
>>>> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:184)
>>>>        at
>>>> org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:146)
>>>>        at
>>>>
>>>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1066)
>>>>        at
>>>>
>>>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1022)
>>>>        at
>>>>
>>>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:810)
>>>>        at
>>>>
>>>> com.s2grupo.triton.service.impl.CorrelatorServiceImpl.insertFact(CorrelatorServiceImpl.java:64)
>>>>        at
>>>>
>>>> com.s2grupo.triton.jms.impl.JmsMessageListenerImpl.onMessage(JmsMessageListenerImpl.java:67)
>>>>        at
>>>>
>>>> org.apache.activemq.ActiveMQMessageConsumer.dispatch(ActiveMQMessageConsumer.java:1021)
>>>>        at
>>>>
>>>> org.apache.activemq.ActiveMQSessionExecutor.dispatch(ActiveMQSessionExecutor.java:122)
>>>>        at
>>>>
>>>> org.apache.activemq.ActiveMQSessionExecutor.iterate(ActiveMQSessionExecutor.java:192)
>>>>        at
>>>>
>>>> org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
>>>>        at
>>>>
>>>> org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43)
>>>>        at
>>>>
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>>>>        at
>>>>
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>>>>        at java.lang.Thread.run(Thread.java:619)
>>>>
>>>> What I'm missing? Is it a bug? I'm using the 5.0.0.SNAPSHOT version of
>>>> drools.
>>>>
>>>> Thanks,
>>>>
>>>> NEStor
>>>>
>>>>
>>>> ober0n wrote:
>>>> >
>>>> > 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-tp22735051p22844999.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
>>>
>>>
>>
>> _______________________________________________
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090402/c74b9b27/attachment.html 


More information about the rules-users mailing list