Thanks Edson, This is exactly same as what I tried and it works.
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Edson Tirelli Sent: Wednesday, February 28, 2007 5:18 PM To: Rules Users List Subject: Re: [rules-users] Correlation of events Ashfaq, The idea of a rules engine is that all the "search", or in better words, the "match" of facts is done in the LHS. This is exactly what the rules engine does better! The RHS should be composed (ideally) of simple actions, not algorithms. For instance, in your example, lets say you use 2 other fields for correlating the events: source (the origin of the error) and type (the type of the error). Your rule would simply be written: rule "new error" when $error : Error( state == NEW_ERROR, $source : source, $type : type ) $errFromWorkingMemory : Error( source == $source, type == $type ) then $errFromWorkingMemory.setLastTimeStamp( currentTimestamp ); modify( $errFromWorkingMemory ); retract( $error ); end See? Clean and clear. No algorithms involved and the engine will optimize the matching and execution giving you the best performance. You can also create rules to automatically remove any error with status NEW_ERROR that is not the last one, based on timestamp. Example rule "keep only the last error" when $error : Error( $state : state == NEW_ERROR, $source : source, $type : type, $timestamp : timestamp ) exists Error( state == $state, source == $source, type == $type, timestamp > $timestamp ) end retract( $error ); end So, my advice is: use the engine to your benefit... ;) []s Edson Steven Williams wrote: > I think you may want to use a global here: > > global ErrorMetaData errorMetadata; > > rule "new error" > when > $error : Error (state == NEW_ERROR) > then > (search workingmemory if this error was already > registered) > if (found) > { > errorMetadata.setLastTimestamp(currentTimestamp) > retract($error); > } > end > > > On 2/28/07, *Framewala, Ashfaq Y* <[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > Hi, > > I am working on a system where I need to correlate few error > conditions happening in the network infrastructure. I have gone > through the documentation for Jboss rules engine (Drools) and I am > planning to use it for the correlation purpose. > > Can anyone let me know a way in which I can get an object from > workingmemory in the "then" part of the rule? For e.g., I need the > following > > > rule "new error" > when > $error : Error (state == NEW_ERROR) > then > (search workingmemory if this error was already > registered) > if (found) > { > > $errFromWorkingMemory.setLastTimestamp(currentTimestamp) > retract($error); > } > End > > Thanks, > Ashfaq > > > > > > _______________________________________________ > rules-users mailing list > [email protected] <mailto:[email protected]> > https://lists.jboss.org/mailman/listinfo/rules-users > > > > > -- > Steven Williams > > Supervising Consultant > > Object Consulting > Office: 8615 4500 Mob: 0439 898 668 Fax: 8615 4501 > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > www.objectconsulting.com.au <http://www.objectconsulting.com.au> > > consulting | development | training | support > our experience makes the difference > >----------------------------------------------------------------------- - > >_______________________________________________ >rules-users mailing list >[email protected] >https://lists.jboss.org/mailman/listinfo/rules-users > > -- Edson Tirelli Software Engineer - JBoss Rules Core Developer Office: +55 11 3124-6000 Mobile: +55 11 9218-4151 JBoss, a division of Red Hat @ www.jboss.com _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
