final StreamSpecCompiled streamSpec = statementSpec.getStreamSpecs()[streamNum];
NamedWindowConsumerStreamSpec namedSpec = (NamedWindowConsumerStreamSpec) streamSpec;
NamedWindowProcessor namedWindowProcessor = processors[streamNum];
// handle the case of a single or matching agent instance
NamedWindowProcessorInstance processorInstance = namedWindowProcessor.getProcessorInstance(agentInstanceContext);
if (processorInstance != null) {
return getStreamSnapshotInstance(streamNum, namedSpec, processorInstance);
}
// context partition runtime query
Collection<Integer> contextPartitions = EPPreparedExecuteMethodHelper.getAgentInstanceIds(namedWindowProcessor, contextPartitionSelector, services.getContextManagementService(), namedWindowProcessor.getContextName());
// collect events
ArrayDeque<EventBean> events = new ArrayDeque<EventBean>();
for (int agentInstanceId : contextPartitions) {
processorInstance = namedWindowProcessor.getProcessorInstance(agentInstanceId);
if (processorInstance != null) {
Collection<EventBean> coll = processorInstance.getTailViewInstance().snapshot(filters[streamNum], statementSpec.getAnnotations());
events.addAll(coll);
}
}
return events;
}