Package org.drools.core.common

Examples of org.drools.core.common.LeftTupleSets


            if (log.isTraceEnabled()) {
                log.trace("Stream removed entry {} {} size {}", System.identityHashCode(tupleQueue), tupleEntry, tupleQueue.size());
            }
            if (tupleEntry.getLeftTuple() != null) {
                SegmentMemory sm = tupleEntry.getNodeMemory().getSegmentMemory();
                LeftTupleSets tuples = sm.getStagedLeftTuples();
                tupleEntry.getLeftTuple().setPropagationContext(tupleEntry.getPropagationContext());
                switch (tupleEntry.getPropagationType()) {
                    case PropagationContext.INSERTION:
                    case PropagationContext.RULE_ADDITION:
                        tuples.addInsert(tupleEntry.getLeftTuple());
                        break;
                    case PropagationContext.MODIFICATION:
                        tuples.addUpdate(tupleEntry.getLeftTuple());
                        break;
                    case PropagationContext.DELETION:
                    case PropagationContext.EXPIRATION:
                    case PropagationContext.RULE_REMOVAL:
                        tuples.addDelete(tupleEntry.getLeftTuple());
                        break;
                }
            } else {
                BetaMemory bm = (BetaMemory) tupleEntry.getNodeMemory();
                tupleEntry.getRightTuple().setPropagationContext(tupleEntry.getPropagationContext());
View Full Code Here


            // lia is in shared segment, so point to next node
            node = liaNode.getSinkPropagator().getFirstLeftTupleSink();
            nodeMem = smem.getNodeMemories().getFirst().getNext(); // skip the liaNode memory
        }

        LeftTupleSets srcTuples = smem.getStagedLeftTuples();

        if (log.isTraceEnabled()) {
            log.trace("Rule[name={}] segments={} {}", ((TerminalNode)pmem.getNetworkNode()).getRule().getName(), smems.length, srcTuples.toStringSizes());
        }

        Set<String> visitedRules;
        if (((TerminalNode)pmem.getNetworkNode()).getType() == NodeTypeEnums.QueryTerminalNode) {
            visitedRules = new HashSet<String>();
View Full Code Here

    }

    public void evalStackEntry(StackEntry entry, LinkedList<StackEntry> stack, LinkedList<StackEntry> outerStack, RuleExecutor executor, InternalWorkingMemory wm) {
        NetworkNode node = entry.getNode();
        Memory nodeMem = entry.getNodeMem();
        LeftTupleSets trgTuples = entry.getTrgTuples();
        if (node.getType() == NodeTypeEnums.QueryElementNode) {
            // copy across the results, if any from the query node memory
            trgTuples.addAll(((QueryElementNodeMemory) nodeMem).getResultLeftTuples());
        }

        LeftTupleSinkNode sink = entry.getSink();
        PathMemory pmem = entry.getRmem();

        SegmentMemory[] smems = entry.getSmems();
        int smemIndex = entry.getSmemIndex();
        Set<String> visitedRules = entry.getVisitedRules();
        boolean processRian;
        if (NodeTypeEnums.isBetaNode(node)) {
            // queued beta nodes do not want their ria node evaluated, otherwise there is recursion
            processRian = false;
        } else {
            processRian = true;
        }

        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();
            } else {
                // Reached end of segment, start on new segment.
                SegmentPropagator.propagate(smem,
                                            trgTuples,
                                            wm);
                smem = smems[++smemIndex];
                trgTuples = smem.getStagedLeftTuples();
                node = (LeftTupleSink) smem.getRootNode();
                nodeMem = smem.getNodeMemories().getFirst();
            }
        }

        if (log.isTraceEnabled()) {
            int offset = getOffset(node);
            log.trace("{} Resume {} {}", indent(offset), node.toString(), trgTuples.toStringSizes());
        }
        innerEval(entry.getLiaNode(), pmem, node, nodeMem, smems, smemIndex, trgTuples, wm, stack, outerStack, visitedRules, processRian, executor);
    }
