예제 #1
0
 public EPStatementInitServicesImpl(
     String statementName,
     IDictionary<StatementProperty, Object> statementProperties,
     Attribute[] annotations,
     String deploymentId,
     EventTypeResolver eventTypeResolver,
     FilterSpecActivatableRegistry filterSpecActivatableRegistry,
     FilterSharedBoolExprRegistery filterSharedBoolExprRegistery,
     FilterSharedLookupableRegistery filterSharedLookupableRegistery,
     ModuleIncidentals moduleIncidentals,
     bool recovery,
     StatementResourceService statementResourceService,
     StatementResultService statementResultService,
     EPServicesContext servicesContext)
 {
     StatementName = statementName;
     StatementProperties = statementProperties;
     Annotations = annotations;
     DeploymentId = deploymentId;
     EventTypeResolver = eventTypeResolver;
     FilterSpecActivatableRegistry = filterSpecActivatableRegistry;
     FilterSharedBoolExprRegistery = filterSharedBoolExprRegistery;
     FilterSharedLookupableRegistery = filterSharedLookupableRegistery;
     ModuleIncidentals = moduleIncidentals;
     IsRecovery = recovery;
     StatementResourceService = statementResourceService;
     StatementResultService = statementResultService;
     ServicesContext = servicesContext;
 }
예제 #2
0
 public StatementCPCacheService(
     bool contextPartitioned,
     StatementResourceService statementResourceService,
     StatementAIResourceRegistry statementAgentInstanceRegistry)
 {
     IsContextPartitioned = contextPartitioned;
     StatementResourceService = statementResourceService;
     this.statementAgentInstanceRegistry = statementAgentInstanceRegistry;
 }
예제 #3
0
        public NamedWindowProcessor AddProcessor(
            string name,
            string contextName,
            EventType eventType,
            StatementResultService statementResultService,
            ValueAddEventProcessor revisionProcessor,
            string eplExpression,
            string statementName,
            bool isPrioritized,
            bool isEnableSubqueryIndexShare,
            bool isBatchingDataWindow,
            bool isVirtualDataWindow,
            StatementMetricHandle statementMetricHandle,
            ICollection <string> optionalUniqueKeyProps,
            string eventTypeAsName,
            StatementResourceService statementResourceService)
        {
            if (_processors.ContainsKey(name))
            {
                throw new ViewProcessingException("A named window by name '" + name + "' has already been created");
            }

            var processor = new NamedWindowProcessor(
                name, this, contextName, eventType, statementResultService, revisionProcessor,
                eplExpression, statementName, isPrioritized, isEnableSubqueryIndexShare, _enableQueryPlanLog,
                _metricReportingService, isBatchingDataWindow, isVirtualDataWindow, statementMetricHandle,
                optionalUniqueKeyProps, eventTypeAsName, statementResourceService);

            _processors.Put(name, processor);

            if (!_observers.IsEmpty())
            {
                var theEvent = new NamedWindowLifecycleEvent(name, processor, NamedWindowLifecycleEvent.LifecycleEventType.CREATE);
                foreach (var observer in _observers)
                {
                    observer.Observe(theEvent);
                }
            }

            return(processor);
        }
예제 #4
0
        public void RemoveAllInstanceIndexes(IndexMultiKey index)
        {
            StatementResourceService statementResourceService = _statementContextCreateWindow.StatementExtensionServicesContext.StmtResources;

            if (_contextName == null)
            {
                StatementResourceHolder holder = statementResourceService.Unpartitioned;
                if (holder != null && holder.NamedWindowProcessorInstance != null)
                {
                    holder.NamedWindowProcessorInstance.RemoveIndex(index);
                }
            }
            else
            {
                foreach (var entry in statementResourceService.ResourcesPartitioned)
                {
                    if (entry.Value.NamedWindowProcessorInstance != null)
                    {
                        entry.Value.NamedWindowProcessorInstance.RemoveIndex(index);
                    }
                }
            }
        }
