-
Bug
-
Resolution: Done
-
Critical
-
6.2.0.Final
-
None
-
None
I'm receiving a NullPointerException trying to dynamically update the rule definitions inside a KieContainer while a KieSession is running, invoked with KieSession.fireUntilHalt(). We need to leverage KieSession.fireUntilHalt() as all of our rules in this service are timer rules, as we're leveraging drools as a scheduling service here.
The code below shows how I'm testing this. First I setup two rules to print every 3 and 6 seconds, then execute KieSession.fireUntilHalt().
Then later on I update the KieContainer version with three rules which print out @ 5, 8 and 10 seconds. I immediately receive a NullPointerException after calling the KieContainer.updateToVersion.
Error:
Exception in thread "Thread-14" java.lang.NullPointerException
at org.drools.core.common.LeftTupleSetsImpl.addAllInserts(LeftTupleSetsImpl.java:185)
at org.drools.core.common.LeftTupleSetsImpl.addAll(LeftTupleSetsImpl.java:253)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:379)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:231)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:106)
at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1016)
at org.drools.core.common.DefaultAgenda.fireUntilHalt(DefaultAgenda.java:1258)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireUntilHalt(StatefulKnowledgeSessionImpl.java:1333)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireUntilHalt(StatefulKnowledgeSessionImpl.java:1310)
at co.bn.sirens.engine.ScheduleRunner$1.run(ScheduleRunner.java:81)
at java.lang.Thread.run(Thread.java:745)
Code:
public void run()
{
String testRuleAdd = "rule \"test-rule-add\" timer (cron: */3 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every three seconds'); end ";
String testRuleAdd2 = "rule \"test-rule-add-two\" timer (cron: */6 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every six seconds'); end ";
String testRuleAdd3 = "rule \"test-rule-add-three\" timer (cron: */10 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every ten seconds'); end ";
String testRuleAdd4 = "rule \"test-rule-add-four\" timer (cron: */5 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every five seconds'); end ";
String testRuleAdd5= "rule \"test-rule-add-five\" timer (cron: */8 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every eight seconds'); end ";
try {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
EntityManager em = modelService.createEntityManager();
List<Schedule> schedules = em
.createQuery("select s from Schedule s where s.enabled = true", Schedule.class)
.getResultList();
schedules.forEach(s -> System.out.println(s.getPath() + " : " + s.getDefinition()));
schedules.forEach(s -> kfs.write(s.getPath(), s.getDefinition()));
ArrayList<String> testRules = new ArrayList<String>();
testRules.add(testRuleAdd);
kfs.write("src/main/resources/r1.drl", testRuleAdd);
kfs.write("src/main/resources/r2.drl", testRuleAdd2);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR))
logger.trace("repository version: " + ks.getRepository().getDefaultReleaseId());
ReleaseId initialReleaseId = ks.getRepository().getDefaultReleaseId();
KieContainer kc = ks.newKieContainer(initialReleaseId);
KieSession ksession = kc.newKieSession();
ksession.setGlobal("queueService", queueService);
new Thread(new Runnable() {
public void run()
}).start();
Thread.sleep((10000));
// Update release version with same KieSession
ReleaseId relId2 = ks.newReleaseId("os-rules", "test-release-upgrade", "1.0.1");
KieFileSystem kfs_2 = ks.newKieFileSystem();
kfs_2.generateAndWritePomXML(relId2);
// kfs_2.write("src/main/resources/r1.drl", testRuleAdd);
// kfs_2.write("src/main/resources/r2.drl", testRuleAdd2);
kfs_2.write("src/main/resources/r3.drl", testRuleAdd3);
kfs_2.write("src/main/resources/r4.drl", testRuleAdd4);
kfs_2.write("src/main/resources/r5.drl", testRuleAdd5);
KieBuilder kb2 = ks.newKieBuilder(kfs_2).buildAll();
if (kb2.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
for (org.kie.api.builder.Message result : kb2.getResults().getMessages() )
throw new RuntimeException((kb2.getResults().toString()));
}
KieModule km = ks.getRepository().getKieModule((relId2));
kc.updateToVersion(relId2);
} catch (Exception ex)
{ logger.error("Failed to start the schedule runner: " + ex.getMessage()); }}
- is related to
-
DROOLS-751 Different threads accessing LeftTuple fields that reference LeftTupleSet
- Resolved