Hi All,
I have a init rule in which i am accessing Agenda.getScheduledActivations()
method. But it throws NullPointerException. I have tried with both
drools-core 4.0.4 and drools-core 4.0.7 jar files.
Here are the rules:
package com.demo.rules;
import java.util.Date;
import org.drools.Agenda;
import org.drools.spi.Activation;
import com.demo.metric.TxInfo;
import com.demo.rules.RuleDemo;
function void removeActivationsForRule(String ruleName, Agenda agenda) {
Activation[] actArr;
Activation act;
int len;
try {
actArr = agenda.getScheduledActivations();
len = actArr.length;
System.out.println("*** Scheduled Activation[] Length : " + len);
for(int i=0;i<len;++i) {
act = actArr[i];
if(act.getRule().getName().equals(ruleName)) {
System.out.println("*** ACTIVATION : " + act + " IS REMOVED
***");
act.remove();
}
}
} catch (NullPointerException ex) {
System.out.println("##############");
ex.printStackTrace();
System.out.println("##############");
}
}
rule 'init_rule1'
salience 10
when TxInfo(totalTime <= 100)
then
removeActivationsForRule("rule1", drools.getWorkingMemory().getAgenda());
end
rule 'rule1'
duration 60000
when TxInfo(totalTime > 100)
then
System.out.println("**** FIRING RULE : rule1 : -" + new Date() + "-
****");
end
Here is the stack trace:
##############
java.lang.NullPointerException
at
org.drools.common.DefaultAgenda.getScheduledActivations(DefaultAgenda.java:351)
at com.demo.rules.RuleDemo.removeScheduledActivations(RuleDemo.java:132)
at com.demo.rules.RuleDemo.beforeActivationFired(RuleDemo.java:175)
at
org.drools.event.AgendaEventSupport.fireBeforeActivationFired(AgendaEventSupport.java:103)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:540)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:475)##############
##############
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
at com.demo.rules.RuleDemo.fireRule(RuleDemo.java:116)
at com.demo.rules.RuleDemo.main(RuleDemo.java:221)
java.lang.NullPointerException
at
org.drools.common.DefaultAgenda.getScheduledActivations(DefaultAgenda.java:351)
at
com.demo.rules.RemoveActivationsForRule.removeActivationsForRule(RemoveActivationsForRule.java:27)
at com.demo.rules.Rule_init_rule1_0.consequence(Rule_init_rule1_0.java:7)
at
com.demo.rules.Rule_init_rule1_0ConsequenceInvoker.evaluate(Rule_init_rule1_0ConsequenceInvoker.java:22)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:518)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:475)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:439)
at com.demo.rules.RuleDemo.fireRule(RuleDemo.java:116)
at com.demo.rules.RuleDemo.main(RuleDemo.java:221)
##############
I have attached my source code.
Thanks and Regards,
Ganesh
http://www.nabble.com/file/p19429177/RuleDemo.java RuleDemo.java
--
View this message in context:
http://www.nabble.com/Agenda.getScheduledActivations%28%29-method-is-thro...
Sent from the drools - dev mailing list archive at
Nabble.com.