use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doRightInserts.
private void doRightInserts(AccumulateNode accNode, AccumulateMemory am, ReteEvaluator reteEvaluator, TupleSets<RightTuple> srcRightTuples, 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();
if (srcRightTuples.getInsertSize() > 32 && rtm instanceof AbstractHashTable) {
((AbstractHashTable) rtm).ensureCapacity(srcRightTuples.getInsertSize());
}
boolean tupleMemoryEnabled = accNode.isLeftTupleMemoryEnabled();
for (RightTuple rightTuple = srcRightTuples.getInsertFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
boolean useTupleMemory = tupleMemoryEnabled || RuleNetworkEvaluator.useLeftMemory(accNode, rightTuple);
if (useTupleMemory || !accNode.isRightInputIsRiaNode()) {
// If tuple memory is off, it will still be when it is not a subnetwork.
rtm.add(rightTuple);
}
if (accNode.isRightInputIsRiaNode() || (ltm != null && ltm.size() > 0)) {
constraints.updateFromFactHandle(contextEntry, reteEvaluator, rightTuple.getFactHandleForEvaluation());
FastIterator leftIt = accNode.getLeftIterator(ltm);
for (LeftTuple leftTuple = accNode.getFirstLeftTuple(rightTuple, ltm, leftIt); leftTuple != null; leftTuple = (LeftTuple) leftIt.next(leftTuple)) {
if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
final BaseAccumulation accctx = (BaseAccumulation) leftTuple.getContextObject();
addMatch(accNode, accumulate, leftTuple, rightTuple, null, null, reteEvaluator, am, accctx, true, false);
// so any existing leftTuples we know are updates, but only add if not already added
if (leftTuple.getStagedType() == LeftTuple.NONE) {
trgLeftTuples.addUpdate(leftTuple);
}
}
}
}
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetFactHandle(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakExistsNode method doRightDeletes.
public void doRightDeletes(ExistsNode existsNode, BetaMemory bm, ReteEvaluator reteEvaluator, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TupleMemory rtm = bm.getRightTupleMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = existsNode.getRawConstraints();
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
FastIterator it = existsNode.getRightIterator(rtm);
boolean useComparisonIndex = rtm.getIndexType().isComparison();
RightTuple rootBlocker = useComparisonIndex ? null : (RightTuple) it.next(rightTuple);
if (rightTuple.getMemory() != null) {
// it may have been staged and never actually added
rtm.remove(rightTuple);
}
if (rightTuple.getBlocked() != null) {
for (LeftTuple leftTuple = rightTuple.getBlocked(); leftTuple != null; ) {
LeftTuple temp = leftTuple.getBlockedNext();
leftTuple.clearBlocker();
if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
// ignore, as it will get processed via left iteration. Children cannot be processed twice
leftTuple = temp;
continue;
}
constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
if (useComparisonIndex) {
rootBlocker = (RightTuple) rtm.getFirst(leftTuple);
}
// we know that older tuples have been checked so continue previously
for (RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) it.next(newBlocker)) {
if (!newBlocker.isDeleted() && constraints.isAllowedCachedLeft(contextEntry, newBlocker.getFactHandleForEvaluation())) {
leftTuple.setBlocker(newBlocker);
newBlocker.addBlocked(leftTuple);
break;
}
}
if (leftTuple.getBlocker() == null) {
// was previous blocked and not in memory, so add
ltm.add(leftTuple);
LeftTuple childLeftTuple = leftTuple.getFirstChild();
if (childLeftTuple != null) {
childLeftTuple.setPropagationContext(rightTuple.getPropagationContext());
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
}
}
leftTuple = temp;
}
}
rightTuple.setBlocked(null);
rightTuple.clearStaged();
rightTuple = next;
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakNotNode method doLeftInserts.
public void doLeftInserts(NotNode notNode, LeftTupleSink sink, BetaMemory bm, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = notNode.getRawConstraints();
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(notNode, leftTuple);
constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
// This method will also remove rightTuples that are from subnetwork where no leftmemory use used
RuleNetworkEvaluator.findLeftTupleBlocker(notNode, rtm, contextEntry, constraints, leftTuple, useLeftMemory);
if (leftTuple.getBlocker() == null) {
insertChildLeftTuple(sink, trgLeftTuples, ltm, leftTuple, leftTuple.getPropagationContext(), useLeftMemory);
}
leftTuple.clearStaged();
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakNotNode method doLeftDeletes.
public void doLeftDeletes(BetaMemory bm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
RightTuple blocker = leftTuple.getBlocker();
if (blocker == null) {
if (leftTuple.getMemory() != null) {
// it may have been staged and never actually added
ltm.remove(leftTuple);
}
LeftTuple childLeftTuple = leftTuple.getFirstChild();
if (childLeftTuple != null) {
// NotNode only has one child
childLeftTuple.setPropagationContext(leftTuple.getPropagationContext());
// no need to update pctx, as no right available, and pctx will exist on a parent LeftTuple anyway
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
}
} else {
blocker.removeBlocked(leftTuple);
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class RuleNetworkEvaluator method doUpdatesReorderRightMemory.
public static void doUpdatesReorderRightMemory(BetaMemory bm, TupleSets<RightTuple> srcRightTuples) {
TupleMemory rtm = bm.getRightTupleMemory();
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
if (rightTuple.getMemory() != null) {
rtm.removeAdd(rightTuple);
doUpdatesReorderChildLeftTuple(rightTuple);
}
}
}
Aggregations