if (processor == null) {
throw new RuntimeException("Failed to obtain named window processor for named window '" + windowName + "'");
}
// Allocate processor instance
NamedWindowProcessorInstance processorInstance = processor.addInstance(agentInstanceContext);
View rootView = processorInstance.getRootViewInstance();
eventStreamParentViewable.addView(rootView);
// Materialize views
AgentInstanceViewFactoryChainContext viewFactoryChainContext = new AgentInstanceViewFactoryChainContext(agentInstanceContext, true, null, null);
finalView = services.getViewService().createViews(rootView, unmaterializedViewChain.getViewFactoryChain(), viewFactoryChainContext, false);
// If this is a virtual data window implementation, bind it to the context for easy lookup
StopCallback envStopCallback = null;
if (finalView instanceof VirtualDWView) {
final String objectName = "/virtualdw/" + windowName;
final VirtualDWView virtualDWView = (VirtualDWView) finalView;
try {
services.getEngineEnvContext().bind(objectName, virtualDWView.getVirtualDataWindow());
}
catch (NamingException e) {
throw new ViewProcessingException("Invalid name for adding to context:" + e.getMessage(), e);
}
envStopCallback = new StopCallback() {
public void stop() {
try {
virtualDWView.destroy();
services.getEngineEnvContext().unbind(objectName);
} catch (NamingException e) {}
}
};
}
final StopCallback environmentStopCallback = envStopCallback;
// create stop method using statement stream specs
StopCallback allInOneStopMethod = new StopCallback()
{
public void stop()
{
String windowName = statementSpec.getCreateWindowDesc().getWindowName();
NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(windowName);
if (processor == null) {
log.warn("Named window processor by name '" + windowName + "' has not been found");
}
else {
NamedWindowProcessorInstance instance = processor.getProcessorInstance(agentInstanceContext);
if (instance.getRootViewInstance().isVirtualDataWindow()) {
instance.getRootViewInstance().getVirtualDataWindow().handleStopWindow();
}
processor.removeProcessorInstance(instance);
}
if (environmentStopCallback != null) {
environmentStopCallback.stop();
}
}
};
stopCallbacks.add(allInOneStopMethod);
// Attach tail view
NamedWindowTailViewInstance tailView = processorInstance.getTailViewInstance();
finalView.addView(tailView);
finalView = tailView;
// obtain result set processor
ResultSetProcessor resultSetProcessor = EPStatementStartMethodHelperAssignExpr.getAssignResultSetProcessor(agentInstanceContext, resultSetProcessorPrototype);
// Attach output view
View outputView = outputProcessViewFactory.makeView(resultSetProcessor, agentInstanceContext);
finalView.addView(outputView);
finalView = outputView;
// Handle insert case
if (statementSpec.getCreateWindowDesc().isInsert() && !isRecoveringStatement)
{
String insertFromWindow = statementSpec.getCreateWindowDesc().getInsertFromWindow();
NamedWindowProcessor namedWindowProcessor = services.getNamedWindowService().getProcessor(insertFromWindow);
NamedWindowProcessorInstance sourceWindowInstances = namedWindowProcessor.getProcessorInstance(agentInstanceContext);
List<EventBean> events = new ArrayList<EventBean>();
if (statementSpec.getCreateWindowDesc().getInsertFilter() != null)
{
EventBean[] eventsPerStream = new EventBean[1];
ExprEvaluator filter = statementSpec.getCreateWindowDesc().getInsertFilter().getExprEvaluator();
for (Iterator<EventBean> it = sourceWindowInstances.getTailViewInstance().iterator(); it.hasNext();)
{
EventBean candidate = it.next();
eventsPerStream[0] = candidate;
Boolean result = (Boolean) filter.evaluate(eventsPerStream, true, agentInstanceContext);
if ((result == null) || (!result))
{
continue;
}
events.add(candidate);
}
}
else
{
for (Iterator<EventBean> it = sourceWindowInstances.getTailViewInstance().iterator(); it.hasNext();)
{
events.add(it.next());
}
}
if (events.size() > 0)