use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class PathEndNodeTest method testSubNetworkSharing.
@Test
public void testSubNetworkSharing() throws Exception {
String str = "package org.test \n" + "rule xxx \n" + "when \n" + " $s : String()\n" + " not( Integer() and Long() )\n" + "then \n" + "end \n" + "rule yyy \n" + "when \n" + " $s : String()\n" + " not( Integer() and Long() )\n" + "then \n" + "end \n";
InternalKnowledgeBase kbase = (InternalKnowledgeBase) new KieHelper().addContent(str, ResourceType.DRL).build();
EntryPointNode epn = kbase.getRete().getEntryPointNode(EntryPointId.DEFAULT);
ObjectTypeNode otn = epn.getObjectTypeNodes().get(new ClassObjectType(Long.class));
BetaNode beta1 = (BetaNode) otn.getObjectSinkPropagator().getSinks()[0];
RightInputAdapterNode rian = (RightInputAdapterNode) beta1.getSinkPropagator().getSinks()[0];
BetaNode beta2 = (BetaNode) rian.getObjectSinkPropagator().getSinks()[0];
LeftTupleSink[] sinks = beta2.getSinkPropagator().getSinks();
RuleTerminalNode rtn1 = (RuleTerminalNode) sinks[0];
RuleTerminalNode rtn2 = (RuleTerminalNode) sinks[1];
assertEquals(3, rian.getPathEndNodes().length);
assertTrue(asList(rian.getPathEndNodes()).containsAll(asList(rtn1, rtn2, rian)));
kbase.removeRule("org.test", "xxx");
assertEquals(2, rian.getPathEndNodes().length);
RuleTerminalNode remainingRTN = rtn1.getRule().getName().equals("yyy") ? rtn1 : rtn2;
assertTrue(asList(rian.getPathEndNodes()).containsAll(asList(remainingRTN, rian)));
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class QueryTest method testDroolsQueryCleanup.
@Test
public void testDroolsQueryCleanup() throws Exception {
KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_QueryMemoryLeak.drl"));
KieSession session = createKieSession(kbase);
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.core.reteoo.EntryPointNode in project drools by kiegroup.
the class KieBaseUpdater method clearInstancesOfModifiedClass.
protected void clearInstancesOfModifiedClass(Class<?> cls) {
// remove all ObjectTypeNodes for the modified classes
ClassObjectType objectType = new ClassObjectType(cls);
for (EntryPointNode epn : ctx.kBase.getRete().getEntryPointNodes().values()) {
epn.removeObjectType(objectType);
}
// remove all instance of the old class from the object stores
for (InternalWorkingMemory wm : ctx.kBase.getWorkingMemories()) {
for (EntryPoint ep : wm.getEntryPoints()) {
InternalWorkingMemoryEntryPoint wmEp = (InternalWorkingMemoryEntryPoint) wm.getWorkingMemoryEntryPoint(ep.getEntryPointId());
ClassAwareObjectStore store = ((ClassAwareObjectStore) wmEp.getObjectStore());
if (store.clearClassStore(cls)) {
log.warn("Class " + cls.getName() + " has been modified and therfore its old instances will no longer match");
}
}
}
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class KnowledgeBaseImpl method rewireReteAfterDeserialization.
private void rewireReteAfterDeserialization() {
for (EntryPointNode entryPointNode : rete.getEntryPointNodes().values()) {
entryPointNode.setParentObjectSource(rete);
rewireNodeAfterDeserialization(entryPointNode);
}
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method updateEntryPointsCache.
// ------------------------------------------------------------
// Instance methods
// ------------------------------------------------------------
public void updateEntryPointsCache() {
if (kBase.getAddedEntryNodeCache() != null) {
for (EntryPointNode addedNode : kBase.getAddedEntryNodeCache()) {
EntryPointId id = addedNode.getEntryPoint();
if (EntryPointId.DEFAULT.equals(id))
continue;
WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(id, addedNode, this);
entryPoints.put(id.getEntryPointId(), wmEntryPoint);
}
}
if (kBase.getRemovedEntryNodeCache() != null) {
for (EntryPointNode removedNode : kBase.getRemovedEntryNodeCache()) {
entryPoints.remove(removedNode.getEntryPoint().getEntryPointId());
}
}
}
Aggregations