}
public LeftTupleSets eval( NetworkNode node, Memory nodeMem, SegmentMemory[] smems, int smemIndex, LeftTupleSets trgTuples, LeftTupleSets stagedLeftTuples, InternalWorkingMemory wm) {
LeftTupleSets srcTuples;
SegmentMemory smem = smems[smemIndex];
while ( true ) {
// if ( log.isTraceEnabled() ) {
// log.trace( "Start Node[offset={}, type={}] Rule[name={}]", getRule().getName() );
// }
srcTuples = trgTuples; // previous target, is now the source
if ( NodeTypeEnums.isTerminalNode( node ) ) {
RuleTerminalNode rtn = rmem.getRuleTerminalNode();
pRtnNode.doNode( rtn, wm, srcTuples );
return null;
} else if ( NodeTypeEnums.RightInputAdaterNode == node.getType() ) {
return trgTuples;
}
if ( node == smem.getTipNode() && smem.getFirst() != null) {
// we are about to process the segment tip, allow it to merge insert/update/delete clashes
// Can happen if the next segments have not yet been initialized
stagedLeftTuples = smem.getFirst().getStagedLeftTuples();
} else {
stagedLeftTuples = null;
}
LeftTupleSinkNode sink = ((LeftTupleSource)node).getSinkPropagator().getFirstLeftTupleSink();
trgTuples = new LeftTupleSets();
if ( NodeTypeEnums.isBetaNode( node ) ) {
BetaNode betaNode = ( BetaNode )node;
BetaMemory bm = null;
AccumulateMemory am = null;
if ( NodeTypeEnums.AccumulateNode == node.getType() ) {
am = (AccumulateMemory) nodeMem;
bm = am.getBetaMemory();
} else {
bm = (BetaMemory) nodeMem;
}
if ( betaNode.isRightInputIsRiaNode() ) {
// if the subnetwork is nested in this segment, it will create srcTuples containing
// peer LeftTuples, suitable for the node in the main path.
srcTuples = doRiaNode( wm,
srcTuples,
betaNode,
bm );
}
switch( node.getType() ) {
case NodeTypeEnums.JoinNode:
pJoinNode.doNode( (JoinNode) node, sink,
bm, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
case NodeTypeEnums.NotNode:
pNotNode.doNode( (NotNode) node, sink,
bm, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
case NodeTypeEnums.ExistsNode:
pExistsNode.doNode( (ExistsNode) node, sink,
bm, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
case NodeTypeEnums.AccumulateNode:
pAccNode.doNode( (AccumulateNode) node, sink,
am, wm, srcTuples, trgTuples, stagedLeftTuples );
break;
}
} else if ( node.getType() == NodeTypeEnums.EvalConditionNode ) {
pEvalNode.doNode( (EvalConditionNode) node, (EvalMemory) nodeMem, sink,
wm, srcTuples, trgTuples, stagedLeftTuples );
} else if ( node.getType() == NodeTypeEnums.FromNode ) {
pFromNode.doNode( (FromNode) node, (FromMemory) nodeMem, sink,
wm, srcTuples, trgTuples, stagedLeftTuples );
} else if (true) {
pBranchNode.doNode( (ConditionalBranchNode) node, (ConditionalBranchMemory) nodeMem, sink,
wm, srcTuples, trgTuples, stagedLeftTuples );
}
if ( node != smem.getTipNode() ) {
// get next node and node memory in the segment
LeftTupleSink nextSink = sink.getNextLeftTupleSinkNode();
if ( nextSink == null ) {
node = sink;
} else {
// there is a nested subnetwork, take out path
node = nextSink;
}
nodeMem = nodeMem.getNext();
} else {
// Reached end of segment, start on new segment.
SegmentPropagator.propagate( smem, trgTuples, wm );
smem = smems[++smemIndex];
trgTuples = smem.getStagedLeftTuples();
node = ( LeftTupleSink ) smem.getRootNode();
nodeMem = smem.getNodeMemories().getFirst();
}
}
}