Search in sources :

Example 21 with RightInputAdapterNode

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

the class SegmentUtilities method processBetaNode.

private static long processBetaNode(BetaNode betaNode, InternalWorkingMemory wm, SegmentMemory smem, long nodePosMask, long allLinkedTestMask, boolean updateNodeBit) {
    BetaMemory bm = NodeTypeEnums.AccumulateNode == betaNode.getType() ? ((AccumulateMemory) smem.createNodeMemory(betaNode, wm)).getBetaMemory() : (BetaMemory) smem.createNodeMemory(betaNode, wm);
    // this must be set first, to avoid recursion as sub networks can be initialised multiple ways
    // and bm.getSegmentMemory == null check can be used to avoid recursion.
    bm.setSegmentMemory(smem);
    if (betaNode.isRightInputIsRiaNode()) {
        RightInputAdapterNode riaNode = createRiaSegmentMemory(betaNode, wm);
        RiaNodeMemory riaMem = wm.getNodeMemory(riaNode);
        bm.setRiaRuleMemory(riaMem.getRiaPathMemory());
        if (updateNodeBit && canBeDisabled(betaNode) && riaMem.getRiaPathMemory().getAllLinkedMaskTest() > 0) {
            // only ria's with reactive subnetworks can be disabled and thus need checking
            allLinkedTestMask = allLinkedTestMask | nodePosMask;
        }
    } else if (updateNodeBit && canBeDisabled(betaNode)) {
        allLinkedTestMask = allLinkedTestMask | nodePosMask;
    }
    bm.setNodePosMaskBit(nodePosMask);
    if (NodeTypeEnums.NotNode == betaNode.getType()) {
        // not nodes start up linked in
        smem.linkNodeWithoutRuleNotify(bm.getNodePosMaskBit());
    }
    return allLinkedTestMask;
}
Also used : RiaNodeMemory(org.drools.core.reteoo.RightInputAdapterNode.RiaNodeMemory) BetaMemory(org.drools.core.reteoo.BetaMemory) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode)

Example 22 with RightInputAdapterNode

use of org.drools.core.reteoo.RightInputAdapterNode 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)

Aggregations

RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)22 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)10 BetaMemory (org.drools.core.reteoo.BetaMemory)10 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)10 Test (org.junit.Test)10 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)8 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)8 BetaNode (org.drools.core.reteoo.BetaNode)7 JoinNode (org.drools.core.reteoo.JoinNode)7 LeftTupleSource (org.drools.core.reteoo.LeftTupleSource)7 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)6 PathMemory (org.drools.core.reteoo.PathMemory)6 KieBase (org.kie.api.KieBase)6 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)5 ExistsNode (org.drools.core.reteoo.ExistsNode)5 ObjectSink (org.drools.core.reteoo.ObjectSink)5 SegmentMemory (org.drools.core.reteoo.SegmentMemory)5 ArrayList (java.util.ArrayList)4 Memory (org.drools.core.common.Memory)4