// obtain factory for output limiting
OutputProcessViewFactory outputViewFactory = OutputProcessViewFactoryFactory.make(statementSpec, services.getInternalEventRouter(), statementContext, resultSetProcessorPrototype.getResultSetProcessorFactory().getResultEventType(), null);
// create context factory
StatementAgentInstanceFactoryCreateWindow contextFactory = new StatementAgentInstanceFactoryCreateWindow(statementContext, statementSpec, services, activator, unmaterializedViewChain, resultSetProcessorPrototype, outputViewFactory, isRecoveringStatement);
// With context - delegate instantiation to context
final EPStatementStopMethod stopMethod = new EPStatementStopMethodImpl(statementContext, stopCallbacks);
if (statementSpec.getOptionalContextName() != null) {
ContextMergeView mergeView = new ContextMergeView(processor.getNamedWindowType());
finalViewable = mergeView;
ContextManagedStatementCreateWindowDesc statement = new ContextManagedStatementCreateWindowDesc(statementSpec, statementContext, mergeView, contextFactory);
services.getContextManagementService().addStatement(contextName, statement, isRecoveringResilient);
stopStatementMethod = new EPStatementStopMethod(){
public void stop()
{
services.getContextManagementService().stoppedStatement(contextName, statementContext.getStatementName(), statementContext.getStatementId());
stopMethod.stop();
}
};
destroyStatementMethod = new EPStatementDestroyMethod(){
public void destroy() {
services.getContextManagementService().destroyedStatement(contextName, statementContext.getStatementName(), statementContext.getStatementId());
}
};
}
// Without context - start here
else {
AgentInstanceContext agentInstanceContext = getDefaultAgentInstanceContext(statementContext);
final StatementAgentInstanceFactoryCreateWindowResult resultOfStart;
try {
resultOfStart = contextFactory.newContext(agentInstanceContext, false);
}
catch (RuntimeException ex) {
services.getNamedWindowService().removeProcessor(windowName);
throw ex;
}