[rules-users] [Drools] Order of sequence of execution of Conditions and Actions

Mark Proctor mproctor at codehaus.org
Wed Aug 8 06:39:50 EDT 2007


Not easily no, the conditions are always evaluated first before any 
ruiles are firing. The only way is to use some sort of semaphore that is 
the first pattern in the rule, which would stop the rest of the rule 
from being evaluated.

Mark
Yv RamaRao wrote:
> Hi all,
>  
> I has a problem in executing the drool code. I have 2 rules with a 
> condition and an action.
> The order of execution is
>
> executeCondition1
> executeCondition2
> executeAction2()
> executeAction1()
>
> but to fullfill my requirements i need the sequence to be executed as
> executeCondition1
> executeAction1()
> executeCondition2
> executeAction2()
>
> Is there any to get way to execute the sequence as above. Kindly suggest
>
> Here is Drool Code and Implementation Java Code
>
>
> Sample.drl
> ========
> package com.sample
> import com.sample.DroolsTest.MyDeligate;
> rule "Rule1"
>     salience 2
>     when
>         delegate: MyDeligate()
>         eval(delegate.executeCondition1());
>     then
>         delegate.executeAction1();
> end
>
> rule "Rule2"
>     salience 1
>     when
>         delegate: MyDeligate()
>         eval(delegate.executeCondition2());
>     then
>         delegate.executeAction2();
> end
>
>  DroolTest.java
> ===========
>
> package com.sample;
>
> import java.io.InputStreamReader;
> import java.io.Reader;
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.WorkingMemory;
> import org.drools.compiler.PackageBuilder;
> import org.drools.rule.Package;
>
> public class DroolsTest {
>
>     public static final void main(String[] args) {
>         try {
>             RuleBase ruleBase = readRule();
>             WorkingMemory workingMemory = ruleBase.newWorkingMemory();
>             MyDeligate delegate = new MyDeligate();
>             workingMemory.assertObject(delegate);
>             workingMemory.fireAllRules();  
>         } catch (Throwable t) {
>             t.printStackTrace();
>         }
>     }
>
>     private static RuleBase readRule() throws Exception
>     {
>         Reader source = new InputStreamReader( 
> DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );
>         PackageBuilder builder = new PackageBuilder();
>         builder.addPackageFromDrl( source );
>         Package pkg = builder.getPackage();
>         RuleBase ruleBase = RuleBaseFactory.newRuleBase();
>         ruleBase.addPackage( pkg );
>         return ruleBase;
>     }
>     public static class MyDeligate
>     {
>         public boolean executeCondition1()
>         {
>             System.out.println("Executed Condition1");
>             return true;
>         }
>         public boolean executeCondition2()
>         {
>             System.out.println("Executed Condition2");
>             return true;
>         }
>         public boolean executeCondition3()
>         {
>             System.out.println("Executed Condition3");
>             return true;
>         }
>        
>         public boolean executeAction1()
>         {
>             System.out.println("Executed Action1");
>             return true;
>         }
>         public boolean executeAction2()
>         {
>             System.out.println("Executed Action2");
>             return true;
>         }
>         public boolean executeAction3()
>         {
>             System.out.println("Executed Action3");
>             return true;
>         }
>     }
> }
>
> Regards
> Ramarao
>
> ------------------------------------------------------------------------
> Download prohibited? No problem. CHAT 
> <http://in.rd.yahoo.com/tagline_webmessenger_1/*http://in.messenger.yahoo.com/webmessengerpromo.php> 
> from any browser, without download.
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/20070808/d3862451/attachment.html 


More information about the rules-users mailing list