View Full Code Here

                          LinkedList<StackEntry> stack,
                          LinkedList<StackEntry> outerStack,
                          Set<String> visitedRules,
                          boolean processRian,
                          RuleExecutor executor) {
        LeftTupleSets srcTuples;
        SegmentMemory smem = smems[smemIndex];
        while (true) {
            srcTuples = trgTuples; // previous target, is now the source
            if (log.isTraceEnabled()) {
                int offset = getOffset(node);
                log.trace("{} {} {} {}", indent(offset), ++cycle, node.toString(), srcTuples.toStringSizes());
            }

            if (NodeTypeEnums.isTerminalNode(node)) {
                TerminalNode rtn = ( TerminalNode ) node;
                if (node.getType() == NodeTypeEnums.QueryTerminalNode) {
                    pQtNode.doNode((QueryTerminalNode) rtn,
                                   wm,
                                   srcTuples,
                                   stack);
                } else {
                    pRtNode.doNode(rtn,
                                   wm,
                                   srcTuples,
                                   executor);
                }
                return;
            } else if (NodeTypeEnums.RightInputAdaterNode == node.getType()) {
                doRiaNode2(wm, srcTuples, (RightInputAdapterNode) node, stack);
                return;
            }

            LeftTupleSets stagedLeftTuples;
            if (node == smem.getTipNode() ) {
                // we are about to process the segment tip, allow it to merge insert/update/delete clashes
                if ( smem.isEmpty() ) {
                    // Can happen if the next segments have not yet been initialized, only when there are no right inputs
                    synchronized ( smem ) {
                        if ( smem.isEmpty() ) {
                            SegmentUtilities.createChildSegments( wm,
                                                                  smem,
                                                                  ((LeftTupleSource) node).getSinkPropagator() );
                        }
                        stagedLeftTuples = smem.getFirst().getStagedLeftTuples();
                    }
                } else {
                    stagedLeftTuples = smem.getFirst().getStagedLeftTuples();
                }
            } else {
                stagedLeftTuples = null;
            }

            LeftTupleSinkNode sink = ((LeftTupleSource) node).getSinkPropagator().getFirstLeftTupleSink();

            trgTuples = new LeftTupleSets();


            if (NodeTypeEnums.isBetaNode(node)) {
                boolean exitInnerEval = evalBetaNode(liaNode, pmem, node, nodeMem, smems, smemIndex, trgTuples, wm, stack, outerStack, visitedRules, processRian, executor, srcTuples, stagedLeftTuples, sink);
                if ( exitInnerEval ) {
View Full Code Here

        LeftTupleMemory ltm = bm.getLeftTupleMemory();
        RightTupleMemory rtm = bm.getRightTupleMemory();
        ContextEntry[] contextEntry = bm.getContext();
        BetaConstraints constraints = notNode.getRawConstraints();

        LeftTupleSets stagedLeftTuples = null;
        if (!bm.getSegmentMemory().isEmpty()) {
            stagedLeftTuples = bm.getSegmentMemory().getFirst().getStagedLeftTuples();
        }

        // this must be processed here, rather than initial insert, as we need to link the blocker
View Full Code Here

            rightTuple.setLeftTuple( null );
            resultLeftTuple.setObject( null );

            DroolsQuery query = (DroolsQuery) this.factHandle.getObject();
            if ( unlinkedEnabled ) {
                LeftTupleSets leftTuples = query.getResultLeftTupleSets();
                LeftTuple childLeftTuple = rightTuple.getFirstChild();
                switch ( childLeftTuple.getStagedType() ) {
                    // handle clash with already staged entries
                    case LeftTuple.INSERT :
                        leftTuples.removeInsert( childLeftTuple );
                        break;
                    case LeftTuple.UPDATE :
                        leftTuples.removeUpdate( childLeftTuple );
                        break;
                }
                leftTuples.addDelete( childLeftTuple  );
                return;
            }

            RightTupleList rightTuples = query.getResultRetractRightTupleList();
            if ( rightTuples == null ) {
View Full Code Here

                rightTuple.setLeftTuple( resultLeftTuple );
                resultLeftTuple.setObject( rightTuple );
            }

            if ( unlinkedEnabled ) {
                LeftTupleSets leftTuples = dquery.getResultLeftTupleSets();
                LeftTuple childLeftTuple = rightTuple.getFirstChild();
                switch ( childLeftTuple.getStagedType() ) {
                    // handle clash with already staged entries
                    case LeftTuple.INSERT :
                        leftTuples.removeInsert( childLeftTuple );
                        break;
                    case LeftTuple.UPDATE :
                        leftTuples.removeUpdate( childLeftTuple );
                        break;
                }
                leftTuples.addUpdate( childLeftTuple  );
                return;
            }

            // Don't need to recreate child links, as they will already be there form the first "add"
View Full Code Here

        private LeftTupleSets resultLeftTuples;
       
        public QueryElementNodeMemory(QueryElementNode node) {
            this.node = node;
            this.resultLeftTuples = new LeftTupleSets();
        }
View Full Code Here

            }
        }
    }

    private static void doDeleteSegmentMemory(LeftTuple leftTuple, PropagationContext context, SegmentMemory sm, InternalWorkingMemory wm, boolean linkOrNotify) {
        LeftTupleSets leftTuples = sm.getStagedLeftTuples();
        switch ( leftTuple.getStagedType() ) {
        // handle clash with already staged entries
            case LeftTuple.INSERT :
                leftTuples.removeInsert( leftTuple );
                break;
            case LeftTuple.UPDATE :
                leftTuples.removeUpdate( leftTuple );
                break;
        }

        if ( linkOrNotify && sm.getStagedLeftTuples().deleteSize() == 0 ) {
            // staged is empty, so notify rule, to force re-evaluation
            sm.notifyRuleLinkSegment( wm );
        }
        leftTuple.setPropagationContext( context );
        leftTuples.addDelete(leftTuple);
    }
View Full Code Here

                SegmentUtilities.createChildSegments( wm, sm, liaNode.getSinkPropagator() );
            }
            sm = sm.getFirst(); // repoint to the child sm
        }
       
        LeftTupleSets leftTuples = sm.getStagedLeftTuples();
                      
        LeftTupleSink sink = liaNode.getSinkPropagator().getFirstLeftTupleSink() ;

        doUpdateSegmentMemory(leftTuple, context, wm, linkOrNotify, sm, leftTuples, sink);
View Full Code Here

TOP

Related Classes of org.drools.core.common.LeftTupleSets

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.