use of org.drools.core.reteoo.RightTuple in project drools by kiegroup.
the class PhreakNotNode method doRightDeletes.
public void doRightDeletes(NotNode notNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = notNode.getRawConstraints();
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
FastIterator it = notNode.getRightIterator(rtm);
// assign now, so we can remove from memory before doing any possible propagations
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, wm, leftTuple);
if (useComparisonIndex) {
rootBlocker = (RightTuple) rtm.getFirst(leftTuple);
}
// we know that older tuples have been checked so continue next
for (RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) it.next(newBlocker)) {
if (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
insertChildLeftTuple(sink, trgLeftTuples, ltm, leftTuple, rightTuple.getPropagationContext(), true);
}
leftTuple = temp;
}
}
rightTuple.setBlocked(null);
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.RightTuple in project drools by kiegroup.
the class RuleNetworkEvaluator method doRiaNode2.
private void doRiaNode2(InternalWorkingMemory wm, TupleSets<LeftTuple> srcTuples, RightInputAdapterNode riaNode) {
ObjectSink[] sinks = riaNode.getObjectSinkPropagator().getSinks();
BetaNode betaNode = (BetaNode) sinks[0];
BetaMemory bm;
Memory nodeMem = wm.getNodeMemory(betaNode);
if (NodeTypeEnums.AccumulateNode == betaNode.getType()) {
bm = ((AccumulateMemory) nodeMem).getBetaMemory();
} else {
bm = (BetaMemory) nodeMem;
}
TupleSets<RightTuple> rightTuples = bm.getStagedRightTuples();
// Build up iteration array for other sinks
BetaNode[] bns = null;
BetaMemory[] bms = null;
int length = sinks.length;
if (length > 1) {
bns = new BetaNode[sinks.length - 1];
bms = new BetaMemory[sinks.length - 1];
for (int i = 1; i < length; i++) {
bns[i - 1] = (BetaNode) sinks[i];
Memory nodeMem2 = wm.getNodeMemory(bns[i - 1]);
if (NodeTypeEnums.AccumulateNode == betaNode.getType()) {
bms[i - 1] = ((AccumulateMemory) nodeMem2).getBetaMemory();
} else {
bms[i - 1] = (BetaMemory) nodeMem2;
}
}
}
// subtract one, as first is not in the array;
length--;
for (SubnetworkTuple subnetworkTuple = (SubnetworkTuple) srcTuples.getInsertFirst(); subnetworkTuple != null; ) {
SubnetworkTuple next = (SubnetworkTuple) subnetworkTuple.getStagedNext();
if (bm.getStagedRightTuples().isEmpty()) {
bm.setNodeDirtyWithoutNotify();
}
subnetworkTuple.prepareStagingOnRight();
rightTuples.addInsert(subnetworkTuple);
if (bns != null) {
for (int i = 0; i < length; i++) {
if (bms[i].getStagedRightTuples().isEmpty()) {
bms[i].setNodeDirtyWithoutNotify();
}
subnetworkTuple = riaNode.createPeer(subnetworkTuple);
bms[i].getStagedRightTuples().addInsert(subnetworkTuple);
}
}
subnetworkTuple = next;
}
for (SubnetworkTuple subnetworkTuple = (SubnetworkTuple) srcTuples.getDeleteFirst(); subnetworkTuple != null; ) {
SubnetworkTuple next = (SubnetworkTuple) subnetworkTuple.getStagedNext();
if (rightTuples.isEmpty()) {
bm.setNodeDirtyWithoutNotify();
}
switch(subnetworkTuple.getStagedTypeOnRight()) {
// handle clash with already staged entries
case Tuple.INSERT:
rightTuples.removeInsert(subnetworkTuple);
break;
case Tuple.UPDATE:
rightTuples.removeUpdate(subnetworkTuple);
break;
}
subnetworkTuple.prepareStagingOnRight();
rightTuples.addDelete(subnetworkTuple);
if (bns != null) {
for (int i = 0; i < length; i++) {
subnetworkTuple = (SubnetworkTuple) subnetworkTuple.getPeer();
if (bms[i].getStagedRightTuples().isEmpty()) {
bms[i].setNodeDirtyWithoutNotify();
}
bms[i].getStagedRightTuples().addDelete(subnetworkTuple);
subnetworkTuple.setStagedOnRight();
}
}
subnetworkTuple = next;
}
for (SubnetworkTuple subnetworkTuple = (SubnetworkTuple) srcTuples.getUpdateFirst(); subnetworkTuple != null; ) {
SubnetworkTuple next = (SubnetworkTuple) subnetworkTuple.getStagedNext();
if (rightTuples.isEmpty()) {
bm.setNodeDirtyWithoutNotify();
}
subnetworkTuple.prepareStagingOnRight();
rightTuples.addUpdate(subnetworkTuple);
if (bns != null) {
for (int i = 0; i < length; i++) {
subnetworkTuple = (SubnetworkTuple) subnetworkTuple.getPeer();
if (bms[i].getStagedRightTuples().isEmpty()) {
bms[i].setNodeDirtyWithoutNotify();
}
bms[i].getStagedRightTuples().addUpdate(subnetworkTuple);
subnetworkTuple.setStagedOnRight();
}
}
subnetworkTuple = next;
}
srcTuples.resetAll();
}
use of org.drools.core.reteoo.RightTuple 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) {
rightTuple.setTempRightTupleMemory(rightTuple.getMemory());
rtm.remove(rightTuple);
}
}
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
if (rightTuple.getTempRightTupleMemory() != null) {
rtm.add(rightTuple);
for (LeftTuple childLeftTuple = rightTuple.getFirstChild(); childLeftTuple != null; ) {
LeftTuple childNext = childLeftTuple.getRightParentNext();
childLeftTuple.reAddLeft();
childLeftTuple = childNext;
}
}
}
}
use of org.drools.core.reteoo.RightTuple in project drools by kiegroup.
the class RuleNetworkEvaluator method doUpdatesExistentialReorderRightMemory.
public static void doUpdatesExistentialReorderRightMemory(BetaMemory bm, BetaNode betaNode, TupleSets<RightTuple> srcRightTuples) {
TupleMemory rtm = bm.getRightTupleMemory();
boolean resumeFromCurrent = !(betaNode.isIndexedUnificationJoin() || rtm.getIndexType().isComparison());
if (rtm.getIndexType() != TupleMemory.IndexType.NONE) {
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
rtm.remove(rightTuple);
}
}
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
if (rightTuple.getMemory() != null) {
rightTuple.setTempRightTupleMemory(rightTuple.getMemory());
if (resumeFromCurrent) {
if (rightTuple.getBlocked() != null) {
// look for a non-staged right tuple first forward ...
RightTuple tempRightTuple = (RightTuple) rightTuple.getNext();
while (tempRightTuple != null && tempRightTuple.getStagedType() != LeftTuple.NONE) {
// next cannot be an updated or deleted rightTuple
tempRightTuple = (RightTuple) tempRightTuple.getNext();
}
// ... and if cannot find one try backward
if (tempRightTuple == null) {
tempRightTuple = (RightTuple) rightTuple.getPrevious();
while (tempRightTuple != null && tempRightTuple.getStagedType() != LeftTuple.NONE) {
// next cannot be an updated or deleted rightTuple
tempRightTuple = (RightTuple) tempRightTuple.getPrevious();
}
}
rightTuple.setTempNextRightTuple(tempRightTuple);
}
}
rightTuple.setTempBlocked(rightTuple.getBlocked());
rightTuple.setBlocked(null);
rtm.remove(rightTuple);
}
}
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
rtm.add(rightTuple);
if (resumeFromCurrent) {
RightTuple tempRightTuple = rightTuple.getTempNextRightTuple();
if (rightTuple.getBlocked() != null && tempRightTuple == null && rightTuple.getMemory() == rightTuple.getTempRightTupleMemory()) {
// the next RightTuple was null, but current RightTuple was added back into the same bucket, so reset as root blocker to re-match can be attempted
rightTuple.setTempNextRightTuple(rightTuple);
}
}
for (LeftTuple childLeftTuple = rightTuple.getFirstChild(); childLeftTuple != null; ) {
LeftTuple childNext = childLeftTuple.getRightParentNext();
childLeftTuple.reAddLeft();
childLeftTuple = childNext;
}
}
if (rtm.getIndexType() != TupleMemory.IndexType.NONE) {
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
rtm.add(rightTuple);
}
}
}
use of org.drools.core.reteoo.RightTuple in project drools by kiegroup.
the class RuleNetworkEvaluator method findLeftTupleBlocker.
public static void findLeftTupleBlocker(BetaNode betaNode, TupleMemory rtm, ContextEntry[] contextEntry, BetaConstraints constraints, LeftTuple leftTuple, boolean useLeftMemory) {
// This method will also remove rightTuples that are from subnetwork where no leftmemory use used
FastIterator it = betaNode.getRightIterator(rtm);
for (RightTuple rightTuple = betaNode.getFirstRightTuple(leftTuple, rtm, null, it); rightTuple != null; ) {
RightTuple nextRight = (RightTuple) it.next(rightTuple);
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandleForEvaluation())) {
leftTuple.setBlocker(rightTuple);
if (useLeftMemory) {
rightTuple.addBlocked(leftTuple);
break;
} else if (betaNode.isRightInputIsRiaNode()) {
// If we aren't using leftMemory and the right input is a RIAN, then we must iterate and find all subetwork right tuples and remove them
// so we don't break
rtm.remove(rightTuple);
} else {
break;
}
}
rightTuple = nextRight;
}
}
Aggregations