use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class SegmentMemory method getNodesInSegment.
public List<NetworkNode> getNodesInSegment() {
List<NetworkNode> nodes = new java.util.LinkedList<>();
NetworkNode currentNode = tipNode;
while (currentNode != rootNode) {
nodes.add(0, currentNode);
currentNode = ((LeftTupleSinkNode) currentNode).getLeftTupleSource();
}
nodes.add(0, currentNode);
return nodes;
}
use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class QueryTerminalNodeVisitor method doVisit.
@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
QueryTerminalNode rtn = (QueryTerminalNode) node;
RuleImpl rule = rtn.getRule();
// first thing, associate all nodes belonging to this rule
for (NetworkNode snode : nodeStack) {
info.assign(snode, rule);
}
// Query Terminal Nodes no longer have memory
// TODO delete this
// final LinkedList<?> memory = (LinkedList<?>) info.getSession().getNodeMemory( rtn );
// final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo( node );
// ni.setMemoryEnabled( true );
// ni.setTupleMemorySize( memory.size() );
}
use of org.drools.core.common.NetworkNode in project drools by kiegroup.
the class RuleNetworkEvaluator method evaluateNetwork.
public void evaluateNetwork(PathMemory pmem, RuleExecutor executor, ActivationsManager activationsManager) {
SegmentMemory[] smems = pmem.getSegmentMemories();
SegmentMemory smem = smems[0];
if (smem == null) {
// if there's no first smem it's a pure alpha firing and then doesn't require any furthe evaluation
return;
}
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) smem.getRootNode();
LinkedList<StackEntry> stack = new LinkedList<>();
NetworkNode node;
Memory nodeMem;
boolean firstSegmentIsOnlyLia = liaNode == smem.getTipNode();
if (firstSegmentIsOnlyLia) {
// segment only has liaNode in it
// nothing is staged in the liaNode, so skip to next segment
smem = smems[1];
node = smem.getRootNode();
nodeMem = smem.getNodeMemories().getFirst();
} else {
// lia is in shared segment, so point to next node
node = liaNode.getSinkPropagator().getFirstLeftTupleSink();
// skip the liaNode memory
nodeMem = smem.getNodeMemories().getFirst().getNext();
}
TupleSets<LeftTuple> srcTuples = smem.getStagedLeftTuples();
if (log.isTraceEnabled()) {
log.trace("Rule[name={}] segments={} {}", ((TerminalNode) pmem.getPathEndNode()).getRule().getName(), smems.length, srcTuples.toStringSizes());
}
outerEval(pmem, node, firstSegmentIsOnlyLia ? 1L : 2L, nodeMem, smems, firstSegmentIsOnlyLia ? 1 : 0, srcTuples, activationsManager, stack, true, executor);
}
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, ActivationsManager activationsManager) {
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, activationsManager.getReteEvaluator());
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, activationsManager, stack, processRian, executor);
}
Aggregations