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;
}
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();
}
Aggregations