public void doLeftDeletes( BetaMemory bm, LeftTupleSets srcLeftTuples, LeftTupleSets trgLeftTuples, LeftTupleSets stagedLeftTuples) { LeftTupleMemory 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()); RuleNetworkEvaluator.deleteLeftChild( childLeftTuple, trgLeftTuples, stagedLeftTuples); // no need to update pctx, as no right available, and pctx will // exist on a parent LeftTuple anyway } } else { blocker.removeBlocked(leftTuple); } leftTuple.clearStaged(); leftTuple = next; } }
public static void doUpdatesExistentialReorderLeftMemory( BetaMemory bm, TupleSets<LeftTuple> srcLeftTuples) { TupleMemory ltm = bm.getLeftTupleMemory(); // sides must first be re-ordered, to ensure iteration integrity for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); if (leftTuple.getMemory() != null) { ltm.remove(leftTuple); } leftTuple = next; } for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); RightTuple blocker = leftTuple.getBlocker(); if (blocker == null) { ltm.add(leftTuple); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; ) { LeftTuple childNext = childLeftTuple.getHandleNext(); childLeftTuple.reAddRight(); childLeftTuple = childNext; } } else if (blocker.getStagedType() != LeftTuple.NONE) { // it's blocker is also being updated, so remove to force it to start from the beginning blocker.removeBlocked(leftTuple); } leftTuple = next; } }
public static void dpUpdatesExistentialReorderLeftMemory( BetaMemory bm, LeftTupleSets srcLeftTuples) { LeftTupleMemory ltm = bm.getLeftTupleMemory(); // sides must first be re-ordered, to ensure iteration integrity for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); if (leftTuple.getMemory() != null) { ltm.remove(leftTuple); } leftTuple = next; } for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); if (leftTuple.getBlocker() == null) { ltm.add(leftTuple); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; ) { LeftTuple childNext = childLeftTuple.getLeftParentNext(); childLeftTuple.reAddRight(); childLeftTuple = childNext; } } leftTuple = next; } }
public void remove(LeftTuple tuple) { LeftTupleList list = tuple.getMemory(); list.remove(tuple); if (list.getFirst() == null) { tree.delete(((Node<Comparable<Comparable>>) list).key); } size--; }
public synchronized void gcStreamQueue() { List<TupleEntry> nonNormalizedDeletes = flushStreamQueue(); for (TupleEntry tupleEntry : nonNormalizedDeletes) { if (tupleEntry.getLeftTuple() != null) { LeftTuple leftTuple = tupleEntry.getLeftTuple(); if (leftTuple.getMemory() != null) { if (tupleEntry.getNodeMemory() instanceof BetaMemory) { ((BetaMemory) tupleEntry.getNodeMemory()).getLeftTupleMemory().remove(leftTuple); } else { leftTuple.getMemory().remove(leftTuple); } } } else { RightTuple rightTuple = tupleEntry.getRightTuple(); if (rightTuple.getMemory() != null) { if (tupleEntry.getNodeMemory() instanceof BetaMemory) { ((BetaMemory) tupleEntry.getNodeMemory()).getRightTupleMemory().remove(rightTuple); } else { rightTuple.getMemory().remove(rightTuple); } } } } }
public void doLeftUpdates( NotNode notNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, LeftTupleSets srcLeftTuples, LeftTupleSets trgLeftTuples, LeftTupleSets stagedLeftTuples) { LeftTupleMemory ltm = bm.getLeftTupleMemory(); RightTupleMemory rtm = bm.getRightTupleMemory(); ContextEntry[] contextEntry = bm.getContext(); BetaConstraints constraints = notNode.getRawConstraints(); boolean leftUpdateOptimizationAllowed = notNode.isLeftUpdateOptimizationAllowed(); for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); FastIterator rightIt = notNode.getRightIterator(rtm); RightTuple firstRightTuple = notNode.getFirstRightTuple(leftTuple, rtm, null, rightIt); // If in memory, remove it, because we'll need to add it anyway if it's not blocked, to ensure // iteration order RightTuple blocker = leftTuple.getBlocker(); if (blocker == null) { if (leftTuple.getMemory() != null) { // memory can be null, if blocker was deleted in same do loop ltm.remove(leftTuple); } } else { // check if we changed bucket if (rtm.isIndexed() && !rightIt.isFullIterator()) { // if newRightTuple is null, we assume there was a bucket change and that bucket is empty if (firstRightTuple == null || firstRightTuple.getMemory() != blocker.getMemory()) { blocker.removeBlocked(leftTuple); blocker = null; } } } constraints.updateFromTuple(contextEntry, wm, leftTuple); if (!leftUpdateOptimizationAllowed && blocker != null) { blocker.removeBlocked(leftTuple); blocker = null; } // if we where not blocked before (or changed buckets), or the previous blocker no longer // blocks, then find the next blocker if (blocker == null || !constraints.isAllowedCachedLeft(contextEntry, blocker.getFactHandle())) { if (blocker != null) { // remove previous blocker if it exists, as we know it doesn't block any more blocker.removeBlocked(leftTuple); } // find first blocker, because it's a modify, we need to start from the beginning again for (RightTuple newBlocker = firstRightTuple; newBlocker != null; newBlocker = (RightTuple) rightIt.next(newBlocker)) { if (constraints.isAllowedCachedLeft(contextEntry, newBlocker.getFactHandle())) { leftTuple.setBlocker(newBlocker); newBlocker.addBlocked(leftTuple); break; } } LeftTuple childLeftTuple = leftTuple.getFirstChild(); if (leftTuple.getBlocker() != null) { // blocked if (childLeftTuple != null) { // blocked, with previous children, so must have not been previously blocked, so retract // no need to remove, as we removed at the start // to be matched against, as it's now blocked childLeftTuple.setPropagationContext( leftTuple .getBlocker() .getPropagationContext()); // we have the righttuple, so use it for the pctx RuleNetworkEvaluator.deleteLeftChild(childLeftTuple, trgLeftTuples, stagedLeftTuples); } // else: it's blocked now and no children so blocked before, thus do nothing } else if (childLeftTuple == null) { // not blocked, with no children, must have been previously blocked so assert ltm.add(leftTuple); // add to memory so other fact handles can attempt to match trgLeftTuples.addInsert( sink.createLeftTuple( leftTuple, sink, leftTuple.getPropagationContext(), true)); // use leftTuple for the pctx here, as the right one is not available // this won't cause a problem, as the trigger tuple (to the left) will be more recent // anwyay } else { updateChildLeftTuple(childLeftTuple, stagedLeftTuples, trgLeftTuples); // not blocked, with children, so wasn't previous blocked and still isn't so modify ltm.add(leftTuple); // add to memory so other fact handles can attempt to match childLeftTuple.reAddLeft(); } } leftTuple.clearStaged(); leftTuple = next; } constraints.resetTuple(contextEntry); }