Re: [rules-users] please provide a rule for events timeout cases
and thanks for providing feedback ! - Mail original - De: "skatta1986" À: rules-users@lists.jboss.org Envoyé: Mardi 24 Avril 2012 16:08:02 Objet: Re: [rules-users] please provide a rule for events timeout cases thanks for the reply its giving expected results -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3935376.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] please provide a rule for events timeout cases
thanks for the reply its giving expected results -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3935376.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] please provide a rule for events timeout cases
>> And make sure to use '==' when testing for equality! Oh yes of course !! Did not noticed ... ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] please provide a rule for events timeout cases
With this kind of scenario it helps a lot if you retract a matching pair (R+S, R+F). (If you need the information for further processing, create another fact.) And make sure to use '==' when testing for equality! rule request_success when $req : EventRecord( type == EventRequest, $user: user) $resp : EventRecord( type == EventResponseSuccess, user==$user, this after[0s.10s] $req ) not EventRecord( type == EventResponseSuccess || == EventResponseFailure, user == $user, this before $resp ) then // success retract( $req ); retract( $resp ); end -W On 19/04/2012, skatta1986 wrote: > Could you please help out me in this... > > modified rules: But it is giving thread exception at runtime > > rule event_success_case > when > $req : EventRecord( type=EventRequest, user="katta" ) > and $resp : EventRecord( type=EventResponseSuccess, user="katta", this > after[0s, 10s] $req ) > and ( not (EventRecord( type=EventResponseSuccess, user="katta", this > after[0s, 10s] $req , this before[0s, 10s] $resp))) > #and ( not (EventRecord( type=EventResponseSuccess, user="katta", $req > overlaps this, this overlaps $resp) )) > then >System.out.println("Success case for user " + $req.getUser()); > retract($req); > end > > rule event_failure_case > when > $req : EventRecord( type=EventRequest, user="katta" ) > and EventRecord( type=EventResponseFailure, user="katta", this > after[0s, 10s] $req ) > and ( not (EventRecord( type=EventResponseFailure, user="katta", this > after[0s, 10s] $req , this before[0s, 10s] $resp))) > #and ( not (EventRecord( type=EventResponseFailure, user="katta", $req > overlaps this, this overlaps $resp) )) > then >System.out.println("Failed case for user " + $req.getUser()); >retract($req); > end > > -- > View this message in context: > http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3923831.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] please provide a rule for events timeout cases
without the error trace, hard to say why it crashes ... But your rules can be simplified/clarified : - "and" to connect conditions is not needed - in your first 'not' condition, which you add to test that no other event takes place between the two objects matched in previous patterns, you should test the two response types, as you don't want *any* response ... - again in your first 'not' condition, the after/before should not be in a interval. Why not using after/before only ? For timeout ? Should be a third rule to me ... and should add a rule to handle response coming after the timeout too. - I cant see the utility of you second 'not' pattern (may be because of my previous remarks) Another question : why don't you retract the response too ? Is it because you want to keep them ? To me it is better to retract it, especially if it takes place between another initial EventRequest and its response. at least mark the response as treated and ignore the treated responses in your conditions So, your rules will become 2 groups of rules : first group to handle the response that correspond to a request, second group to handle the timeout cases : rule event_success_case when $req : EventRecord( type=EventRequest, $user : user ) $resp : EventRecord( type=EventResponseSuccess, user=$user, this after $req ) not (EventRecord( type=EventResponseSuccess || EventResponseFailure, user=$user, this != $resp, this after $req , this before $resp))) # 'this != $resp' is not mandatory as you test after/before (which are strict), but it does not harm ... then System.out.println("Success case for user " + $req.getUser()); retract($req); retract($resp); end rule event_failure_case : same but testing the other status rule event_timeout_case when $req : EventRecord( type=EventRequest, $user : user ) not (EventRecord( type=EventResponseSuccess || EventResponseFailure, user=$user, this after[0,10s] $req))) // assuming 10s for timeout then System.out.println("Timeout case for user " + $req.getUser()); retract($req); end rule event_response_after_timeout_case when $resp: EventRecord( type=EventResponseSuccess || EventResponseFailure, $user : user ) not (EventRecord( type=EventRequest, user=$user, this before $resp))) then System.out.println("Response coming after timeout case for user " + $req.getUser()); retract($resp); end ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] please provide a rule for events timeout cases
Could you please help out me in this... modified rules: But it is giving thread exception at runtime rule event_success_case when $req : EventRecord( type=EventRequest, user="katta" ) and $resp : EventRecord( type=EventResponseSuccess, user="katta", this after[0s, 10s] $req ) and ( not (EventRecord( type=EventResponseSuccess, user="katta", this after[0s, 10s] $req , this before[0s, 10s] $resp))) #and ( not (EventRecord( type=EventResponseSuccess, user="katta", $req overlaps this, this overlaps $resp) )) then System.out.println("Success case for user " + $req.getUser()); retract($req); end rule event_failure_case when $req : EventRecord( type=EventRequest, user="katta" ) and EventRecord( type=EventResponseFailure, user="katta", this after[0s, 10s] $req ) and ( not (EventRecord( type=EventResponseFailure, user="katta", this after[0s, 10s] $req , this before[0s, 10s] $resp))) #and ( not (EventRecord( type=EventResponseFailure, user="katta", $req overlaps this, this overlaps $resp) )) then System.out.println("Failed case for user " + $req.getUser()); retract($req); end -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3923831.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] please provide a rule for events timeout cases
"Immediate response" is one way of saying that there is no other response between a request and a response for one user. Simply add this condition, testing for both kinds of response. -W On 19/04/2012, skatta1986 wrote: > Hi, > > Now time out is working fine. > > But facing issues for correlating success and failure events which doesnot > have unique id. I want to correlate an event request followed by its > immediate event response. > > Ex: Consider the events in below order > EventRecord( type=EventRequest, user="katta" ) > EventRecord( type=EventResponseFailure, user="katta" ) > > EventRecord( type=EventRequest, user="katta" ) > EventRecord( type=EventResponseSuccess, user="katta" ) > > Rules: > > rule event_success_case > when >$req : EventRecord( type=EventRequest, user="katta" ) >and EventRecord( type=EventResponseSuccess, user="katta", this after[0s, > 10s] $req ) > then > System.out.println("Success case for user " + $req.getUser()); >retract($req); > end > > rule event_failure_case > when >$req : EventRecord( type=EventRequest, user="katta" ) >and EventRecord( type=EventResponseFailure, user="katta", this after[0s, > 10s] $req ) > then > System.out.println("Failed case for user " + $req.getUser()); > retract($req); > end > > In the above example I don't have any unique identity to correlate request > and response. I need to correlate only based on events order. > > > In the above example events order is EventRequest --> EventResponseFailure > and then EventRequest --> EventResponseSuccess. So my expected output is: > Failed case for user katta > Success case for user katta > > But I am getting below response: > Success case for user katta > Success case for user katta > > First EventRequest and second EventRequest are correlating with second > response EventResponseSuccess as this response is within 0 to 10sec for both > events. > > Note: I am getting expected result only when I send few events. If I insert > around 50 events at time into Working Memory, I face this kind of unexpected > result. > > I need to work on live trafic, where I receive hurends of messages per > second. > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3922235.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] please provide a rule for events timeout cases
Hi, Now time out is working fine. But facing issues for correlating success and failure events which doesnot have unique id. I want to correlate an event request followed by its immediate event response. Ex: Consider the events in below order EventRecord( type=EventRequest, user="katta" ) EventRecord( type=EventResponseFailure, user="katta" ) EventRecord( type=EventRequest, user="katta" ) EventRecord( type=EventResponseSuccess, user="katta" ) Rules: rule event_success_case when $req : EventRecord( type=EventRequest, user="katta" ) and EventRecord( type=EventResponseSuccess, user="katta", this after[0s, 10s] $req ) then System.out.println("Success case for user " + $req.getUser()); retract($req); end rule event_failure_case when $req : EventRecord( type=EventRequest, user="katta" ) and EventRecord( type=EventResponseFailure, user="katta", this after[0s, 10s] $req ) then System.out.println("Failed case for user " + $req.getUser()); retract($req); end In the above example I don't have any unique identity to correlate request and response. I need to correlate only based on events order. In the above example events order is EventRequest --> EventResponseFailure and then EventRequest --> EventResponseSuccess. So my expected output is: Failed case for user katta Success case for user katta But I am getting below response: Success case for user katta Success case for user katta First EventRequest and second EventRequest are correlating with second response EventResponseSuccess as this response is within 0 to 10sec for both events. Note: I am getting expected result only when I send few events. If I insert around 50 events at time into Working Memory, I face this kind of unexpected result. I need to work on live trafic, where I receive hurends of messages per second. -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3922235.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] please provide a rule for events timeout cases
See inline. On 16/04/2012, skatta1986 wrote: > Hi, Thanks for the response.. > > In general timer means executing a thread for every specified time period > interval. Why would you think so? java.util.Timer runs one thread, and TimerTasks are executed by it, one after the other. > But in our case, one time would be enough for an event. In the > above rule my query is - after timeout case (i.e., firstime 10 seconds from > the EventRequest), timer thread will be closed or will it be still running? There's no point in disposing a Timer thread and to recreate it for another activity. A dormant thread doesn't burden the system. > > Second Query is: > > Consider the below Success rule: > rule event_success_case > when >EventRecord( type=EventRequest, id=1 ) >and EventRecord( type=EventResponse, id=1 ) > > With "no_response" rule, for every EventRequest there is a timer thread > running for every 10Sec. Second rule "event_success_case" looks for its > EventResponse. Suppose with in 10 seconds there is a response then > "event_success_case" rule is run. Now I would like to close the timer thread > because it uses my system memory. Please let me know if this is possible. Trust Drools, trust Java. If the condition isn't true, everything will be taken care of. (Threads don't use that much memory.) -W > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3914382.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] please provide a rule for events timeout cases
Hi, Thanks for the response.. This is working fine.. But I have a query on the rule: rule no_response timer( int: 10s ) when EventRecord( type=EventRequest, id=1 ) not EventRecord( type=EventResponse, id=1 ) In general timer means executing a thread for every specified time period interval. But in our case, one time would be enough for an event. In the above rule my query is - after timeout case (i.e., firstime 10 seconds from the EventRequest), timer thread will be closed or will it be still running? Second Query is: Consider the below Success rule: rule event_success_case when EventRecord( type=EventRequest, id=1 ) and EventRecord( type=EventResponse, id=1 ) With "no_response" rule, for every EventRequest there is a timer thread running for every 10Sec. Second rule "event_success_case" looks for its EventResponse. Suppose with in 10 seconds there is a response then "event_success_case" rule is run. Now I would like to close the timer thread because it uses my system memory. Please let me know if this is possible. -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3914382.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] please provide a rule for events timeout cases
You might use a timer: rule no_response timer( int: 10s ) when EventRecord( type=EventRequest, id=1 ) not EventRecord( type=EventResponse, id=1 ) then // ... no matching response after 10s end -W On 16/04/2012, skatta1986 wrote: > Hi, > > For the first time even I have tried the same. But it doesn't work. > > I need to correlate the events on live. I am using fire rule until hault > (ksession.fireUntilHalt()). > > EventRecord(type=EventRequest, id=1) > not EventRecord(type=EventResponse, id=1, this after [1s,10s]) > > This rule doesn't work because when EventRecord(type=EventRequest, id=1) hit > working memory, this rule also looks for EventRecord(type=EventResponse, > id=1). As the EventResponse doesn't the working memory, "not" logic become > true and executing the R.H.S part as soon as EventRequest arrives. This is > not waiting for 10seconds time interval. > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3914047.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] please provide a rule for events timeout cases
Hi, For the first time even I have tried the same. But it doesn't work. I need to correlate the events on live. I am using fire rule until hault (ksession.fireUntilHalt()). EventRecord(type=EventRequest, id=1) not EventRecord(type=EventResponse, id=1, this after [1s,10s]) This rule doesn't work because when EventRecord(type=EventRequest, id=1) hit working memory, this rule also looks for EventRecord(type=EventResponse, id=1). As the EventResponse doesn't the working memory, "not" logic become true and executing the R.H.S part as soon as EventRequest arrives. This is not waiting for 10seconds time interval. -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3914047.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] please provide a rule for events timeout cases
First question: are you using Drools Fusion? If yes, did you try with something like this?: EventRecord(type=EventRequest, id=1) not EventRecord(type=EventResponse, id=1, this after [1s,10s]). I'm using a 10s timeout here. Best Regards, Esteban Aliverti - Developer @ http://www.plugtree.com - Blog @ http://ilesteban.wordpress.com On Fri, Apr 13, 2012 at 3:03 PM, skatta1986 wrote: > Hi, > > I would like to write a rule for events timeout case. > > Consider the events EventRecord(type=EventRequest, id=1) and > EventRecord(type=EventResponse, id=1). > I have written rules (in .drl file) for correlting the event request with > event response. > > Now I would like to write timeout case. Suppose > EventRecord(type=EventRequest, id=2) is not followed by its response. If we > doesn't recieve response within 10 seconds, then it is considered as > timeout > case. > I tried to use timers but it doen't work as it is not allowing me write > inside when (LHS) pattern. > > Is there any other way to find timeout cases? > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3907955.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
[rules-users] please provide a rule for events timeout cases
Hi, I would like to write a rule for events timeout case. Consider the events EventRecord(type=EventRequest, id=1) and EventRecord(type=EventResponse, id=1). I have written rules (in .drl file) for correlting the event request with event response. Now I would like to write timeout case. Suppose EventRecord(type=EventRequest, id=2) is not followed by its response. If we doesn't recieve response within 10 seconds, then it is considered as timeout case. I tried to use timers but it doen't work as it is not allowing me write inside when (LHS) pattern. Is there any other way to find timeout cases? -- View this message in context: http://drools.46999.n3.nabble.com/please-provide-a-rule-for-events-timeout-cases-tp3907955p3907955.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