gpt4 book ai didi

java - 如何在 drools 7 中创建可重复使用的 KieBase

转载 作者:太空宇宙 更新时间:2023-11-04 09:56:01 27 4
gpt4 key购买 nike

我们通过以下方式实用地创建 KIEBase,并将编译后的 Kiebase 存储在 java 映射中:

private static Map<String, KieBase> kieBaseMap = new HashMap<>();

public setKieBaseMap(String groupId,String drl){
KieHelper kieHelper = new KieHelper();
kieHelper.addContent(drl, ResourceType.DRL);
Results results = kieHelper.verify();
kieBaseMap.put(groupId,kieHelper.build());
}

StatelessKieSession buildKieSession(String ruleGroupId) {
return kieBaseMap.get(ruleGroupId).newStatelessKieSession();
}

但是如果我们尝试再次执行相同的 Kiebase,我们会遇到以下异常:

java.lang.NullPointerException
at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:95)
at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:71)
at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:552)
at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:538)
at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:373)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:333)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:169)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:127)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:212)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:87)
at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34)
at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1067)
at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1014)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1006)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1308)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1299)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1283)
at org.drools.core.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:281)

我已经设置了drools.getWorkingMemory().getKnowledgeBase().getConfiguration().setProperty(SequentialOption.PROPERTY_NAME,"true")

按顺序执行所有规则。请帮助我为什么会收到此异常

最佳答案

由于我想以顺序方式运行议程组,因此需要在模块创建时自行设置 SequentialAgendaOption.DYNAMIC:

 kieSessionBuilder.setKieBaseMap(
ruleGroupId, kieHelper.build(SequentialAgendaOption.DYNAMIC, SequentialOption.YES));

那么这个问题就没有出现

关于java - 如何在 drools 7 中创建可重复使用的 KieBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54142775/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com