Search in sources :

Example 16 with LeftTupleSource

use of org.drools.core.reteoo.LeftTupleSource in project drools by kiegroup.

the class RuleNetworkEvaluator method getOffset.

public static int getOffset(NetworkNode node) {
    LeftTupleSource lt;
    int offset = 1;
    if (NodeTypeEnums.isTerminalNode(node)) {
        lt = ((TerminalNode) node).getLeftTupleSource();
        offset++;
    } else if (node.getType() == NodeTypeEnums.RightInputAdaterNode) {
        lt = ((RightInputAdapterNode) node).getLeftTupleSource();
    } else {
        lt = (LeftTupleSource) node;
    }
    while (lt.getType() != NodeTypeEnums.LeftInputAdapterNode) {
        offset++;
        lt = lt.getLeftTupleSource();
    }
    return offset;
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode)

Example 17 with LeftTupleSource

use of org.drools.core.reteoo.LeftTupleSource in project drools by kiegroup.

the class SegmentPropagator method propagate.

public static void propagate(SegmentMemory sourceSegment, TupleSets<LeftTuple> leftTuples, InternalWorkingMemory wm) {
    if (leftTuples.isEmpty()) {
        return;
    }
    LeftTupleSource source = (LeftTupleSource) sourceSegment.getTipNode();
    if (sourceSegment.isEmpty()) {
        SegmentUtilities.createChildSegments(wm, sourceSegment, source.getSinkPropagator());
    }
    processPeers(sourceSegment, leftTuples, wm);
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource)

Example 18 with LeftTupleSource

use of org.drools.core.reteoo.LeftTupleSource in project drools by kiegroup.

the class SegmentUtilities method inSubNetwork.

/**
 * Is the LeftTupleSource a node in the sub network for the RightInputAdapterNode
 * To be in the same network, it must be a node is after the two output of the parent
 * and before the rianode.
 */
public static boolean inSubNetwork(RightInputAdapterNode riaNode, LeftTupleSource leftTupleSource) {
    LeftTupleSource startTupleSource = riaNode.getStartTupleSource();
    LeftTupleSource parent = riaNode.getLeftTupleSource();
    while (parent != startTupleSource) {
        if (parent == leftTupleSource) {
            return true;
        }
        parent = parent.getLeftTupleSource();
    }
    return false;
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource)

Example 19 with LeftTupleSource

use of org.drools.core.reteoo.LeftTupleSource in project drools by kiegroup.

the class AccumulateBuilder method build.

/**
 * @inheritDoc
 */
public void build(final BuildContext context, final BuildUtils utils, final RuleConditionElement rce) {
    final Accumulate accumulate = (Accumulate) rce;
    boolean existSubNetwort = false;
    context.pushRuleComponent(accumulate);
    final List<BetaNodeFieldConstraint> resultBetaConstraints = context.getBetaconstraints();
    final List<AlphaNodeFieldConstraint> resultAlphaConstraints = context.getAlphaConstraints();
    RuleConditionElement source = accumulate.getSource();
    if (source instanceof GroupElement) {
        GroupElement ge = (GroupElement) source;
        if (ge.isAnd() && ge.getChildren().size() == 1) {
            source = ge.getChildren().get(0);
        }
    }
    // get builder for the pattern
    final ReteooComponentBuilder builder = utils.getBuilderFor(source);
    // save tuple source and current pattern offset for later if needed
    LeftTupleSource tupleSource = context.getTupleSource();
    final int currentPatternIndex = context.getCurrentPatternOffset();
    // builds the source pattern
    builder.build(context, utils, source);
    // if object source is null, then we need to adapt tuple source into a subnetwork
    if (context.getObjectSource() == null) {
        // attach right input adapter node to convert tuple source into an object source
        RightInputAdapterNode riaNode = context.getComponentFactory().getNodeFactoryService().buildRightInputNode(context.getNextId(), context.getTupleSource(), tupleSource, context);
        // attach right input adapter node to convert tuple source into an object source
        context.setObjectSource(utils.attachNode(context, riaNode));
        // restore tuple source from before the start of the sub network
        context.setTupleSource(tupleSource);
        // create a tuple start equals constraint and set it in the context
        final TupleStartEqualsConstraint constraint = TupleStartEqualsConstraint.getInstance();
        final List<BetaNodeFieldConstraint> betaConstraints = new ArrayList<BetaNodeFieldConstraint>();
        betaConstraints.add(constraint);
        context.setBetaconstraints(betaConstraints);
        existSubNetwort = true;
    }
    NodeFactory nfactory = context.getComponentFactory().getNodeFactoryService();
    final BetaConstraints resultsBinder = utils.createBetaNodeConstraint(context, resultBetaConstraints, true);
    final BetaConstraints sourceBinder = utils.createBetaNodeConstraint(context, context.getBetaconstraints(), false);
    AccumulateNode accNode = nfactory.buildAccumulateNode(context.getNextId(), context.getTupleSource(), context.getObjectSource(), resultAlphaConstraints.toArray(new AlphaNodeFieldConstraint[resultAlphaConstraints.size()]), sourceBinder, resultsBinder, accumulate, existSubNetwort, context);
    context.setTupleSource(utils.attachNode(context, accNode));
    // source pattern was bound, so nulling context
    context.setObjectSource(null);
    context.setCurrentPatternOffset(currentPatternIndex);
    context.popRuleComponent();
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) AccumulateNode(org.drools.core.reteoo.AccumulateNode) GroupElement(org.drools.core.rule.GroupElement) ArrayList(java.util.ArrayList) TupleStartEqualsConstraint(org.drools.core.common.TupleStartEqualsConstraint) RuleConditionElement(org.drools.core.rule.RuleConditionElement) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) TupleStartEqualsConstraint(org.drools.core.common.TupleStartEqualsConstraint) Accumulate(org.drools.core.rule.Accumulate) LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode)

