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

Yv RamaRao ramarao_bvrm at yahoo.co.in
Wed Aug 8 01:16:58 EDT 2007


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



      Why delete messages? Unlimited storage is just a click away. Go to http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070808/7ea16c23/attachment.html 


More information about the rules-users mailing list