use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class ProtobufMarshaller method unmarshall.
public StatefulKnowledgeSession unmarshall(final InputStream stream, KieSessionConfiguration config, Environment environment) throws IOException, ClassNotFoundException {
if (config == null) {
config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
}
if (environment == null) {
environment = KieServices.get().newEnvironment();
}
MarshallerReaderContext context = new MarshallerReaderContext(stream, (KnowledgeBaseImpl) kbase, RuleBaseNodes.getNodeMap((KnowledgeBaseImpl) kbase), this.strategyStore, TIMER_READERS, this.marshallingConfig.isMarshallProcessInstances(), this.marshallingConfig.isMarshallWorkItems(), environment);
int id = ((KnowledgeBaseImpl) this.kbase).nextWorkingMemoryCounter();
RuleBaseConfiguration conf = ((KnowledgeBaseImpl) this.kbase).getConfiguration();
StatefulKnowledgeSessionImpl session = ProtobufInputMarshaller.readSession(context, id, environment, (SessionConfiguration) config, initializer);
context.close();
if (((SessionConfiguration) config).isKeepReference()) {
((KnowledgeBaseImpl) this.kbase).addStatefulSession(session);
}
return session;
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class DroolsAbstractPMMLTest method createExecutor.
protected RuleUnitExecutor createExecutor(String sourceName) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
ReleaseId releaseId = new ReleaseIdImpl("org.kie:pmmlTest:1.0-SNAPSHOT");
((KieRepositoryImpl) kr).setDefaultGAV(releaseId);
Resource res = ResourceFactory.newClassPathResource(sourceName);
kbase = new KieHelper().addResource(res, ResourceType.PMML).build();
assertNotNull(kbase);
RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
KieContainer kc = ((KnowledgeBaseImpl) ((InternalRuleUnitExecutor) executor).getKieSession().getKieBase()).getKieContainer();
InternalKieModule ikm = (InternalKieModule) kr.getKieModule(releaseId);
try (FileOutputStream fos = new FileOutputStream("/tmp/outputModule.jar")) {
fos.write(ikm.getBytes());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
kc.getKieBaseNames().forEach(n -> {
System.out.println(n);
});
data = executor.newDataSource("request");
resultData = executor.newDataSource("results");
pmmlData = executor.newDataSource("pmmlData");
return executor;
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class RuleTest method testTimeMachine.
@Test
public void testTimeMachine() {
SessionConfiguration conf = SessionConfiguration.newInstance();
conf.setClockType(ClockType.PSEUDO_CLOCK);
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(conf, null);
final Calendar future = Calendar.getInstance();
((PseudoClockScheduler) wm.getSessionClock()).setStartupTime(future.getTimeInMillis());
final RuleImpl rule = new RuleImpl("myrule");
rule.setEnabled(EnabledBoolean.ENABLED_TRUE);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
future.setTimeInMillis(future.getTimeInMillis() + 100000000);
rule.setDateEffective(future);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
((PseudoClockScheduler) wm.getSessionClock()).advanceTime(1000000000000L, TimeUnit.MILLISECONDS);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class RuleTest method testDateExpires.
@Test
public void testDateExpires() throws Exception {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar earlier = Calendar.getInstance();
earlier.setTimeInMillis(10);
rule.setDateExpires(earlier);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar later = Calendar.getInstance();
later.setTimeInMillis(later.getTimeInMillis() + 100000000);
rule.setDateExpires(later);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.impl.KnowledgeBaseImpl in project drools by kiegroup.
the class ScenarioTest method createContext.
public BuildContext createContext() {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf);
BuildContext buildContext = new BuildContext(rbase);
RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1");
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.pkg1");
pkg.getDialectRuntimeRegistry().setDialectData("mvel", new MVELDialectRuntimeData());
pkg.addRule(rule);
buildContext.setRule(rule);
return buildContext;
}
Aggregations