Here is a very simple test. Note that utilMethod is called twice for the
first rule, but is never called for the other two rules. If you convert to
Java dialect then things execute as expected.
TestRules.drl:
#created on: Jan 5, 2012
package com.sample
import com.sample.TestUtility;
rule "First Rule"
when
$tf : TestFact(TestUtility.utilMethod(s, "Value1") == true
&& i > 0
)
then
System.out.println("First Rule Fires");
end
rule "Second Rule"
when
$tf : TestFact(TestUtility.utilMethod(s, "Value2") == true
&& i > 0
)
then
System.out.println("Second Rule Fires");
end
rule "Third Rule"
when
$tf : TestFact(TestUtility.utilMethod(s, "Value3") == true
&& i > 0
)
then
System.out.println("Third Rule Fires");
end
TestUtility.java:
package com.sample;
public class TestUtility {
public static Boolean utilMethod(String s1, String s2) {
Boolean result = null;
if (s1 != null) {
result = s1.equals(s2);
}
System.out.println("in utilMethod >" + s1 + "< >" +
s2 + "< returns
" + result);
return result;
}
}
TestDriver.java:
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
// setup the debug listeners
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new
DebugWorkingMemoryEventListener());
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
TestFact fact = new TestFact();
fact.setS("asdf");
fact.setI(10);
ksession.insert(fact);
ksession.fireAllRules();
logger.close();
}
catch (Throwable t) {
t.printStackTrace();
}
}
Output:
in utilMethod >asdf< >Value1< returns false
in utilMethod >asdf< >Value1< returns false
==>[ObjectInsertedEventImpl: getFactHandle()=[fact
0:1:31556811:31556811:1:DEFAULT:com.sample.TestFact@1e184cb],
getObject()=com.sample.TestFact@1e184cb,
getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@70610a,
getPropagationContext()=PropagationContextImpl [activeActivations=0,
dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact
0:1:31556811:31556811:1:DEFAULT:com.sample.TestFact@1e184cb],
leftTuple=null, originOffset=-1, propagationNumber=3, rule=null, type=0]]
--
View this message in context:
http://drools.46999.n3.nabble.com/Error-in-MVEL-execution-optimization-tp...
Sent from the Drools: User forum mailing list archive at
Nabble.com.