public EPServiceProviderIsolated GetIsolationUnit(string name, int?optionalUnitId)
        {
            var serviceProviderIsolated = _isolatedProviders.Get(name);

            if (serviceProviderIsolated != null)
            {
                return(serviceProviderIsolated);
            }

            FilterServiceSPI filterService = FilterServiceProvider.NewService(
                _epServicesContext.LockManager,
                _epServicesContext.RWLockManager,
                _epServicesContext.ConfigSnapshot.EngineDefaults.Execution.FilterServiceProfile,
                true);

            var scheduleService = new SchedulingServiceImpl(
                _epServicesContext.TimeSource,
                _epServicesContext.LockManager);
            var services = new EPIsolationUnitServices(name, currentUnitId, filterService, scheduleService);

            serviceProviderIsolated = new EPServiceProviderIsolatedImpl(
                name, services, _epServicesContext, _isolatedProviders);
            _isolatedProviders.Put(name, serviceProviderIsolated);
            return(serviceProviderIsolated);
        }
 /// <summary>Ctor. </summary>
 /// <param name="isolatedServiceName">name of the isolated service</param>
 /// <param name="services">isolated services</param>
 /// <param name="unisolatedServices">engine services</param>
 /// <param name="isolatedRuntime">the runtime for this isolated service</param>
 public EPAdministratorIsolatedImpl(string isolatedServiceName, EPIsolationUnitServices services, EPServicesContext unisolatedServices, EPRuntimeIsolatedSPI isolatedRuntime)
 {
     _isolatedServiceName = isolatedServiceName;
     _services            = services;
     _unisolatedServices  = unisolatedServices;
     _isolatedRuntime     = isolatedRuntime;
 }
示例#3
0
        /// <summary>Ctor. </summary>
        /// <param name="svc">isolated services</param>
        /// <param name="unisolatedSvc">engine services</param>
        public EPRuntimeIsolatedImpl(EPIsolationUnitServices svc, EPServicesContext unisolatedSvc)
        {
            _services           = svc;
            _unisolatedServices = unisolatedSvc;
            _threadWorkQueue    = new ThreadWorkQueue();

            _isSubselectPreeval           = unisolatedSvc.EngineSettingsService.EngineSettings.Expression.IsSelfSubselectPreeval;
            _isPrioritized                = unisolatedSvc.EngineSettingsService.EngineSettings.Execution.IsPrioritized;
            _isLatchStatementInsertStream = unisolatedSvc.EngineSettingsService.EngineSettings.Threading.IsInsertIntoDispatchPreserveOrder;

            _threadLocalData = ThreadLocalManager.Create(CreateLocalData);
        }
        /// <summary>Ctor. </summary>
        /// <param name="name">name of isolated service</param>
        /// <param name="isolatedServices">filter and scheduling service isolated</param>
        /// <param name="unisolatedSvc">engine services</param>
        /// <param name="providers">names and isolated service providers</param>
        public EPServiceProviderIsolatedImpl(String name,
                                             EPIsolationUnitServices isolatedServices,
                                             EPServicesContext unisolatedSvc,
                                             IDictionary <String, EPServiceProviderIsolatedImpl> providers)
        {
            _name             = name;
            _providers        = providers;
            _isolatedServices = isolatedServices;

            _runtime = new EPRuntimeIsolatedImpl(isolatedServices, unisolatedSvc);
            _admin   = new EPAdministratorIsolatedImpl(name, isolatedServices, unisolatedSvc, _runtime);
        }
示例#5
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));
        }
示例#6
0
 /// <summary>
 /// Dispose for destroying an engine instance: sets references to null and clears thread-locals
 /// </summary>
 public void Dispose()
 {
     _services        = null;
     _threadLocalData = null;
 }
示例#7
0
 public void NewStatement(int stmtId, string stmtName, EPIsolationUnitServices isolatedServices)
 {
     Log.Info("New statement '" + stmtName + "' unit " + isolatedServices.Name);
 }