Search in sources :

Example 1 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, InternalAgenda agenda) {
    SegmentMemory[] smems = pmem.getSegmentMemories();
    int smemIndex = 0;
    // 0
    SegmentMemory smem = smems[smemIndex];
    LeftInputAdapterNode liaNode = (LeftInputAdapterNode) smem.getRootNode();
    LinkedList<StackEntry> stack = new LinkedList<StackEntry>();
    NetworkNode node;
    Memory nodeMem;
    long bit = 1;
    if (liaNode == smem.getTipNode()) {
        // segment only has liaNode in it
        // nothing is staged in the liaNode, so skip to next segment
        // 1
        smem = smems[++smemIndex];
        node = smem.getRootNode();
        nodeMem = smem.getNodeMemories().getFirst();
    } else {
        // lia is in shared segment, so point to next node
        bit = 2;
        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, bit, nodeMem, smems, smemIndex, srcTuples, agenda, stack, true, executor);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) Memory(org.drools.core.common.Memory) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) PathMemory(org.drools.core.reteoo.PathMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ConditionalBranchMemory(org.drools.core.reteoo.ConditionalBranchNode.ConditionalBranchMemory) 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) RiaPathMemory(org.drools.core.reteoo.RiaPathMemory) NetworkNode(org.drools.core.common.NetworkNode) LeftTuple(org.drools.core.reteoo.LeftTuple) LinkedList(org.drools.core.util.LinkedList) QueryTerminalNode(org.drools.core.reteoo.QueryTerminalNode) TerminalNode(org.drools.core.reteoo.TerminalNode) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 2 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 3 with NetworkNode

use of org.drools.core.common.NetworkNode in project drools by kiegroup.

the class RuleTerminalNodeVisitor method doVisit.

@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
    RuleTerminalNode rtn = (RuleTerminalNode) node;
    RuleImpl rule = rtn.getRule();
    // first thing, associate all nodes belonging to this rule
    for (NetworkNode snode : nodeStack) {
        info.assign(snode, rule);
    }
    final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo(node);
    ni.setMemoryEnabled(false);
}
Also used : RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) NetworkNode(org.drools.core.common.NetworkNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

Example 4 with NetworkNode

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

Example 5 with NetworkNode

use of org.drools.core.common.NetworkNode in project drools by kiegroup.

the class RuleTerminalNodeVisitor method doVisit.

@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
    RuleTerminalNode rtn = (RuleTerminalNode) node;
    RuleImpl rule = rtn.getRule();
    // first thing, associate all nodes belonging to this rule
    for (NetworkNode snode : nodeStack) {
        info.assign(snode, rule);
    }
    final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo(node);
    ni.setMemoryEnabled(false);
}
Also used : RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) NetworkNode(org.drools.core.common.NetworkNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode)

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