[rules-users] Unable to fire Rules
hanumesh.m
hanumesh.m at gmail.com
Fri Apr 4 03:28:24 EDT 2008
Hi,
I am inserting message(fileName, fromQ,toQ,transType) to WorkingMemory.
fileName as "ABC-834-test-100.edi"
I am inserting 3 instances of TrasactionVO's to workingmemory as follows:
TransactionVO transVO = new TransactionVO("ABC-834", "ABC.834.EDI",
"ABC.834.XML", "834");
TransactionVO transVO1 = new TransactionVO("XYZ-834", "XYZ.834.EDI",
"XYZ.834.XML", "834");
TransactionVO transVO2 = new TransactionVO("834", "INBOUND.834.EDI",
"INBOUND.834.XML", "834");
In drl, which ever object of TransactionVO matches the fileName of Message,
then update Message's rest of the details with TransactionVO. But the rules
are not getting fired.
Follewed is the testCase and .drl file along with FactObjects.
TestCase:
-------------------------------------------------------------
package com.sample;
import java.io.InputStreamReader;
import java.io.Reader;
import org.drools.FactException;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
import com.sample.MessageEA;
import com.sample.TransactionVO;
/**
* This is a sample file to launch a rule package from a rule source file.
*/
public class DroolsTest2 {
public static final void main(String[] args) {
try {
//load up the rulebase
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
MessageEA messageEA = new MessageEA();
messageEA.setFileName("ABC-834-test-100.edi");
workingMemory.insert( messageEA );
TransactionVO transVO = new TransactionVO("ABC-834",
"ABC.834.EDI", "ABC.834.XML", "834");
TransactionVO transVO1 = new TransactionVO("XYZ-834",
"XYZ.834.EDI", "XYZ.834.XML", "834");
TransactionVO transVO2 = new TransactionVO("834",
"INBOUND.834.EDI", "INBOUND.834.XML", "834");
workingMemory.insert( transVO );
workingMemory.insert( transVO1 );
workingMemory.insert( transVO2);
try{
workingMemory.fireAllRules();
}catch (FactException e ){
System.out.println("err: "+e.getMessage());
}catch(Exception ee){
System.out.println("Err2 : "+ee.getMessage());
}
System.out.println("fName: "+messageEA.getFileName());
System.out.println("frQ: "+messageEA.getFromQ());
System.out.println("toQ: "+messageEA.getToQ());
} catch (Throwable t) {
t.printStackTrace();
}
}
/**
* Please note that this is the "low level" rule assembly API.
*/
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader(
DroolsTest.class.getResourceAsStream( "/EATech.drl" ) );
//optionally read in the DSL (if you are using it).
//Reader dsl = new InputStreamReader(
DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilder builder = new PackageBuilder();
//this wil parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is for normal DRL.
builder.addPackageFromDrl( source );
//Use the following instead of above if you are using a DSL:
//builder.addPackageFromDrl( source, dsl );
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
}
-------------------------------------------
.drl file
package com.sample;
import com.sample.MessageEA;
import com.sample.TransactionVO;
rule "Process ALL"
no-loop
when
m:MessageEA()
p: TransactionVO(fileMask matches m.fileName)
then
System.out.println( "Reading Rule for ..." + p.getFileMask() );
m.setFromQ(p.getFrom_Q());
m.setToQ(p.getTo_Q());
m.setTransType(p.getTransType());
update( m );
end
------------------------------------------------------------------
MessageEA (private String transType, private String fileName,private String
fromQ, private String toQ)
TransactionVO(private String fileMask, private String from_Q,private String
to_Q,private String transType);
)
This testCase has executed only Once accurately. But from later on it
stopped working. Not able to file Rules..
I am doing wrong anywhere?
Please suggest.
Hanumesh M
--
View this message in context: http://www.nabble.com/Unable-to-fire-Rules-tp16486801p16486801.html
Sent from the drools - user mailing list archive at Nabble.com.
More information about the rules-users
mailing list