final StreamSpecCompiled streamSpec = statementSpec.getStreamSpecs().get(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;
if (contextPartitionSelector == null || contextPartitionSelector instanceof ContextPartitionSelectorAll) {
contextPartitions = namedWindowProcessor.getProcessorInstancesAll();
}
else {
ContextManager contextManager = services.getContextManagementService().getContextManager(namedWindowProcessor.getContextName());
contextPartitions = contextManager.getAgentInstanceIds(contextPartitionSelector);
}
// 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;
}