[rules-users] Rule definition help

Rahul Phadnis rahul.phadnis at fatspaniel.com
Fri Feb 23 12:58:38 EST 2007


Thank you for your responses.

Is the "from" CE (condition expression) available in
3.0.5?

-Rahul


--- Edson Tirelli <tirelli at post.com> wrote:

> 
>     Michael,
> 
>     Yes, it is surelly heavier to make database
> calls in the LHS of a 
> rule when compared to handling objects in memory.
> Sometimes, though, it 
> is not possible or not worth to load your objects
> from the database in 
> advance and you need to go for loading as needed in
> LHS. Although, the 
> best would be to use "from" CE, as it caches some
> results and allow 
> Rahul to do more or less what he wants.
>     Example: pretend you have Power and Temperature
> objects, you could 
> do something like:
> 
> rule "Device not working (condition id = 4)"
>   when
>     alertDefinition : AlertDefinition (conditionID==
> 4, eid : entityID)
>     Power( value < 1000 ) from dao.getPower( eid )
>     Temperature( deviceTemp > 50, ambTemp > 40 )
> from dao.getTemperature(eid)
>   then
>     log("Triggered Device not working  alert for "+
> eid);
> end
> 
>    
>    Hope it helps,
> 
>       Edson
> 
> 
> Anstis, Michael (M.) wrote:
> 
> >It seems inefficient to make calls to a database
> from a rule LHS as (I'm
> >guessing [Edson?]) that the Rete network can't be
> built\optimised around
> >an evaluated predicate (trying to use the correct
> language, but possibly
> >failing badly). Would the AlertCondition not
> already have these
> >properties populated? Making the rule simpler too:
> >
> >Rule "Device not working (condition id = 4)"
> >	when
> >		$ac : AlertCondition (conditionId ==4, $eid :
> entityID,
> >$p : power, $at : ambTemperature)
> >	then
> >		log("Triggered Device not working  alert for " +
> $eid +
> >", power=" + $p + ", ambient temperature=" + $at);
> >end
> >
> >-----Original Message-----
> >From: rules-users-bounces at lists.jboss.org
> >[mailto:rules-users-bounces at lists.jboss.org] On
> Behalf Of Rahul Phadnis
> >Sent: 22 February 2007 21:12
> >To: rules-users at lists.jboss.org
> >Subject: [rules-users] Rule definition help
> >
> >I am very new to JBoss rules and I am trying to use
> it
> >for evaluating alert conditions.
> >
> >I am asserting the AlertDefinition object as a fact
> >into the working memory.
> >
> >The rules file would define a variety of alert
> >condition rules. 
> >for example
> >
> >rule "Device not working (condition id = 4)"
> >    # the if part
> >	when
> >        alertDefinition : AlertDefinition
> (conditionID
> >== 4, 
> >        eid : entityID)
> >        # here i would like to get the last power
> >reading from device
> >        # with id == eid 
> >        eval (dao.getPower(eid).doubleValue() <
> 1000)
> >        # then get temperature from the device
> >        eval ((dao.getTemperature(eid) != null && 
> >dao.getTemperature(eid) > 50)
> >        || (dao.getAmbTemperature(eid) != null && 
> >dao.getAmbTemperature(eid) > 40)
> >        ) 
> >        
> >	then
> >        # what do we do if the rule evaluates to
> true
> >        log("Triggered Device not working  alert
> for "
> >+ eid);
> >end
> >
> >
> >Here are  my questions:
> >
> >1. Am using the evals correctly? Can I possibly
> split
> >this into multiple rules to make it work better?
> >
> >2. Can assign dao.getTemperature(eid) to a field.
> The
> >getTemperature call is expensive and doing it twice
> is
> >not right.
> >
> >Any pointer would be appreciated.
> >
> >-Rahul
> >
> >_______________________________________________
> >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
>  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
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 




More information about the rules-users mailing list