예제 #5
0
        public NamedWindowConsumerView AddConsumer(NamedWindowConsumerDesc consumerDesc, bool isSubselect)
        {
            StatementResourceService statementResourceService = _statementContextCreateWindow.StatementExtensionServicesContext.StmtResources;

            // handle same-context consumer
            if (_contextName != null)
            {
                ContextDescriptor contextDescriptor = consumerDesc.AgentInstanceContext.StatementContext.ContextDescriptor;
                if (contextDescriptor != null && _contextName.Equals(contextDescriptor.ContextName))
                {
                    StatementResourceHolder holder = statementResourceService.GetPartitioned(consumerDesc.AgentInstanceContext.AgentInstanceId);
                    return(holder.NamedWindowProcessorInstance.TailViewInstance.AddConsumer(consumerDesc, isSubselect));
                }
                else
                {
                    // consumer is out-of-context
                    return(_tailView.AddConsumer(consumerDesc));     // non-context consumers
                }
            }

            // handle no context associated
            return(statementResourceService.ResourcesUnpartitioned.NamedWindowProcessorInstance.TailViewInstance.AddConsumer(consumerDesc, isSubselect));
        }
예제 #6
0
        public TableMetadata(string tableName, string eplExpression, string statementName, Type[] keyTypes, IDictionary <String, TableMetadataColumn> tableColumns, TableStateRowFactory rowFactory, int numberMethodAggregations, StatementResourceService createTableResources, string contextName, ObjectArrayEventType internalEventType, ObjectArrayEventType publicEventType, TableMetadataInternalEventToPublic eventToPublic, bool queryPlanLogging, string createTableStatementName)
        {
            _tableName               = tableName;
            _eplExpression           = eplExpression;
            _statementName           = statementName;
            KeyTypes                 = keyTypes;
            TableColumns             = tableColumns;
            RowFactory               = rowFactory;
            NumberMethodAggregations = numberMethodAggregations;
            _createTableResources    = createTableResources;
            ContextName              = contextName;
            InternalEventType        = internalEventType;
            _publicEventType         = publicEventType;
            _eventToPublic           = eventToPublic;
            _queryPlanLogging        = queryPlanLogging;

            if (keyTypes.Length > 0)
            {
                var pair = TableServiceUtil.GetIndexMultikeyForKeys(tableColumns, internalEventType);
                _eventTableIndexMetadataRepo.AddIndex(true, pair.Second, tableName, createTableStatementName, true);
                _tableRowKeyFactory = new TableRowKeyFactory(pair.First);
            }
        }
예제 #7
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="namedWindowName">Name of the named window.</param>
        /// <param name="namedWindowService">service for dispatching results</param>
        /// <param name="contextName">Name of the context.</param>
        /// <param name="singleInstanceContext">if set to <c>true</c> [single instance context].</param>
        /// <param name="eventType">the type of event held by the named window</param>
        /// <param name="statementResultService">for coordinating on whether insert and remove stream events should be posted</param>
        /// <param name="revisionProcessor">for revision processing</param>
        /// <param name="eplExpression">epl expression</param>
        /// <param name="statementName">statement name</param>
        /// <param name="isPrioritized">if the engine is running with prioritized execution</param>
        /// <param name="isEnableSubqueryIndexShare">if set to <c>true</c> [is enable subquery index share].</param>
        /// <param name="enableQueryPlanLog">if set to <c>true</c> [enable query plan log].</param>
        /// <param name="metricReportingService">The metric reporting service.</param>
        /// <param name="isBatchingDataWindow">if set to <c>true</c> [is batching data window].</param>
        /// <param name="isVirtualDataWindow">if set to <c>true</c> [is virtual data window].</param>
        /// <param name="statementMetricHandle">The statement metric handle.</param>
        /// <param name="optionalUniqueKeyProps">The optional unique key props.</param>
        /// <param name="eventTypeAsName">Name of the event type as.</param>
        public NamedWindowProcessor(
            string namedWindowName,
            NamedWindowService namedWindowService,
            string contextName,
            EventType eventType,
            StatementResultService statementResultService,
            ValueAddEventProcessor revisionProcessor,
            string eplExpression,
            string statementName,
            bool isPrioritized,
            bool isEnableSubqueryIndexShare,
            bool enableQueryPlanLog,
            MetricReportingService metricReportingService,
            bool isBatchingDataWindow,
            bool isVirtualDataWindow,
            StatementMetricHandle statementMetricHandle,
            ICollection <string> optionalUniqueKeyProps,
            string eventTypeAsName,
            StatementResourceService statementResourceService)
        {
            _namedWindowName            = namedWindowName;
            _contextName                = contextName;
            _eventType                  = eventType;
            _eplExpression              = eplExpression;
            _statementName              = statementName;
            _isEnableSubqueryIndexShare = isEnableSubqueryIndexShare;
            _isVirtualDataWindow        = isVirtualDataWindow;
            _statementMetricHandle      = statementMetricHandle;
            _optionalUniqueKeyProps     = optionalUniqueKeyProps;
            _eventTypeAsName            = eventTypeAsName;
            _statementResourceService   = statementResourceService;
            _lock = LockManager.CreateLock(GetType());

            _rootView = new NamedWindowRootView(revisionProcessor, enableQueryPlanLog, metricReportingService, eventType, isBatchingDataWindow, isEnableSubqueryIndexShare, optionalUniqueKeyProps);
            _tailView = new NamedWindowTailView(eventType, namedWindowService, statementResultService, revisionProcessor, isPrioritized, isBatchingDataWindow);
        }
