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