use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class DynamicEvalTest method testDynamicAdd2.
@Test
public void testDynamicAdd2() {
String test = "rule id3\n" + "when\n" + "eval(0 == 0)\n" + // this eval works
"String( this == \"go\" )\n" + "then\n" + "insertLogical( \"done\" );\n" + "end\n" + "rule id5\n" + "when\n" + "eval(0 == 0)\n" + // this eval works
"Integer( this == 7 )\n" + "then\n" + "insertLogical( \"done3\" );\n" + "end\n";
loadPackages(ResourceFactory.newByteArrayResource(test.getBytes()), ResourceType.DRL);
((RuleBase) session.getKieBase()).addPackages(kbuilder.getKnowledgePackages());
session.addEventListener(new DebugRuleRuntimeEventListener());
session.insert("go");
session.insert(5);
session.insert(7);
// 1
int fired = session.fireAllRules();
System.out.println(fired);
effects = session.getObjects();
assertTrue("fired", effects.contains("done"));
// so the above works, let's try it again
String test2 = "\nrule id4" + "\nwhen" + // this eval doesn't
"\neval(0 == 0 )" + "\nInteger( this == 5 )" + "\nthen" + "\ninsertLogical( \"done2\" );" + "\nend";
loadPackages(ResourceFactory.newByteArrayResource(test2.getBytes()), ResourceType.DRL);
((RuleBase) session.getKieBase()).addPackages(kbuilder.getKnowledgePackages());
// 0
fired = session.fireAllRules();
System.out.println(fired);
effects = session.getObjects();
// fails
assertTrue("fired", effects.contains("done2"));
for (Object o : session.getObjects()) {
System.out.println(o);
}
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class DynamicEvalTest method testDynamicAdd.
@Test
public void testDynamicAdd() {
String test = "\nrule id3" + "\nwhen" + // this eval works
"\neval(0 < 1)" + "\nthen" + "\ninsertLogical( \"done\" );" + "\nend";
loadPackages(ResourceFactory.newByteArrayResource(test.getBytes()), ResourceType.DRL);
((RuleBase) session.getKieBase()).addPackages(kbuilder.getKnowledgePackages());
session.addEventListener(new DebugRuleRuntimeEventListener());
// 1
int fired = session.fireAllRules();
System.out.println(fired);
effects = session.getObjects();
assertTrue("fired", effects.contains("done"));
// so the above works, let's try it again
String test2 = "\nrule id4" + "\nwhen" + // this eval doesn't
"\neval(0 == 0 )" + "\nthen" + "\ninsertLogical( \"done2\" );" + "\nend";
loadPackages(ResourceFactory.newByteArrayResource(test2.getBytes()), ResourceType.DRL);
((RuleBase) session.getKieBase()).addPackages(kbuilder.getKnowledgePackages());
// 0
fired = session.fireAllRules();
System.out.println(fired);
effects = session.getObjects();
// fails
assertTrue("fired", effects.contains("done2"));
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class KnowledgeBuilderImpl method newKnowledgeBase.
public KieBase newKnowledgeBase(KieBaseConfiguration conf) {
KnowledgeBuilderErrors errors = getErrors();
if (!errors.isEmpty()) {
for (KnowledgeBuilderError error : errors) {
logger.error(error.toString());
}
throw new IllegalArgumentException("Could not parse knowledge. See the logs for details.");
}
RuleBase kbase = RuleBaseFactory.newRuleBase(conf);
kbase.addPackages(Arrays.asList(getPackages()));
return KnowledgeBaseFactory.newKnowledgeBase(kbase);
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class AbstractKieModule method createKieBase.
public InternalKnowledgeBase createKieBase(KieBaseModelImpl kBaseModel, KieProject kieProject, BuildContext buildContext, KieBaseConfiguration conf) {
KnowledgePackagesBuildResult knowledgePackagesBuildResult = buildKnowledgePackages(kBaseModel, kieProject, buildContext);
if (knowledgePackagesBuildResult.hasErrors()) {
return null;
}
Collection<KiePackage> pkgs = knowledgePackagesBuildResult.getPkgs();
checkStreamMode(kBaseModel, conf, pkgs);
ClassLoader cl = kieProject.getClassLoader();
if (conf == null) {
conf = getKnowledgeBaseConfiguration(kBaseModel, cl);
} else if (conf instanceof RuleBaseConfiguration) {
((RuleBaseConfiguration) conf).setClassLoader(cl);
}
RuleBase kBase = RuleBaseFactory.newRuleBase(kBaseModel.getName(), conf);
kBase.addPackages(pkgs);
return KnowledgeBaseFactory.newKnowledgeBase(kBase);
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class ConcurrentNodeMemories method resetAllMemories.
public void resetAllMemories(StatefulKnowledgeSession session) {
RuleBase kBase = (RuleBase) session.getKieBase();
Set<SegmentMemory> smemSet = new HashSet<>();
for (int i = 0; i < memories.length(); i++) {
Memory memory = memories.get(i);
if (memory != null) {
memory.reset();
smemSet.add(memory.getSegmentMemory());
}
}
smemSet.forEach(smem -> resetSegmentMemory(session, kBase, smem));
}
Aggregations