// Materialize views
Viewable finalView = services.getViewService().createViews(rootView, unmaterializedViewChain.getViewFactoryChain(), statementContext);
// 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
EPStatementStopMethod stopMethod = new EPStatementStopMethod()
{
public void stop()
{
statementContext.getStatementStopService().fireStatementStopped();
boolean filterSubselectSameStream = determineSubquerySameStream(filterStreamSpec);
services.getStreamService().dropStream(filterStreamSpec.getFilterSpec(), statementContext.getFilterService(), false,false, true, filterSubselectSameStream);
String windowName = statementSpec.getCreateWindowDesc().getWindowName();
try {
NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(windowName);
if (processor.isVirtualDataWindow()) {
processor.getVirtualDataWindow().handleStopWindow();
}
} catch (ExprValidationException e) {
log.warn("Named window processor by name '" + windowName + "' has not been found");
}
services.getNamedWindowService().removeProcessor(windowName);
if (environmentStopCallback != null) {
environmentStopCallback.stop();
}
}
};
// Attach tail view