use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doRightUpdates.
private void doRightUpdates(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = accNode.getRawConstraints();
Accumulate accumulate = accNode.getAccumulate();
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
if (ltm != null && ltm.size() > 0) {
LeftTuple childLeftTuple = rightTuple.getFirstChild();
FastIterator leftIt = accNode.getLeftIterator(ltm);
LeftTuple leftTuple = accNode.getFirstLeftTuple(rightTuple, ltm, leftIt);
constraints.updateFromFactHandle(contextEntry, reteEvaluator, rightTuple.getFactHandleForEvaluation());
// We assume a bucket change if leftTuple == null
if (childLeftTuple != null && ltm.isIndexed() && !leftIt.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory()))) {
// our index has changed, so delete all the previous matches
removePreviousMatchesForRightTuple(accNode, accumulate, rightTuple, reteEvaluator, am, childLeftTuple, trgLeftTuples);
// null so the next check will attempt matches for new bucket
childLeftTuple = null;
}
// if LeftTupleMemory is empty, there are no matches to modify
if (leftTuple != null) {
doRightUpdatesProcessChildren(accNode, am, reteEvaluator, bm, constraints, accumulate, leftIt, rightTuple, childLeftTuple, leftTuple, trgLeftTuples);
}
}
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetFactHandle(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doRightDeletes.
private void doRightDeletes(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
TupleMemory rtm = am.getBetaMemory().getRightTupleMemory();
Accumulate accumulate = accNode.getAccumulate();
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
if (rightTuple.getMemory() != null) {
// it may have been staged and never actually added
rtm.remove(rightTuple);
if (rightTuple.getFirstChild() != null) {
LeftTuple match = rightTuple.getFirstChild();
while (match != null) {
LeftTuple nextLeft = match.getRightParentNext();
LeftTuple leftTuple = match.getLeftParent();
final BaseAccumulation accctx = (BaseAccumulation) leftTuple.getContextObject();
// FIXME This will be really slow, if it re-accumulates on the same LeftTuple (MDP)
removeMatch(accNode, accumulate, rightTuple, match, reteEvaluator, am, accctx, true);
if (leftTuple.getStagedType() == LeftTuple.NONE) {
trgLeftTuples.addUpdate(leftTuple);
}
match = nextLeft;
}
}
}
rightTuple.clearStaged();
rightTuple = next;
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doLeftDeletes.
private void doLeftDeletes(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
Accumulate accumulate = accNode.getAccumulate();
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
if (leftTuple.getMemory() != null) {
// it may have been staged and never actually added
ltm.remove(leftTuple);
BaseAccumulation accctx = (BaseAccumulation) leftTuple.getContextObject();
leftTuple.setContextObject(null);
removePreviousMatchesForLeftTuple(accumulate, leftTuple, reteEvaluator, am, accctx, false);
propagateDelete(trgLeftTuples, stagedLeftTuples, accctx);
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doLeftUpdates.
private void doLeftUpdates(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleMemory rtm = bm.getRightTupleMemory();
Accumulate accumulate = accNode.getAccumulate();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = accNode.getRawConstraints();
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
BaseAccumulation accctx = (BaseAccumulation) leftTuple.getContextObject();
if (accNode.isRightInputIsRiaNode()) {
// This is a subnetwork, do not process further. As all matches will processed
// by the right updates. This is to avoid double iteration (first right side iteration
// then left side iteration) or for the join to find matching tuple chains, which it previously
// did via subsumption checking.
leftTuple.clearStaged();
trgLeftTuples.addUpdate(leftTuple);
leftTuple = next;
continue;
}
constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
FastIterator rightIt = accNode.getRightIterator(rtm);
RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple, rtm, rightIt);
LeftTuple childLeftTuple = leftTuple.getFirstChild();
// if rightTuple is null, we assume there was a bucket change and that bucket is empty
if (childLeftTuple != null && rtm.isIndexed() && !rightIt.isFullIterator() && (rightTuple == null || (rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory()))) {
// our index has changed, so delete all the previous matchings
removePreviousMatchesForLeftTuple(accumulate, leftTuple, reteEvaluator, am, accctx, true);
// null so the next check will attempt matches for new bucket
childLeftTuple = null;
}
// we can't do anything if RightTupleMemory is empty
if (rightTuple != null) {
doLeftUpdatesProcessChildren(accNode, am, reteEvaluator, bm, accumulate, constraints, rightIt, leftTuple, accctx, rightTuple, childLeftTuple);
}
leftTuple.clearStaged();
trgLeftTuples.addUpdate(leftTuple);
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doLeftInserts.
private void doLeftInserts(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
Accumulate accumulate = accNode.getAccumulate();
BetaMemory bm = am.getBetaMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = accNode.getRawConstraints();
boolean leftTupleMemoryEnabled = accNode.isLeftTupleMemoryEnabled();
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean useLeftMemory = leftTupleMemoryEnabled || RuleNetworkEvaluator.useLeftMemory(accNode, leftTuple);
if (useLeftMemory) {
ltm.add(leftTuple);
}
BaseAccumulation accresult = initAccumulationContext(am, reteEvaluator, accumulate, leftTuple);
if (accNode.isRightInputIsRiaNode()) {
// This is a subnetwork, do not process further. As all matches will processed
// by the right insert. This is to avoid double iteration (first right side iteration
// then left side iteration) or for the join to find matching tuple chains, which it previously
// did via subsumption checking.
leftTuple.clearStaged();
trgLeftTuples.addInsert(leftTuple);
leftTuple = next;
continue;
}
constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
FastIterator rightIt = accNode.getRightIterator(rtm);
for (RightTuple rightTuple = accNode.getFirstRightTuple(leftTuple, rtm, rightIt); rightTuple != null; ) {
RightTuple nextRightTuple = (RightTuple) rightIt.next(rightTuple);
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandleForEvaluation())) {
// add a match
addMatch(accNode, accumulate, leftTuple, rightTuple, null, null, reteEvaluator, am, accresult, useLeftMemory, true);
}
rightTuple = nextRightTuple;
}
leftTuple.clearStaged();
trgLeftTuples.addInsert(leftTuple);
constraints.resetTuple(contextEntry);
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
Aggregations