}
public StatementAgentInstanceFactoryCreateWindowResult newContext(final AgentInstanceContext agentInstanceContext)
{
final List<StopCallback> stopCallbacks = new ArrayList<StopCallback>();
StopCallback stopCallback = new StopCallback() {
public void stop() {
StatementAgentInstanceUtil.stopSafe(agentInstanceContext.getTerminationCallbacks(), stopCallbacks, statementContext);
}
};
String windowName = statementSpec.getCreateWindowDesc().getWindowName();
Viewable finalView;
try {
// Register interest
ViewableActivationResult activationResult = activator.activate(agentInstanceContext, false);
stopCallbacks.add(activationResult.getStopCallback());
Viewable eventStreamParentViewable = activationResult.getViewable();
// Obtain processor for this named window
NamedWindowProcessor processor = services.getNamedWindowService().getProcessor(windowName);
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);