예제 #8
0
        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));
        }
예제 #9
0
        private static StatementLightweight InitStatement(
            bool recovery,
            string moduleName,
            StatementProvider statementProvider,
            string deploymentId,
            int statementId,
            EventTypeResolver eventTypeResolver,
            ModuleIncidentals moduleIncidentals,
            StatementNameRuntimeOption statementNameResolverRuntime,
            StatementUserObjectRuntimeOption userObjectResolverRuntime,
            ClassLoader moduleClassLoader,
            EPServicesContext services)
        {
            var informationals = statementProvider.Informationals;

            // set instrumentation unless already provided
            if (informationals.InstrumentationProvider == null)
            {
                informationals.InstrumentationProvider = InstrumentationDefault.INSTANCE;
            }

            var statementResultService = new StatementResultServiceImpl(informationals, services);
            FilterSharedLookupableRegistery filterSharedLookupableRegistery = new ProxyFilterSharedLookupableRegistery()
            {
                ProcRegisterLookupable = (
                    eventTypeX,
                    lookupable) => {
                    services.FilterSharedLookupableRepository.RegisterLookupable(statementId, eventTypeX, lookupable);
                },
            };

            FilterSharedBoolExprRegistery filterSharedBoolExprRegistery = new ProxyFilterSharedBoolExprRegistery()
            {
                ProcRegisterBoolExpr = (node) => { services.FilterSharedBoolExprRepository.RegisterBoolExpr(statementId, node); },
            };

            IDictionary <int, FilterSpecActivatable> filterSpecActivatables        = new Dictionary <int, FilterSpecActivatable>();
            FilterSpecActivatableRegistry            filterSpecActivatableRegistry = new ProxyFilterSpecActivatableRegistry()
            {
                ProcRegister = (filterSpecActivatable) => { filterSpecActivatables.Put(filterSpecActivatable.FilterCallbackId, filterSpecActivatable); },
            };

            var contextPartitioned       = informationals.OptionalContextName != null;
            var statementResourceService = new StatementResourceService(contextPartitioned);

            // determine statement name
            var statementName = informationals.StatementNameCompileTime;

            if (statementNameResolverRuntime != null)
            {
                string statementNameAssigned = statementNameResolverRuntime.Invoke(
                    new StatementNameRuntimeContext(
                        deploymentId,
                        statementName,
                        statementId,
                        (string)informationals.Properties.Get(StatementProperty.EPL),
                        informationals.Annotations));
                if (statementNameAssigned != null)
                {
                    statementName = statementNameAssigned;
                }
            }

            statementName = statementName.Trim();

            var epInitServices = new EPStatementInitServicesImpl(
                statementName,
                informationals.Properties,
                informationals.Annotations,
                deploymentId,
                eventTypeResolver,
                filterSpecActivatableRegistry,
                filterSharedBoolExprRegistery,
                filterSharedLookupableRegistery,
                moduleIncidentals,
                recovery,
                statementResourceService,
                statementResultService,
                services);

            if (!services.EpServicesHA.RuntimeExtensionServices.IsHAEnabled)
            {
                statementProvider.Initialize(epInitServices);
            }
            else
            {
                // for HA we set the context classloader as state may be loaded considering the module provider's classloader
                // - NEsper doesn't support HA like this, and we wouldn't want to deliver this information in
                // - this manner.  An alternative delivery mechanism must be established to carry the information
                // - without relying on the "current" thread to carry that detail.

                // ClassLoader originalClassLoader = Thread.CurrentThread().ContextClassLoader;
                // try {
                //  Thread.CurrentThread().ContextClassLoader = moduleClassLoader;
                //  statementProvider.Initialize(epInitServices);
                // }
                // finally {
                //  Thread.CurrentThread().ContextClassLoader = originalClassLoader;
                // }
            }

            var multiMatchHandler = services.MultiMatchHandlerFactory.Make(informationals.HasSubquery, informationals.IsNeedDedup);

            var stmtMetric = services.MetricReportingService.GetStatementHandle(statementId, deploymentId, statementName);

            var optionalEPL = (string)informationals.Properties.Get(StatementProperty.EPL);
            InsertIntoLatchFactory insertIntoFrontLatchFactory = null;
            InsertIntoLatchFactory insertIntoBackLatchFactory  = null;

            if (informationals.InsertIntoLatchName != null)
            {
                var latchFactoryNameBack  = "insert_stream_B_" + informationals.InsertIntoLatchName + "_" + statementName;
                var latchFactoryNameFront = "insert_stream_F_" + informationals.InsertIntoLatchName + "_" + statementName;
                var msecTimeout           = services.RuntimeSettingsService.ConfigurationRuntime.Threading.InsertIntoDispatchTimeout;
                var locking           = services.RuntimeSettingsService.ConfigurationRuntime.Threading.InsertIntoDispatchLocking;
                var latchFactoryFront = new InsertIntoLatchFactory(
                    latchFactoryNameFront,
                    informationals.IsStateless,
                    msecTimeout,
                    locking,
                    services.TimeSourceService);
                var latchFactoryBack = new InsertIntoLatchFactory(
                    latchFactoryNameBack,
                    informationals.IsStateless,
                    msecTimeout,
                    locking,
                    services.TimeSourceService);
                insertIntoFrontLatchFactory = latchFactoryFront;
                insertIntoBackLatchFactory  = latchFactoryBack;
            }

            var statementHandle = new EPStatementHandle(
                statementName,
                deploymentId,
                statementId,
                optionalEPL,
                informationals.Priority,
                informationals.IsPreemptive,
                informationals.IsCanSelfJoin,
                multiMatchHandler,
                informationals.HasVariables,
                informationals.HasTableAccess,
                stmtMetric,
                insertIntoFrontLatchFactory,
                insertIntoBackLatchFactory);

            // determine context
            StatementAIResourceRegistry statementAgentInstanceRegistry = null;
            ContextRuntimeDescriptor    contextRuntimeDescriptor       = null;
            var optionalContextName = informationals.OptionalContextName;

            if (optionalContextName != null)
            {
                var contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId(
                    informationals.OptionalContextModuleName,
                    informationals.OptionalContextVisibility,
                    optionalContextName,
                    deploymentId,
                    services.ContextPathRegistry);
                var contextManager = services.ContextManagementService.GetContextManager(contextDeploymentId, optionalContextName);
                contextRuntimeDescriptor = contextManager.ContextRuntimeDescriptor;
                var registryRequirements = statementProvider.StatementAIFactoryProvider.Factory.RegistryRequirements;
                statementAgentInstanceRegistry = contextManager.AllocateAgentInstanceResourceRegistry(registryRequirements);
            }

            var statementCPCacheService = new StatementCPCacheService(
                contextPartitioned,
                statementResourceService,
                statementAgentInstanceRegistry);

            var eventType = statementProvider.StatementAIFactoryProvider.Factory.StatementEventType;

            var configurationThreading = services.RuntimeSettingsService.ConfigurationRuntime.Threading;
            var preserveDispatchOrder  = configurationThreading.IsListenerDispatchPreserveOrder && !informationals.IsStateless;
            var isSpinLocks            = configurationThreading.ListenerDispatchLocking == Locking.SPIN;
            var msecBlockingTimeout    = configurationThreading.ListenerDispatchTimeout;
            UpdateDispatchViewBase dispatchChildView;

            if (preserveDispatchOrder)
            {
                if (isSpinLocks)
                {
                    dispatchChildView = new UpdateDispatchViewBlockingSpin(
                        eventType,
                        statementResultService,
                        services.DispatchService,
                        msecBlockingTimeout,
                        services.TimeSourceService);
                }
                else
                {
                    dispatchChildView = new UpdateDispatchViewBlockingWait(eventType, statementResultService, services.DispatchService, msecBlockingTimeout);
                }
            }
            else
            {
                dispatchChildView = new UpdateDispatchViewNonBlocking(eventType, statementResultService, services.DispatchService);
            }

            var countSubexpressions = services.ConfigSnapshot.Runtime.Patterns.MaxSubexpressions != null;
            PatternSubexpressionPoolStmtSvc patternSubexpressionPoolStmtSvc = null;

            if (countSubexpressions)
            {
                var stmtCounter = new PatternSubexpressionPoolStmtHandler();
                patternSubexpressionPoolStmtSvc = new PatternSubexpressionPoolStmtSvc(services.PatternSubexpressionPoolRuntimeSvc, stmtCounter);
                services.PatternSubexpressionPoolRuntimeSvc.AddPatternContext(statementId, statementName, stmtCounter);
            }

            var countMatchRecogStates = services.ConfigSnapshot.Runtime.MatchRecognize.MaxStates != null;
            RowRecogStatePoolStmtSvc rowRecogStatePoolStmtSvc = null;

            if (countMatchRecogStates && informationals.HasMatchRecognize)
            {
                var stmtCounter = new RowRecogStatePoolStmtHandler();
                rowRecogStatePoolStmtSvc = new RowRecogStatePoolStmtSvc(services.RowRecogStatePoolEngineSvc, stmtCounter);
                services.RowRecogStatePoolEngineSvc.AddPatternContext(new DeploymentIdNamePair(deploymentId, statementName), stmtCounter);
            }

            // get user object for runtime
            object userObjectRuntime = null;

            if (userObjectResolverRuntime != null)
            {
                userObjectRuntime = userObjectResolverRuntime.GetUserObject(
                    new StatementUserObjectRuntimeContext(
                        deploymentId,
                        statementName,
                        statementId,
                        (string)informationals.Properties.Get(StatementProperty.EPL),
                        informationals.Annotations));
            }

            var statementContext = new StatementContext(
                services.Container,
                contextRuntimeDescriptor,
                deploymentId,
                statementId,
                statementName,
                moduleName,
                informationals,
                userObjectRuntime,
                services.StatementContextRuntimeServices,
                statementHandle,
                filterSpecActivatables,
                patternSubexpressionPoolStmtSvc,
                rowRecogStatePoolStmtSvc,
                new ScheduleBucket(statementId),
                statementAgentInstanceRegistry,
                statementCPCacheService,
                statementProvider.StatementAIFactoryProvider,
                statementResultService,
                dispatchChildView,
                services.FilterService,
                services.SchedulingService,
                services.InternalEventRouteDest
                );

            foreach (var readyCallback in epInitServices.ReadyCallbacks)
            {
                readyCallback.Ready(statementContext, moduleIncidentals, recovery);
            }

            return(new StatementLightweight(statementProvider, informationals, statementResultService, statementContext));
        }