// determine the number of output streams
Object producingOp = operators.get(producerOpNum);
int numOutputStreams = operatorMetadata.get(producerOpNum).getOperatorSpec().getOutput().getItems().size();
List<ObjectBindingPair>[] targets = getOperatorConsumersPerStream(numOutputStreams, producerOpNum, operators, operatorMetadata, bindings);
EPDataFlowEmitter runtimeContext = generateRuntimeContext(statementContext.getEngineURI(), statementContext.getStatementName(), audit, dataFlowName, producerOpNum, operatorPrettyPrint, dataFlowSignalManager, targets, options);
if (options.isOperatorStatistics()) {
runtimeContext = new EPDataFlowEmitterWrapperWStatistics(runtimeContext, producerOpNum, statisticsProvider, options.isCpuStatistics());
}
JavaClassHelper.setFieldForAnnotation(producingOp, DataFlowContext.class, runtimeContext);
runtimeContexts.put(producerOpNum, runtimeContext);
}
// Second pass: hook punctuation such that it gets forwarded
for (int producerOpNum : operatorBuildOrder) {
String operatorPrettyPrint = operatorMetadata.get(producerOpNum).getOperatorPrettyPrint();
if (log.isDebugEnabled()) {
log.debug("Handling signals for " + operatorPrettyPrint);
}
// determine consumers that receive punctuation
Set<Integer> consumingOperatorsWithPunctuation = new HashSet<Integer>();
for (LogicalChannelBinding binding : bindings) {
if (!binding.getLogicalChannel().getOutputPort().isHasPunctuation() || binding.getLogicalChannel().getOutputPort().getProducingOpNum() != producerOpNum) {
continue;
}
consumingOperatorsWithPunctuation.add(binding.getLogicalChannel().getConsumingOpNum());
}
// hook up a listener for each
for (int consumerPunc : consumingOperatorsWithPunctuation) {
final EPDataFlowEmitter context = runtimeContexts.get(consumerPunc);
if (context == null) {
continue;
}
dataFlowSignalManager.addSignalListener(producerOpNum, new DataFlowSignalListener() {
public void processSignal(EPDataFlowSignal signal) {
context.submitSignal(signal);
}
});
}
}