Example 20 with LeftTupleSource

use of org.drools.core.reteoo.LeftTupleSource in project drools by kiegroup.

the class ReteooBuilderTest method nodesEquals.

private void nodesEquals(final Object object1, final Object object2) {
    assertEquals(object1 + " is not of the same type as " + object2, object1.getClass(), object2.getClass());
    assertEquals(object1 + " is not equal to " + object2, object1, object2);
    if (object1 instanceof ObjectSource) {
        final ObjectSource source1 = (ObjectSource) object1;
        final ObjectSource source2 = (ObjectSource) object2;
        final ObjectSink[] list1 = source1.getObjectSinkPropagator().getSinks();
        final ObjectSink[] list2 = source2.getObjectSinkPropagator().getSinks();
        assertEquals(object1.getClass() + " nodes have different number of sinks", list1.length, list2.length);
        for (int i = 0, size = list1.length; i < size; i++) {
            nodesEquals(list1[i], list2[i]);
        }
    } else if (object1 instanceof LeftTupleSource) {
        final LeftTupleSource source1 = (LeftTupleSource) object1;
        final LeftTupleSource source2 = (LeftTupleSource) object2;
        final LeftTupleSink[] list1 = source1.getSinkPropagator().getSinks();
        final LeftTupleSink[] list2 = source2.getSinkPropagator().getSinks();
        assertEquals(object1.getClass() + " nodes have different number of sinks", list1.length, list2.length);
        for (int i = 0, size = list1.length; i < size; i++) {
            nodesEquals(list1[i], list2[i]);
        }
    }
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) ObjectSource(org.drools.core.reteoo.ObjectSource) ObjectSink(org.drools.core.reteoo.ObjectSink)

Aggregations

LeftTupleSource (org.drools.core.reteoo.LeftTupleSource)20 ObjectSource (org.drools.core.reteoo.ObjectSource)7 RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)7 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)6 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)5 BetaMemory (org.drools.core.reteoo.BetaMemory)5 BetaNode (org.drools.core.reteoo.BetaNode)5 SegmentMemory (org.drools.core.reteoo.SegmentMemory)5 AccumulateNode (org.drools.core.reteoo.AccumulateNode)4 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)4 LeftTuple (org.drools.core.reteoo.LeftTuple)4 LeftTupleSink (org.drools.core.reteoo.LeftTupleSink)4 PathMemory (org.drools.core.reteoo.PathMemory)4 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)3 EntryPointNode (org.drools.core.reteoo.EntryPointNode)3 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)3 ObjectSink (org.drools.core.reteoo.ObjectSink)3 QueryElementNode (org.drools.core.reteoo.QueryElementNode)3 RiaNodeMemory (org.drools.core.reteoo.RightInputAdapterNode.RiaNodeMemory)3 RightTuple (org.drools.core.reteoo.RightTuple)3