Search in sources :

Example 16 with NetworkNode

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;
}
Also used : NetworkNode(org.drools.core.common.NetworkNode) LinkedList(org.drools.core.util.LinkedList)

Example 17 with NetworkNode

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() );
}
Also used : QueryTerminalNode(org.drools.core.reteoo.QueryTerminalNode) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) NetworkNode(org.drools.core.common.NetworkNode)

Example 18 with NetworkNode

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);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) Memory(org.drools.core.common.Memory) AsyncReceiveMemory(org.drools.core.reteoo.AsyncReceiveNode.AsyncReceiveMemory) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) PathMemory(org.drools.core.reteoo.PathMemory) ConditionalBranchMemory(org.drools.core.reteoo.ConditionalBranchNode.ConditionalBranchMemory) BetaNode.getBetaMemory(org.drools.core.reteoo.BetaNode.getBetaMemory) AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) TupleMemory(org.drools.core.reteoo.TupleMemory) TimerNodeMemory(org.drools.core.reteoo.TimerNode.TimerNodeMemory) BetaMemory(org.drools.core.reteoo.BetaMemory) EvalMemory(org.drools.core.reteoo.EvalConditionNode.EvalMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) FromMemory(org.drools.core.reteoo.FromNode.FromMemory) AsyncSendMemory(org.drools.core.reteoo.AsyncSendNode.AsyncSendMemory) RiaPathMemory(org.drools.core.reteoo.RiaPathMemory) NetworkNode(org.drools.core.common.NetworkNode) QueryTerminalNode(org.drools.core.reteoo.QueryTerminalNode) TerminalNode(org.drools.core.reteoo.TerminalNode) LeftTuple(org.drools.core.reteoo.LeftTuple) LinkedList(org.drools.core.util.LinkedList) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 19 with NetworkNode

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);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) Memory(org.drools.core.common.Memory) AsyncReceiveMemory(org.drools.core.reteoo.AsyncReceiveNode.AsyncReceiveMemory) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) PathMemory(org.drools.core.reteoo.PathMemory) ConditionalBranchMemory(org.drools.core.reteoo.ConditionalBranchNode.ConditionalBranchMemory) BetaNode.getBetaMemory(org.drools.core.reteoo.BetaNode.getBetaMemory) AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) TupleMemory(org.drools.core.reteoo.TupleMemory) TimerNodeMemory(org.drools.core.reteoo.TimerNode.TimerNodeMemory) BetaMemory(org.drools.core.reteoo.BetaMemory) EvalMemory(org.drools.core.reteoo.EvalConditionNode.EvalMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) FromMemory(org.drools.core.reteoo.FromNode.FromMemory) AsyncSendMemory(org.drools.core.reteoo.AsyncSendNode.AsyncSendMemory) RiaPathMemory(org.drools.core.reteoo.RiaPathMemory) LeftTupleSink(org.drools.core.reteoo.LeftTupleSink) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) NetworkNode(org.drools.core.common.NetworkNode) LeftTuple(org.drools.core.reteoo.LeftTuple) LeftTupleSinkNode(org.drools.core.reteoo.LeftTupleSinkNode) PathMemory(org.drools.core.reteoo.PathMemory) RiaPathMemory(org.drools.core.reteoo.RiaPathMemory)

Aggregations

NetworkNode (org.drools.core.common.NetworkNode)19 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)6 NodeList (com.github.javaparser.ast.NodeList)5 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)5 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)5 SegmentMemory (org.drools.core.reteoo.SegmentMemory)5 NodeList.nodeList (com.github.javaparser.ast.NodeList.nodeList)4 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)4 VoidType (com.github.javaparser.ast.type.VoidType)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AlphaNode (org.drools.core.reteoo.AlphaNode)4 QueryTerminalNode (org.drools.core.reteoo.QueryTerminalNode)4 StaticJavaParser.parseStatement (com.github.javaparser.StaticJavaParser.parseStatement)3 Memory (org.drools.core.common.Memory)3 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)3 BetaMemory (org.drools.core.reteoo.BetaMemory)3 ConditionalBranchMemory (org.drools.core.reteoo.ConditionalBranchNode.ConditionalBranchMemory)3 EvalMemory (org.drools.core.reteoo.EvalConditionNode.EvalMemory)3 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)3