[rules-users] please provide a rule for events timeout cases

Vincent LEGENDRE vincent.legendre at eurodecision.com
Thu Apr 19 14:26:40 EDT 2012


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 





More information about the rules-users mailing list