}
private static void flushStagedTuples(LeftTupleSource splitStartNode, PathMemory pmem, InternalWorkingMemory wm, boolean removeTuples) {
int smemIndex = getSegmentPos(splitStartNode, null); // index before the segments are merged
SegmentMemory[] smems = pmem.getSegmentMemories();
SegmentMemory sm;
LeftTupleSink sink;
Memory mem;
long bit = 1;
if ( smems.length == 1 ) {
// there is no sharing
sm = smems[0];
if ( sm == null ) {
return; // segment has not yet been initialized
}
sink = ((LeftInputAdapterNode)sm.getRootNode()).getSinkPropagator().getFirstLeftTupleSink();
mem = sm.getNodeMemories().get(1);
bit = 2; // adjust bit to point to next node
} else {
sm = smems[smemIndex+1]; // segment after the split being removed.
if ( sm == null ) {
return; // segment has not yet been initialized
}
sink = (LeftTupleSink) sm.getRootNode();
mem = sm.getNodeMemories().get(0);
}
// stages the LeftTuples for deletion in the target SegmentMemory, if necessary it looks up the nodes to find.
if (removeTuples) {
processLeftTuples(splitStartNode, sink, sm, wm, false);
}
RuleNetworkEvaluator rne = new RuleNetworkEvaluator();
LeftInputAdapterNode lian = ( LeftInputAdapterNode ) smems[0].getRootNode();
LinkedList<StackEntry> stack = new LinkedList<StackEntry>();
LinkedList<StackEntry> outerStack = new LinkedList<StackEntry>();
Set<String> visitedRules = new HashSet<String>();
// The graph must be fully updated before SegmentMemory and PathMemories are mutated
if ( !sm.getStagedLeftTuples().isEmpty() && pmem.isRuleLinked() ) {
rne.outerEval( lian, pmem, sink, bit, mem,
smems, smemIndex, sm.getStagedLeftTuples().takeAll(),
wm, stack, outerStack, visitedRules, true,
pmem.getRuleAgendaItem().getRuleExecutor() );
}
}