use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class SessionInspector method gatherNodeInfo.
private void gatherNodeInfo(NetworkNode parent, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
if (!info.visited(parent)) {
nodeStack.push(parent);
NetworkNodeVisitor visitor = visitors.get(parent.getType());
if (visitor != null) {
visitor.visit(parent, nodeStack, info);
} else {
throw new RuntimeException("No visitor found for node class: " + parent.getClass() + " node: " + parent);
}
visitChildren(parent, nodeStack, info);
nodeStack.pop();
} else {
// if already visited, then assign the same rules to the nodes currently in the stack
Set<RuleImpl> rules = info.getNodeInfo(parent).getRules();
for (NetworkNode snode : nodeStack) {
for (RuleImpl rule : rules) {
info.assign(snode, rule);
}
}
}
}
use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class PhreakTimerNode method evaluate.
private static void evaluate(PathMemory pmem, InternalAgenda agenda, LeftTupleSink sink, TimerNodeMemory tm, TupleSets<LeftTuple> trgLeftTuples) {
SegmentMemory[] smems = pmem.getSegmentMemories();
SegmentMemory sm = tm.getSegmentMemory();
int smemIndex = 0;
for (SegmentMemory smem : smems) {
if (smem == sm) {
break;
}
smemIndex++;
}
long bit = 1;
for (NetworkNode node = sm.getRootNode(); node != sink; node = ((LeftTupleSource) node).getSinkPropagator().getFirstLeftTupleSink()) {
// update the bit to the correct node position.
bit = bit << 1;
}
RuleNetworkEvaluator rne = new RuleNetworkEvaluator();
rne.outerEval(pmem, sink, bit, tm, smems, smemIndex, trgLeftTuples, agenda, new LinkedList<>(), true, pmem.getRuleAgendaItem().getRuleExecutor());
}
use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class RuleNetworkEvaluator method evalStackEntry.
public void evalStackEntry(StackEntry entry, LinkedList<StackEntry> stack, RuleExecutor executor, InternalAgenda agenda) {
NetworkNode node = entry.getNode();
Memory nodeMem = entry.getNodeMem();
TupleSets<LeftTuple> trgTuples = entry.getTrgTuples();
if (node.getType() == NodeTypeEnums.QueryElementNode) {
// copy across the results, if any from the query node memory
QueryElementNodeMemory qmem = (QueryElementNodeMemory) nodeMem;
qmem.setNodeCleanWithoutNotify();
qmem.getResultLeftTuples().addTo(trgTuples);
}
LeftTupleSinkNode sink = entry.getSink();
PathMemory pmem = entry.getRmem();
SegmentMemory[] smems = entry.getSmems();
int smemIndex = entry.getSmemIndex();
boolean processRian = entry.isProcessRian();
long bit = entry.getBit();
if (entry.isResumeFromNextNode()) {
SegmentMemory smem = smems[smemIndex];
if (node != smem.getTipNode()) {
// get next node and node memory in the segment
LeftTupleSink nextSink = sink.getNextLeftTupleSinkNode();
if (nextSink == null) {
node = sink;
} else {
// there is a nested subnetwork, take out path
node = nextSink;
}
nodeMem = nodeMem.getNext();
// update bit to new node
bit = bit << 1;
} else {
// Reached end of segment, start on new segment.
SegmentPropagator.propagate(smem, trgTuples, agenda.getWorkingMemory());
smem = smems[++smemIndex];
trgTuples = smem.getStagedLeftTuples().takeAll();
node = smem.getRootNode();
nodeMem = smem.getNodeMemories().getFirst();
// update bit to start of new segment
bit = 1;
}
}
if (log.isTraceEnabled()) {
int offset = getOffset(node);
log.trace("{} Resume {} {}", indent(offset), node.toString(), trgTuples.toStringSizes());
}
innerEval(pmem, node, bit, nodeMem, smems, smemIndex, trgTuples, agenda, stack, processRian, executor);
}
use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class InlineFieldReferenceInitHandler method generateInitBody.
private void generateInitBody(BlockStmt initBodyPerPartition, List<NetworkNode> subNodes, int partitionIndex) {
CompilationUnit partitionedCompilationUnit = partitionedNodeInitialisationClasses.get(partitionIndex);
PackageDeclaration partitionedClassPackage = (PackageDeclaration) partitionedCompilationUnit.getChildNodes().get(0);
ClassOrInterfaceDeclaration partitionedClass = (ClassOrInterfaceDeclaration) partitionedCompilationUnit.getChildNodes().get(1);
for (NetworkNode n : subNodes) {
if (n instanceof CanInlineInANC) {
String variableName;
final ClassOrInterfaceType initMethodReturnType;
if (n instanceof AlphaNode) {
variableName = getVariableName((AlphaNode) n);
initMethodReturnType = StaticJavaParser.parseClassOrInterfaceType(getVariableType((AlphaNode) n).getCanonicalName());
} else {
variableName = getVariableName((Sink) n);
initMethodReturnType = StaticJavaParser.parseClassOrInterfaceType(getVariableType((Sink) n).getCanonicalName());
}
String initMethodName = String.format("init%s", variableName);
// We'll need to partition the lambda creation as with too many the compiler crashes
// We'll move it to a separated class
MethodDeclaration initMethod = new MethodDeclaration(nodeList(Modifier.publicModifier(), Modifier.staticModifier()), initMethodName, initMethodReturnType, parametersFromAdditionalFields());
Expression initExpressionForNode = ((CanInlineInANC) n).toANCInlinedForm();
partitionedClass.addMember(initMethod);
BlockStmt initMethodBlock = new BlockStmt();
initMethodBlock.addStatement(new ReturnStmt(initExpressionForNode));
initMethod.setBody(initMethodBlock);
String callInitMethodAndAssignToFieldString = String.format("%s = %s.%s.%s(ctx);", variableName, partitionedClassPackage.getNameAsString(), partitionedClass.getNameAsString(), initMethodName);
initBodyPerPartition.addStatement(parseStatement(callInitMethodAndAssignToFieldString));
}
}
}
use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class PhreakTimerNode method evaluate.
private static void evaluate(PathMemory pmem, ActivationsManager activationsManager, LeftTupleSink sink, TimerNodeMemory tm, TupleSets<LeftTuple> trgLeftTuples) {
SegmentMemory[] smems = pmem.getSegmentMemories();
SegmentMemory sm = tm.getSegmentMemory();
int smemIndex = 0;
for (SegmentMemory smem : smems) {
if (smem == sm) {
break;
}
smemIndex++;
}
long bit = 1;
for (NetworkNode node = sm.getRootNode(); node != sink; node = ((LeftTupleSource) node).getSinkPropagator().getFirstLeftTupleSink()) {
// update the bit to the correct node position.
bit = bit << 1;
}
RuleNetworkEvaluator.INSTANCE.outerEval(pmem, sink, bit, tm, smems, smemIndex, trgLeftTuples, activationsManager, new LinkedList<>(), true, pmem.getRuleAgendaItem().getRuleExecutor());
}
Aggregations