throw new EPException("Context for named window is '" + processor.getContextName() + "' and query specifies context '" + statementSpec.getOptionalContextName() + "'");
}
// handle non-specified context
if (statementSpec.getOptionalContextName() == null) {
NamedWindowProcessorInstance processorInstance = processor.getProcessorInstanceNoContext();
if (processorInstance != null) {
EventBean[] rows = executor.execute(processorInstance);
if (rows.length > 0) {
dispatch();
}
return new EPPreparedQueryResult(processor.getNamedWindowType(), rows);
}
}
// context partition runtime query
Collection<Integer> agentInstanceIds = EPPreparedExecuteMethodHelper.getAgentInstanceIds(processor, optionalSingleSelector, services.getContextManagementService(), processor.getContextName());
// collect events and agent instances
if (agentInstanceIds.isEmpty()) {
return new EPPreparedQueryResult(processor.getNamedWindowType(), CollectionUtil.EVENT_PER_STREAM_EMPTY);
}
if (agentInstanceIds.size() == 1) {
int agentInstanceId = agentInstanceIds.iterator().next();
NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceId);
EventBean[] rows = executor.execute(processorInstance);
if (rows.length > 0) {
dispatch();
}
return new EPPreparedQueryResult(processor.getNamedWindowType(), rows);
}
ArrayDeque<EventBean> allRows = new ArrayDeque<EventBean>();
for (int agentInstanceId : agentInstanceIds) {
NamedWindowProcessorInstance processorInstance = processor.getProcessorInstance(agentInstanceId);
if (processorInstance != null) {
EventBean[] rows = executor.execute(processorInstance);
allRows.addAll(Arrays.asList(rows));
}
}