// settable for view-sharing /// <summary> /// Constructor. /// </summary> /// <param name="stmtEngineServices">is the engine services for the statement</param> /// <param name="schedulingService">implementation for schedule registration</param> /// <param name="scheduleBucket">is for ordering scheduled callbacks within the view statements</param> /// <param name="epStatementHandle">is the statements-own handle for use in registering callbacks with services</param> /// <param name="viewResultionService">is a service for resolving view namespace and name to a view factory</param> /// <param name="patternResolutionService">is the service that resolves pattern objects for the statement</param> /// <param name="statementExtensionSvcContext">provide extension points for custom statement resources</param> /// <param name="statementStopService">for registering a callback invoked when a statement is stopped</param> /// <param name="methodResolutionService">is a service for resolving static methods and aggregation functions</param> /// <param name="patternContextFactory">is the pattern-level services and context information factory</param> /// <param name="filterService">is the filtering service</param> /// <param name="statementResultService">handles awareness of listeners/subscriptions for a statement customizing output produced</param> /// <param name="internalEventEngineRouteDest">routing destination</param> /// <param name="annotations">The annotations.</param> /// <param name="statementAgentInstanceRegistry">The statement agent instance registry.</param> /// <param name="defaultAgentInstanceLock">The default agent instance lock.</param> /// <param name="contextDescriptor">The context descriptor.</param> /// <param name="patternSubexpressionPoolSvc">The pattern subexpression pool SVC.</param> /// <param name="matchRecognizeStatePoolStmtSvc">The match recognize state pool statement SVC.</param> /// <param name="statelessSelect">if set to <c>true</c> [stateless select].</param> /// <param name="contextControllerFactoryService">The context controller factory service.</param> /// <param name="defaultAgentInstanceScriptContext">The default agent instance script context.</param> /// <param name="aggregationServiceFactoryService">The aggregation service factory service.</param> /// <param name="scriptingService">The scripting service.</param> /// <param name="writesToTables">if set to <c>true</c> [writes to tables].</param> /// <param name="statementUserObject">The statement user object.</param> /// <param name="statementSemiAnonymousTypeRegistry">The statement semi anonymous type registry.</param> /// <param name="priority">The priority.</param> public StatementContext( StatementContextEngineServices stmtEngineServices, SchedulingService schedulingService, ScheduleBucket scheduleBucket, EPStatementHandle epStatementHandle, ViewResolutionService viewResultionService, PatternObjectResolutionService patternResolutionService, StatementExtensionSvcContext statementExtensionSvcContext, StatementStopService statementStopService, MethodResolutionService methodResolutionService, PatternContextFactory patternContextFactory, FilterService filterService, StatementResultService statementResultService, InternalEventRouteDest internalEventEngineRouteDest, Attribute[] annotations, StatementAIResourceRegistry statementAgentInstanceRegistry, IReaderWriterLock defaultAgentInstanceLock, ContextDescriptor contextDescriptor, PatternSubexpressionPoolStmtSvc patternSubexpressionPoolSvc, MatchRecognizeStatePoolStmtSvc matchRecognizeStatePoolStmtSvc, bool statelessSelect, ContextControllerFactoryService contextControllerFactoryService, AgentInstanceScriptContext defaultAgentInstanceScriptContext, AggregationServiceFactoryService aggregationServiceFactoryService, ScriptingService scriptingService, bool writesToTables, object statementUserObject, StatementSemiAnonymousTypeRegistry statementSemiAnonymousTypeRegistry, int priority) { _stmtEngineServices = stmtEngineServices; SchedulingService = schedulingService; ScheduleBucket = scheduleBucket; EpStatementHandle = epStatementHandle; ViewResolutionService = viewResultionService; PatternResolutionService = patternResolutionService; StatementExtensionServicesContext = statementExtensionSvcContext; StatementStopService = statementStopService; MethodResolutionService = methodResolutionService; PatternContextFactory = patternContextFactory; FilterService = filterService; _statementResultService = statementResultService; InternalEventEngineRouteDest = internalEventEngineRouteDest; ScheduleAdjustmentService = stmtEngineServices.ConfigSnapshot.EngineDefaults.ExecutionConfig.IsAllowIsolatedService ? new ScheduleAdjustmentService() : null; Annotations = annotations; StatementAgentInstanceRegistry = statementAgentInstanceRegistry; DefaultAgentInstanceLock = defaultAgentInstanceLock; ContextDescriptor = contextDescriptor; PatternSubexpressionPoolSvc = patternSubexpressionPoolSvc; MatchRecognizeStatePoolStmtSvc = matchRecognizeStatePoolStmtSvc; IsStatelessSelect = statelessSelect; ContextControllerFactoryService = contextControllerFactoryService; DefaultAgentInstanceScriptContext = defaultAgentInstanceScriptContext; AggregationServiceFactoryService = aggregationServiceFactoryService; ScriptingService = scriptingService; IsWritesToTables = writesToTables; StatementUserObject = statementUserObject; StatementSemiAnonymousTypeRegistry = statementSemiAnonymousTypeRegistry; Priority = priority; }
public StatementContext MakeContext( int statementId, string statementName, string expression, StatementType statementType, EPServicesContext engineServices, IDictionary <string, object> optAdditionalContext, bool isFireAndForget, Attribute[] annotations, EPIsolationUnitServices isolationUnitServices, bool stateless, StatementSpecRaw statementSpecRaw, IList <ExprSubselectNode> subselectNodes, bool writesToTables, object statementUserObject) { // Allocate the statement's schedule bucket which stays constant over it's lifetime. // The bucket allows callbacks for the same time to be ordered (within and across statements) and thus deterministic. var scheduleBucket = engineServices.SchedulingMgmtService.AllocateBucket(); // Create a lock for the statement IReaderWriterLock defaultStatementAgentInstanceLock; // For on-delete statements, use the create-named-window statement lock var optCreateWindowDesc = statementSpecRaw.CreateWindowDesc; var optOnTriggerDesc = statementSpecRaw.OnTriggerDesc; if ((optOnTriggerDesc != null) && (optOnTriggerDesc is OnTriggerWindowDesc)) { var windowName = ((OnTriggerWindowDesc)optOnTriggerDesc).WindowName; if (engineServices.TableService.GetTableMetadata(windowName) == null) { defaultStatementAgentInstanceLock = engineServices.NamedWindowMgmtService.GetNamedWindowLock(windowName); if (defaultStatementAgentInstanceLock == null) { throw new EPStatementException("Named window or table '" + windowName + "' has not been declared", expression); } } else { defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock(statementName, annotations, stateless); } } // For creating a named window, save the lock for use with on-delete/on-merge/on-Update etc. statements else if (optCreateWindowDesc != null) { defaultStatementAgentInstanceLock = engineServices.NamedWindowMgmtService.GetNamedWindowLock(optCreateWindowDesc.WindowName); if (defaultStatementAgentInstanceLock == null) { defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock( statementName, annotations, false); engineServices.NamedWindowMgmtService.AddNamedWindowLock( optCreateWindowDesc.WindowName, defaultStatementAgentInstanceLock, statementName); } } else { defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock( statementName, annotations, stateless); } StatementMetricHandle stmtMetric = null; if (!isFireAndForget) { stmtMetric = engineServices.MetricsReportingService.GetStatementHandle(statementId, statementName); } var annotationData = AnnotationAnalysisResult.AnalyzeAnnotations(annotations); var hasVariables = statementSpecRaw.HasVariables || (statementSpecRaw.CreateContextDesc != null); var hasTableAccess = StatementContextFactoryUtil.DetermineHasTableAccess(subselectNodes, statementSpecRaw, engineServices); var epStatementHandle = new EPStatementHandle( statementId, statementName, expression, statementType, expression, hasVariables, stmtMetric, annotationData.Priority, annotationData.IsPremptive, hasTableAccess, engineServices.MultiMatchHandlerFactory.GetDefaultHandler()); var patternContextFactory = new PatternContextFactoryDefault(); var optionalCreateNamedWindowName = statementSpecRaw.CreateWindowDesc != null ? statementSpecRaw.CreateWindowDesc.WindowName : null; var viewResolutionService = new ViewResolutionServiceImpl( _viewRegistry, optionalCreateNamedWindowName, _systemVirtualDwViewFactory); var patternResolutionService = new PatternObjectResolutionServiceImpl(_patternObjectClasses); var schedulingService = engineServices.SchedulingService; var filterService = engineServices.FilterService; if (isolationUnitServices != null) { filterService = isolationUnitServices.FilterService; schedulingService = isolationUnitServices.SchedulingService; } var scheduleAudit = AuditEnum.SCHEDULE.GetAudit(annotations); if (scheduleAudit != null) { schedulingService = new SchedulingServiceAudit( engineServices.EngineURI, statementName, schedulingService); } StatementAIResourceRegistry statementAgentInstanceRegistry = null; ContextDescriptor contextDescriptor = null; var optionalContextName = statementSpecRaw.OptionalContextName; if (optionalContextName != null) { contextDescriptor = engineServices.ContextManagementService.GetContextDescriptor(optionalContextName); // allocate a per-instance registry of aggregations and prev/prior/subselect if (contextDescriptor != null) { statementAgentInstanceRegistry = contextDescriptor.AiResourceRegistryFactory.Invoke(); } } var countSubexpressions = engineServices.ConfigSnapshot.EngineDefaults.PatternsConfig.MaxSubexpressions != null; PatternSubexpressionPoolStmtSvc patternSubexpressionPoolStmtSvc = null; if (countSubexpressions) { var stmtCounter = new PatternSubexpressionPoolStmtHandler(); patternSubexpressionPoolStmtSvc = new PatternSubexpressionPoolStmtSvc(engineServices.PatternSubexpressionPoolSvc, stmtCounter); engineServices.PatternSubexpressionPoolSvc.AddPatternContext(statementName, stmtCounter); } var countMatchRecogStates = engineServices.ConfigSnapshot.EngineDefaults.MatchRecognizeConfig.MaxStates != null; MatchRecognizeStatePoolStmtSvc matchRecognizeStatePoolStmtSvc = null; if (countMatchRecogStates && statementSpecRaw.MatchRecognizeSpec != null) { var stmtCounter = new MatchRecognizeStatePoolStmtHandler(); matchRecognizeStatePoolStmtSvc = new MatchRecognizeStatePoolStmtSvc(engineServices.MatchRecognizeStatePoolEngineSvc, stmtCounter); engineServices.MatchRecognizeStatePoolEngineSvc.AddPatternContext(statementName, stmtCounter); } AgentInstanceScriptContext defaultAgentInstanceScriptContext = null; if (statementSpecRaw.ScriptExpressions != null && !statementSpecRaw.ScriptExpressions.IsEmpty()) { defaultAgentInstanceScriptContext = new AgentInstanceScriptContext(); } // allow a special context controller factory for testing var contextControllerFactoryService = GetContextControllerFactoryService(annotations); // may use resource tracking var statementResourceService = new StatementResourceService(optionalContextName != null); StatementExtensionSvcContext extensionSvcContext = new ProxyStatementExtensionSvcContext { ProcStmtResources = () => statementResourceService, ProcExtractStatementResourceHolder = resultOfStart => StatementResourceHolderUtil.PopulateHolder(resultOfStart) }; // Create statement context return(new StatementContext( _stmtEngineServices, schedulingService, scheduleBucket, epStatementHandle, viewResolutionService, patternResolutionService, extensionSvcContext, new StatementStopServiceImpl(), patternContextFactory, filterService, new StatementResultServiceImpl( statementName, engineServices.StatementLifecycleSvc, engineServices.MetricsReportingService, engineServices.ThreadingService), engineServices.InternalEventEngineRouteDest, annotations, statementAgentInstanceRegistry, defaultStatementAgentInstanceLock, contextDescriptor, patternSubexpressionPoolStmtSvc, matchRecognizeStatePoolStmtSvc, stateless, contextControllerFactoryService, defaultAgentInstanceScriptContext, AggregationServiceFactoryServiceImpl.DEFAULT_FACTORY, engineServices.ScriptingService, writesToTables, statementUserObject, StatementSemiAnonymousTypeRegistryImpl.INSTANCE, annotationData.Priority)); }