use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class FactHandleMarshallingTest method createWorkingMemory.
private StatefulKnowledgeSessionImpl createWorkingMemory(InternalKnowledgeBase kBase) {
// WorkingMemoryEntryPoint
KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.PSEUDO);
SessionConfiguration sessionConf = ((SessionConfiguration) ksconf);
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase, true, sessionConf, EnvironmentFactory.newEnvironment());
return wm;
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ProtobufInputMarshaller method readSession.
public static ReadSessionResult readSession(ProtobufMarshallerReaderContext context, int id, Environment environment, SessionConfiguration config, KieSessionInitializer initializer) throws IOException, ClassNotFoundException {
ProtobufMessages.KnowledgeSession _session = loadAndParseSession(context);
StatefulKnowledgeSessionImpl session = createAndInitializeSession(context, id, environment, config, _session);
// Initialize the session before unmarshalling data
if (initializer != null) {
initializer.init(session);
}
return new ReadSessionResult(readSession(_session, session, session.getAgenda(), context), _session);
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class ProtobufInputMarshaller method createAndInitializeSession.
private static StatefulKnowledgeSessionImpl createAndInitializeSession(ProtobufMarshallerReaderContext context, int id, Environment environment, SessionConfiguration config, ProtobufMessages.KnowledgeSession _session) throws IOException {
FactHandleFactory handleFactory = context.getKnowledgeBase().newFactHandleFactory(_session.getRuleData().getLastId(), _session.getRuleData().getLastRecency());
InternalAgenda agenda = RuntimeComponentFactory.get().getAgendaFactory().createAgenda(context.getKnowledgeBase(), false);
StatefulKnowledgeSessionImpl session = (StatefulKnowledgeSessionImpl) PhreakWorkingMemoryFactory.getInstance().createWorkingMemory(id, context.getKnowledgeBase(), handleFactory, // pCTx starts at 1, as InitialFact is 0
1, config, agenda, environment);
agenda.setWorkingMemory(session);
readAgenda(context, _session.getRuleData(), agenda);
return session;
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class QueryTest method testDroolsQueryCleanup.
@Test
public void testDroolsQueryCleanup() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_QueryMemoryLeak.drl");
KieSession ksession = kbase.newKieSession();
String workerId = "B1234";
Worker worker = new Worker();
worker.setId(workerId);
FactHandle handle = ksession.insert(worker);
ksession.fireAllRules();
assertNotNull(handle);
Object retractedWorker = null;
for (int i = 0; i < 100; i++) {
retractedWorker = (Object) ksession.getQueryResults("getWorker", new Object[] { workerId });
}
assertNotNull(retractedWorker);
StatefulKnowledgeSessionImpl sessionImpl = (StatefulKnowledgeSessionImpl) ksession;
Collection<EntryPointNode> entryPointNodes = sessionImpl.getKnowledgeBase().getRete().getEntryPointNodes().values();
EntryPointNode defaultEntryPointNode = null;
for (EntryPointNode epNode : entryPointNodes) {
if (epNode.getEntryPoint().getEntryPointId().equals("DEFAULT")) {
defaultEntryPointNode = epNode;
break;
}
}
assertNotNull(defaultEntryPointNode);
Map<ObjectType, ObjectTypeNode> obnodes = defaultEntryPointNode.getObjectTypeNodes();
ObjectType key = new ClassObjectType(DroolsQuery.class);
ObjectTypeNode droolsQueryNode = obnodes.get(key);
Iterator<InternalFactHandle> it = ((ObjectTypeNodeMemory) sessionImpl.getNodeMemory(droolsQueryNode)).iterator();
assertFalse(it.hasNext());
}
use of org.drools.kiesession.session.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class BayesRuntimeTest method testBayesRuntimeManager.
@Test
public void testBayesRuntimeManager() throws Exception {
KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
kbuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
InternalKnowledgeBase kbase = getKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kbase.newKieSession();
BayesRuntime bayesRuntime = ksession.getKieRuntime(BayesRuntime.class);
BayesInstance<Garden> instance = bayesRuntime.createInstance(Garden.class);
assertNotNull(instance);
}
Aggregations