コード例 #1
0
        public EPServicesContext CreateServicesContext(
            IContainer container,
            EPServiceProvider epServiceProvider,
            ConfigurationInformation configSnapshot)
        {
            var lockManager        = container.LockManager();
            var rwLockManager      = container.RWLockManager();
            var threadLocalManager = container.ThreadLocalManager();
            var resourceManager    = container.ResourceManager();

            // Directory for binding resources
            var resourceDirectory = container.Resolve <Directory>();

            // Engine import service
            var engineImportService = MakeEngineImportService(
                container.Resolve <ClassLoaderProvider>(),
                configSnapshot,
                AggregationFactoryFactoryDefault.INSTANCE,
                epServiceProvider.URI);

            // Event Type Id Generation
            EventTypeIdGenerator eventTypeIdGenerator;

            if (configSnapshot.EngineDefaults.AlternativeContext == null ||
                configSnapshot.EngineDefaults.AlternativeContext.EventTypeIdGeneratorFactory == null)
            {
                eventTypeIdGenerator = new EventTypeIdGeneratorImpl();
            }
            else
            {
                var eventTypeIdGeneratorFactory = TypeHelper.Instantiate <EventTypeIdGeneratorFactory>(
                    configSnapshot.EngineDefaults.AlternativeContext.EventTypeIdGeneratorFactory,
                    engineImportService.GetClassForNameProvider());
                eventTypeIdGenerator = eventTypeIdGeneratorFactory.Create(
                    new EventTypeIdGeneratorContext(epServiceProvider.URI));
            }

            // Make services that depend on snapshot config entries
            EventAdapterAvroHandler avroHandler = EventAdapterAvroHandlerUnsupported.INSTANCE;

            if (configSnapshot.EngineDefaults.EventMeta.AvroSettings.IsEnableAvro)
            {
                try
                {
                    avroHandler = TypeHelper.Instantiate <EventAdapterAvroHandler>(
                        EventAdapterAvroHandlerConstants.HANDLER_IMPL, engineImportService.GetClassForNameProvider());
                }
                catch (Exception e)
                {
                    Log.Debug(
                        "Avro provider {0} not instantiated, not enabling Avro support: {1}",
                        EventAdapterAvroHandlerConstants.HANDLER_IMPL, e.Message);
                }
                try
                {
                    avroHandler.Init(configSnapshot.EngineDefaults.EventMeta.AvroSettings, engineImportService);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Failed to initialize Esper-Avro: " + e.Message, e);
                }
            }

            var eventAdapterService = new EventAdapterServiceImpl(
                container,
                eventTypeIdGenerator,
                configSnapshot.EngineDefaults.EventMeta.AnonymousCacheSize,
                avroHandler,
                engineImportService);

            Init(eventAdapterService, configSnapshot, engineImportService, resourceManager);

            // New read-write lock for concurrent event processing
            var eventProcessingRwLock = rwLockManager.CreateLock(GetType());

            var timeSourceService     = MakeTimeSource(configSnapshot);
            var schedulingService     = SchedulingServiceProvider.NewService(timeSourceService, lockManager);
            var schedulingMgmtService = new SchedulingMgmtServiceImpl();
            var engineSettingsService = new EngineSettingsService(
                configSnapshot.EngineDefaults, configSnapshot.PlugInEventTypeResolutionURIs);
            var databaseConfigService = MakeDatabaseRefService(
                configSnapshot, schedulingService, schedulingMgmtService, engineImportService);

            var plugInViews = new PluggableObjectCollection();

            plugInViews.AddViews(
                configSnapshot.PlugInViews, configSnapshot.PlugInVirtualDataWindows, engineImportService);
            var plugInPatternObj = new PluggableObjectCollection();

            plugInPatternObj.AddPatternObjects(configSnapshot.PlugInPatternObjects, engineImportService);

            // exception handling
            var exceptionHandlingService = InitExceptionHandling(
                epServiceProvider.URI, configSnapshot.EngineDefaults.ExceptionHandling,
                configSnapshot.EngineDefaults.ConditionHandling, engineImportService);

            // Statement context factory
            Type systemVirtualDWViewFactory = null;

            if (configSnapshot.EngineDefaults.AlternativeContext.VirtualDataWindowViewFactory != null)
            {
                try
                {
                    systemVirtualDWViewFactory =
                        engineImportService.GetClassForNameProvider()
                        .ClassForName(configSnapshot.EngineDefaults.AlternativeContext.VirtualDataWindowViewFactory);
                    if (!TypeHelper.IsImplementsInterface(systemVirtualDWViewFactory, typeof(VirtualDataWindowFactory)))
                    {
                        throw new ConfigurationException(
                                  "Type " + systemVirtualDWViewFactory.Name + " does not implement the interface " +
                                  typeof(VirtualDataWindowFactory).Name);
                    }
                }
                catch (TypeLoadException)
                {
                    throw new ConfigurationException("Failed to look up class " + systemVirtualDWViewFactory);
                }
            }
            var statementContextFactory = new StatementContextFactoryDefault(
                plugInViews, plugInPatternObj, systemVirtualDWViewFactory);

            var msecTimerResolution = configSnapshot.EngineDefaults.Threading.InternalTimerMsecResolution;

            if (msecTimerResolution <= 0)
            {
                throw new ConfigurationException(
                          "Timer resolution configuration not set to a valid value, expecting a non-zero value");
            }
            var timerService = new TimerServiceImpl(epServiceProvider.URI, msecTimerResolution);

            var variableService = new VariableServiceImpl(
                container,
                configSnapshot.EngineDefaults.Variables.MsecVersionRelease,
                schedulingService,
                eventAdapterService,
                null);

            InitVariables(variableService, configSnapshot.Variables, engineImportService);

            var tableService = new TableServiceImpl(container);

            var statementLockFactory = new StatementLockFactoryImpl(
                rwLockManager,
                configSnapshot.EngineDefaults.Execution.IsFairlock,
                configSnapshot.EngineDefaults.Execution.IsDisableLocking
                );

            var streamFactoryService = StreamFactoryServiceProvider.NewService(
                epServiceProvider.URI, configSnapshot.EngineDefaults.ViewResources.IsShareViews);
            var filterService = FilterServiceProvider.NewService(
                lockManager,
                rwLockManager,
                configSnapshot.EngineDefaults.Execution.FilterServiceProfile,
                configSnapshot.EngineDefaults.Execution.IsAllowIsolatedService);
            var metricsReporting = new MetricReportingServiceImpl(
                configSnapshot.EngineDefaults.MetricsReporting,
                epServiceProvider.URI,
                rwLockManager);
            var namedWindowMgmtService = new NamedWindowMgmtServiceImpl(
                configSnapshot.EngineDefaults.Logging.IsEnableQueryPlan,
                metricsReporting);
            var namedWindowDispatchService = new NamedWindowDispatchServiceImpl(
                schedulingService, variableService, tableService,
                engineSettingsService.EngineSettings.Execution.IsPrioritized, eventProcessingRwLock,
                exceptionHandlingService, metricsReporting, threadLocalManager);

            var valueAddEventService = new ValueAddEventServiceImpl(lockManager);

            valueAddEventService.Init(
                configSnapshot.RevisionEventTypes, configSnapshot.VariantStreams, eventAdapterService,
                eventTypeIdGenerator);

            var statementEventTypeRef = new StatementEventTypeRefImpl(rwLockManager);
            var statementVariableRef  = new StatementVariableRefImpl(
                variableService, tableService, namedWindowMgmtService, rwLockManager);

            var threadingService = new ThreadingServiceImpl(configSnapshot.EngineDefaults.Threading);

            var internalEventRouterImpl = new InternalEventRouterImpl(epServiceProvider.URI);

            var statementIsolationService = new StatementIsolationServiceImpl();

            var deploymentStateService = new DeploymentStateServiceImpl(lockManager);

            StatementMetadataFactory stmtMetadataFactory;

            if (configSnapshot.EngineDefaults.AlternativeContext.StatementMetadataFactory == null)
            {
                stmtMetadataFactory = new StatementMetadataFactoryDefault();
            }
            else
            {
                stmtMetadataFactory = TypeHelper.Instantiate <StatementMetadataFactory>(
                    configSnapshot.EngineDefaults.AlternativeContext.StatementMetadataFactory,
                    engineImportService.GetClassForNameProvider());
            }

            var contextManagementService = new ContextManagementServiceImpl();

            PatternSubexpressionPoolEngineSvc patternSubexpressionPoolSvc = null;

            if (configSnapshot.EngineDefaults.Patterns.MaxSubexpressions != null)
            {
                patternSubexpressionPoolSvc =
                    new PatternSubexpressionPoolEngineSvc(
                        configSnapshot.EngineDefaults.Patterns.MaxSubexpressions.Value,
                        configSnapshot.EngineDefaults.Patterns.IsMaxSubexpressionPreventStart);
            }

            MatchRecognizeStatePoolEngineSvc matchRecognizeStatePoolEngineSvc = null;

            if (configSnapshot.EngineDefaults.MatchRecognize.MaxStates != null)
            {
                matchRecognizeStatePoolEngineSvc =
                    new MatchRecognizeStatePoolEngineSvc(
                        configSnapshot.EngineDefaults.MatchRecognize.MaxStates.Value,
                        configSnapshot.EngineDefaults.MatchRecognize.IsMaxStatesPreventStart);
            }

            var scriptingService = new ScriptingServiceImpl();

            scriptingService.DiscoverEngines();

            // New services context

            var services = new EPServicesContext(
                container, epServiceProvider.URI,
                schedulingService,
                eventAdapterService,
                engineImportService,
                engineSettingsService,
                databaseConfigService,
                plugInViews,
                statementLockFactory,
                eventProcessingRwLock,
                null,
                resourceDirectory,
                statementContextFactory,
                plugInPatternObj,
                timerService,
                filterService,
                streamFactoryService,
                namedWindowMgmtService,
                namedWindowDispatchService,
                variableService,
                tableService,
                timeSourceService,
                valueAddEventService,
                metricsReporting,
                statementEventTypeRef,
                statementVariableRef,
                configSnapshot,
                threadingService,
                internalEventRouterImpl,
                statementIsolationService,
                schedulingMgmtService,
                deploymentStateService,
                exceptionHandlingService,
                new PatternNodeFactoryImpl(),
                eventTypeIdGenerator,
                stmtMetadataFactory,
                contextManagementService,
                patternSubexpressionPoolSvc,
                matchRecognizeStatePoolEngineSvc,
                new DataFlowServiceImpl(epServiceProvider, new DataFlowConfigurationStateServiceImpl(), lockManager),
                new ExprDeclaredServiceImpl(lockManager),
                new ContextControllerFactoryFactorySvcImpl(),
                new ContextManagerFactoryServiceImpl(),
                new EPStatementFactoryDefault(),
                new RegexHandlerFactoryDefault(container),
                new ViewableActivatorFactoryDefault(),
                new FilterNonPropertyRegisteryServiceImpl(),
                new ResultSetProcessorHelperFactoryImpl(),
                new ViewServicePreviousFactoryImpl(),
                new EventTableIndexServiceImpl(),
                new EPRuntimeIsolatedFactoryImpl(),
                new FilterBooleanExpressionFactoryImpl(),
                new DataCacheFactory(),
                new MultiMatchHandlerFactoryImpl(),
                NamedWindowConsumerMgmtServiceImpl.INSTANCE,
                AggregationFactoryFactoryDefault.INSTANCE,
                scriptingService
                );

            // Engine services subset available to statements
            statementContextFactory.StmtEngineServices = services;

            // Circular dependency
            var statementLifecycleSvc = new StatementLifecycleSvcImpl(epServiceProvider, services);

            services.StatementLifecycleSvc = statementLifecycleSvc;

            // Observers to statement events
            statementLifecycleSvc.LifecycleEvent += (s, theEvent) => metricsReporting.Observe(theEvent);

            // Circular dependency
            statementIsolationService.SetEpServicesContext(services);

            return(services);
        }
コード例 #2
0
        public EPServicesContext CreateServicesContext(EPServiceProvider epServiceProvider, ConfigurationInformation configSnapshot)
        {
            // Directory for binding resources
            var resourceDirectory = new SimpleServiceDirectory();

            EventTypeIdGenerator eventTypeIdGenerator;

            if (configSnapshot.EngineDefaults.AlternativeContextConfig == null || configSnapshot.EngineDefaults.AlternativeContextConfig.EventTypeIdGeneratorFactory == null)
            {
                eventTypeIdGenerator = new EventTypeIdGeneratorImpl();
            }
            else
            {
                var eventTypeIdGeneratorFactory = TypeHelper.Instantiate <EventTypeIdGeneratorFactory>(
                    configSnapshot.EngineDefaults.AlternativeContextConfig.EventTypeIdGeneratorFactory);
                eventTypeIdGenerator = eventTypeIdGeneratorFactory.Create(new EventTypeIdGeneratorContext(epServiceProvider.URI));
            }

            // Make services that depend on snapshot config entries
            var eventAdapterService = new EventAdapterServiceImpl(eventTypeIdGenerator, configSnapshot.EngineDefaults.EventMetaConfig.AnonymousCacheSize);

            Init(eventAdapterService, configSnapshot);

            // New read-write lock for concurrent event processing
            var eventProcessingRwLock = ReaderWriterLockManager.CreateLock(
                MethodBase.GetCurrentMethod().DeclaringType);

            var timeSourceService     = MakeTimeSource(configSnapshot);
            var schedulingService     = SchedulingServiceProvider.NewService(timeSourceService);
            var schedulingMgmtService = new SchedulingMgmtServiceImpl();
            var engineImportService   = MakeEngineImportService(configSnapshot);
            var engineSettingsService = new EngineSettingsService(configSnapshot.EngineDefaults, configSnapshot.PlugInEventTypeResolutionURIs);
            var databaseConfigService = MakeDatabaseRefService(configSnapshot, schedulingService, schedulingMgmtService);

            var plugInViews = new PluggableObjectCollection();

            plugInViews.AddViews(configSnapshot.PlugInViews, configSnapshot.PlugInVirtualDataWindows);
            var plugInPatternObj = new PluggableObjectCollection();

            plugInPatternObj.AddPatternObjects(configSnapshot.PlugInPatternObjects);

            // exception handling
            ExceptionHandlingService exceptionHandlingService = InitExceptionHandling(
                epServiceProvider.URI,
                configSnapshot.EngineDefaults.ExceptionHandlingConfig,
                configSnapshot.EngineDefaults.ConditionHandlingConfig);

            // Statement context factory
            Type systemVirtualDWViewFactory = null;

            if (configSnapshot.EngineDefaults.AlternativeContextConfig.VirtualDataWindowViewFactory != null)
            {
                try {
                    systemVirtualDWViewFactory = TypeHelper.ResolveType(configSnapshot.EngineDefaults.AlternativeContextConfig.VirtualDataWindowViewFactory);
                    if (!systemVirtualDWViewFactory.IsImplementsInterface(typeof(VirtualDataWindowFactory)))
                    {
                        throw new ConfigurationException("Class " + systemVirtualDWViewFactory.Name + " does not implement the interface " + typeof(VirtualDataWindowFactory).FullName);
                    }
                }
                catch (TypeLoadException e) {
                    throw new ConfigurationException("Failed to look up class " + systemVirtualDWViewFactory);
                }
            }
            StatementContextFactory statementContextFactory = new StatementContextFactoryDefault(plugInViews, plugInPatternObj, systemVirtualDWViewFactory);

            long msecTimerResolution = configSnapshot.EngineDefaults.ThreadingConfig.InternalTimerMsecResolution;

            if (msecTimerResolution <= 0)
            {
                throw new ConfigurationException("Timer resolution configuration not set to a valid value, expecting a non-zero value");
            }
            var timerService = new TimerServiceImpl(epServiceProvider.URI, msecTimerResolution);

            var variableService = new VariableServiceImpl(configSnapshot.EngineDefaults.VariablesConfig.MsecVersionRelease, schedulingService, eventAdapterService, null);

            InitVariables(variableService, configSnapshot.Variables, engineImportService);

            var tableService = new TableServiceImpl();

            var statementLockFactory = new StatementLockFactoryImpl(configSnapshot.EngineDefaults.ExecutionConfig.IsFairlock, configSnapshot.EngineDefaults.ExecutionConfig.IsDisableLocking);
            var streamFactoryService = StreamFactoryServiceProvider.NewService(
                epServiceProvider.URI,
                configSnapshot.EngineDefaults.ViewResourcesConfig.IsShareViews);

            var filterService = FilterServiceProvider.NewService(
                configSnapshot.EngineDefaults.ExecutionConfig.FilterServiceProfile,
                configSnapshot.EngineDefaults.ExecutionConfig.IsAllowIsolatedService);

            var metricsReporting   = new MetricReportingServiceImpl(configSnapshot.EngineDefaults.MetricsReportingConfig, epServiceProvider.URI);
            var namedWindowService = new NamedWindowServiceImpl(
                schedulingService,
                variableService,
                tableService,
                engineSettingsService.EngineSettings.ExecutionConfig.IsPrioritized,
                eventProcessingRwLock,
                exceptionHandlingService,
                configSnapshot.EngineDefaults.LoggingConfig.IsEnableQueryPlan,
                metricsReporting);

            var valueAddEventService = new ValueAddEventServiceImpl();

            valueAddEventService.Init(configSnapshot.RevisionEventTypes, configSnapshot.VariantStreams, eventAdapterService, eventTypeIdGenerator);

            var statementEventTypeRef = new StatementEventTypeRefImpl();
            var statementVariableRef  = new StatementVariableRefImpl(variableService, tableService);

            var threadingService = new ThreadingServiceImpl(
                configSnapshot.EngineDefaults.ThreadingConfig);

            var internalEventRouterImpl = new InternalEventRouterImpl();

            var statementIsolationService = new StatementIsolationServiceImpl();

            DeploymentStateService deploymentStateService = new DeploymentStateServiceImpl();

            StatementMetadataFactory stmtMetadataFactory;

            if (configSnapshot.EngineDefaults.AlternativeContextConfig.StatementMetadataFactory == null)
            {
                stmtMetadataFactory = new StatementMetadataFactoryDefault();
            }
            else
            {
                stmtMetadataFactory = TypeHelper.Instantiate <StatementMetadataFactory>(configSnapshot.EngineDefaults.AlternativeContextConfig.StatementMetadataFactory);
            }

            ContextManagementService contextManagementService = new ContextManagementServiceImpl();

            SchedulableAgentInstanceDirectory schedulableAgentInstanceDirectory = null;     // not required for Non-HA.

            PatternSubexpressionPoolEngineSvc patternSubexpressionPoolSvc = null;

            if (configSnapshot.EngineDefaults.PatternsConfig.MaxSubexpressions != null)
            {
                patternSubexpressionPoolSvc = new PatternSubexpressionPoolEngineSvc(
                    configSnapshot.EngineDefaults.PatternsConfig.MaxSubexpressions.GetValueOrDefault(),
                    configSnapshot.EngineDefaults.PatternsConfig.IsMaxSubexpressionPreventStart);
            }

            MatchRecognizeStatePoolEngineSvc matchRecognizeStatePoolEngineSvc = null;

            if (configSnapshot.EngineDefaults.MatchRecognizeConfig.MaxStates != null)
            {
                matchRecognizeStatePoolEngineSvc = new MatchRecognizeStatePoolEngineSvc(
                    configSnapshot.EngineDefaults.MatchRecognizeConfig.MaxStates.Value,
                    configSnapshot.EngineDefaults.MatchRecognizeConfig.IsMaxStatesPreventStart);
            }

            var scriptingService = new ScriptingServiceImpl();

            scriptingService.DiscoverEngines();

            // New services context
            EPServicesContext services = new EPServicesContext(
                epServiceProvider.URI, schedulingService,
                eventAdapterService, engineImportService, engineSettingsService, databaseConfigService, plugInViews,
                statementLockFactory, eventProcessingRwLock, null, resourceDirectory, statementContextFactory,
                plugInPatternObj, timerService, filterService, streamFactoryService,
                namedWindowService, variableService, tableService, timeSourceService, valueAddEventService, metricsReporting, statementEventTypeRef,
                statementVariableRef, configSnapshot, threadingService, internalEventRouterImpl, statementIsolationService, schedulingMgmtService,
                deploymentStateService, exceptionHandlingService, new PatternNodeFactoryImpl(), eventTypeIdGenerator, stmtMetadataFactory,
                contextManagementService, schedulableAgentInstanceDirectory, patternSubexpressionPoolSvc, matchRecognizeStatePoolEngineSvc,
                new DataFlowServiceImpl(epServiceProvider, new DataFlowConfigurationStateServiceImpl()),
                new ExprDeclaredServiceImpl(),
                new ContextControllerFactoryFactorySvcImpl(),
                new ContextManagerFactoryServiceImpl(),
                new EPStatementFactoryDefault(),
                new RegexHandlerFactoryDefault(),
                new ViewableActivatorFactoryDefault(),
                scriptingService
                );

            // Engine services subset available to statements
            statementContextFactory.StmtEngineServices = services;

            // Circular dependency
            var statementLifecycleSvc = new StatementLifecycleSvcImpl(epServiceProvider, services);

            services.StatementLifecycleSvc = statementLifecycleSvc;

            // Observers to statement events
            statementLifecycleSvc.LifecycleEvent += (s, theEvent) => metricsReporting.Observe(theEvent);

            // Circular dependency
            statementIsolationService.ServicesContext = services;

            return(services);
        }
コード例 #3
0
        public EPServicesContext CreateServicesContext(
            EPRuntimeSPI epRuntime,
            Configuration configs)
        {
            var container = epRuntime.Container;
            var runtimeEnvContext = new RuntimeEnvContext();
            var eventProcessingRWLock = epRuntime.Container.RWLockManager().CreateLock("EventProcLock");
            var deploymentLifecycleService = new DeploymentLifecycleServiceImpl(-1);

            var runtimeSettingsService = MakeRuntimeSettingsService(configs);

            var scriptCompiler = new ScriptCompilerImpl(container, configs.Common);
            
            var timeAbacus = TimeAbacusFactory.Make(configs.Common.TimeSource.TimeUnit);
            var timeZone = configs.Runtime.Expression.TimeZone ?? TimeZoneInfo.Utc;
            var importServiceRuntime = new ImportServiceRuntime(
                container,
                configs.Common.TransientConfiguration, timeAbacus,
                configs.Common.EventTypeAutoNameNamespaces, timeZone,
                configs.Common.MethodInvocationReferences,
                configs.Common.Imports,
                configs.Common.AnnotationImports);

            var epServicesHA = InitHA(epRuntime.URI, configs, runtimeEnvContext, eventProcessingRWLock, runtimeSettingsService);

            var eventTypeAvroHandler = MakeEventTypeAvroHandler(
                importServiceRuntime, configs.Common.EventMeta.AvroSettings, epServicesHA.RuntimeExtensionServices);
            var resolvedBeanEventTypes = BeanEventTypeRepoUtil.ResolveBeanEventTypes(configs.Common.EventTypeNames, importServiceRuntime);
            var eventBeanTypedEventFactory = MakeEventBeanTypedEventFactory(eventTypeAvroHandler);
            var beanEventTypeStemService =
                BeanEventTypeRepoUtil.MakeBeanEventTypeStemService(configs, resolvedBeanEventTypes, eventBeanTypedEventFactory);
            var eventTypeRepositoryPreconfigured = new EventTypeRepositoryImpl(false);
            var eventTypeFactory = MakeEventTypeFactory(
                epServicesHA.RuntimeExtensionServices, eventTypeRepositoryPreconfigured, deploymentLifecycleService, eventBeanTypedEventFactory);
            var beanEventTypeFactoryPrivate = new BeanEventTypeFactoryPrivate(eventBeanTypedEventFactory, eventTypeFactory, beanEventTypeStemService);
            
            EventTypeRepositoryBeanTypeUtil.BuildBeanTypes(
                beanEventTypeStemService,
                eventTypeRepositoryPreconfigured,
                resolvedBeanEventTypes,
                beanEventTypeFactoryPrivate,
                configs.Common.EventTypesBean);
            EventTypeRepositoryMapTypeUtil.BuildMapTypes(
                eventTypeRepositoryPreconfigured,
                configs.Common.MapTypeConfigurations,
                configs.Common.EventTypesMapEvents,
                configs.Common.EventTypesNestableMapEvents,
                beanEventTypeFactoryPrivate,
                importServiceRuntime);
            EventTypeRepositoryOATypeUtil.BuildOATypes(
                eventTypeRepositoryPreconfigured,
                configs.Common.ObjectArrayTypeConfigurations,
                configs.Common.EventTypesNestableObjectArrayEvents,
                beanEventTypeFactoryPrivate, 
                importServiceRuntime);
            
            var xmlFragmentEventTypeFactory = new XMLFragmentEventTypeFactory(beanEventTypeFactoryPrivate, null, eventTypeRepositoryPreconfigured);
            
            EventTypeRepositoryXMLTypeUtil.BuildXMLTypes(
                eventTypeRepositoryPreconfigured,
                configs.Common.EventTypesXMLDOM,
                beanEventTypeFactoryPrivate,
                xmlFragmentEventTypeFactory,
                container.ResourceManager());
                //importServiceRuntime
            EventTypeRepositoryAvroTypeUtil.BuildAvroTypes(
                eventTypeRepositoryPreconfigured, configs.Common.EventTypesAvro, eventTypeAvroHandler,
                beanEventTypeFactoryPrivate.EventBeanTypedEventFactory);
            EventTypeRepositoryVariantStreamUtil.BuildVariantStreams(
                eventTypeRepositoryPreconfigured, configs.Common.VariantStreams, eventTypeFactory);

            var eventTypeResolvingBeanFactory = MakeEventTypeResolvingBeanFactory(eventTypeRepositoryPreconfigured, eventTypeAvroHandler);

            var viewableActivatorFactory = InitViewableActivatorFactory();

            var statementLifecycleService = new StatementLifecycleServiceImpl();

            EventTypeIdResolver eventTypeIdResolver = new ProxyEventTypeIdResolver {
                ProcGetTypeById = (
                    eventTypeIdPublic,
                    eventTypeIdProtected) => {
                    if (eventTypeIdProtected == -1) {
                        return eventTypeRepositoryPreconfigured.GetTypeById(eventTypeIdPublic);
                    }

                    var deployerResult = deploymentLifecycleService.GetDeploymentByCRC(eventTypeIdPublic);
                    return deployerResult.DeploymentTypes.Get(eventTypeIdProtected);
                }
            };
            var filterSharedBoolExprRepository = MakeFilterSharedBoolExprRepository();
            var filterSharedLookupableRepository = MakeFilterSharedLookupableRepository();
            var filterServiceSPI = MakeFilterService(
                epServicesHA.RuntimeExtensionServices, eventTypeRepositoryPreconfigured, statementLifecycleService, runtimeSettingsService,
                eventTypeIdResolver, filterSharedLookupableRepository);
            var filterBooleanExpressionFactory = MakeFilterBooleanExpressionFactory(statementLifecycleService);

            var statementResourceHolderBuilder = MakeStatementResourceHolderBuilder();

            var aggregationServiceFactoryService = MakeAggregationServiceFactoryService(epServicesHA.RuntimeExtensionServices);

            var viewFactoryService = MakeViewFactoryService();
            var patternFactoryService = MakePatternFactoryService();

            var exceptionHandlingService = InitExceptionHandling(
                epRuntime.URI, configs.Runtime.ExceptionHandling, configs.Runtime.ConditionHandling, ClassForNameProviderDefault.INSTANCE);

            var timeSourceService = MakeTimeSource(configs);
            var schedulingService = MakeSchedulingService(
                epServicesHA,
                timeSourceService,
                epServicesHA.RuntimeExtensionServices,
                runtimeSettingsService,
                statementLifecycleService,
                importServiceRuntime.TimeZone.Id);

            var internalEventRouter = new InternalEventRouterImpl(eventBeanTypedEventFactory);

            var multiMatchHandlerFactory = MakeMultiMatchHandlerFactory(configs);

            var dispatchService = new DispatchService();
            var contextServiceFactory = MakeContextServiceFactory(epServicesHA.RuntimeExtensionServices);
            ContextManagementService contextManagementService = new ContextManagementServiceImpl();

            var viewServicePreviousFactory = MakeViewServicePreviousFactory(epServicesHA.RuntimeExtensionServices);

            var epStatementFactory = MakeEPStatementFactory();

            var msecTimerResolution = configs.Runtime.Threading.InternalTimerMsecResolution;
            if (msecTimerResolution <= 0) {
                throw new ConfigurationException("Timer resolution configuration not set to a valid value, expecting a non-zero value");
            }

            TimerService timerService = new TimerServiceImpl(epRuntime.URI, msecTimerResolution);
            StatementAgentInstanceLockFactory statementAgentInstanceLockFactory = new StatementAgentInstanceLockFactoryImpl(
                configs.Runtime.Execution.IsFairlock, configs.Runtime.Execution.IsDisableLocking);

            var eventTableIndexService = MakeEventTableIndexService(epServicesHA.RuntimeExtensionServices);
            var expressionResultCacheSharable = new ExpressionResultCacheService(
                configs.Runtime.Execution.DeclaredExprValueCacheSize,
                epRuntime.Container.ThreadLocalManager());

            var resultSetProcessorHelperFactory = MakeResultSetProcessorHelperFactory(epServicesHA.RuntimeExtensionServices);

            var variableRepositoryPreconfigured = new VariableRepositoryPreconfigured();
            VariableUtil.ConfigureVariables(
                variableRepositoryPreconfigured, configs.Common.Variables, importServiceRuntime, eventBeanTypedEventFactory,
                eventTypeRepositoryPreconfigured, beanEventTypeFactoryPrivate);
            var variableManagementService = MakeVariableManagementService(
                configs, schedulingService, eventBeanTypedEventFactory, runtimeSettingsService, epServicesHA);
            foreach (var publicVariable in variableRepositoryPreconfigured.Metadata) {
                variableManagementService.AddVariable(null, publicVariable.Value, null, null);
                variableManagementService.AllocateVariableState(
                    null, publicVariable.Key, DEFAULT_AGENT_INSTANCE_ID, false, null, eventBeanTypedEventFactory);
            }

            var variablePathRegistry = new PathRegistry<string, VariableMetaData>(PathRegistryObjectType.VARIABLE);

            var tableExprEvaluatorContext = new TableExprEvaluatorContext(
                epRuntime.Container.ThreadLocalManager());
            var tableManagementService = MakeTableManagementService(epServicesHA.RuntimeExtensionServices, tableExprEvaluatorContext);
            var tablePathRegistry = new PathRegistry<string, TableMetaData>(PathRegistryObjectType.TABLE);

            var metricsReporting = new MetricReportingServiceImpl(
                configs.Runtime.MetricsReporting, epRuntime.URI, container.RWLockManager());

            var namedWindowFactoryService = MakeNamedWindowFactoryService();
            var namedWindowDispatchService = MakeNamedWindowDispatchService(
                schedulingService, configs, eventProcessingRWLock, exceptionHandlingService, variableManagementService, tableManagementService,
                metricsReporting);
            NamedWindowManagementService namedWindowManagementService = new NamedWindowManagementServiceImpl();
            var namedWindowConsumerManagementService = MakeNamedWindowConsumerManagementService(namedWindowManagementService);

            var pathNamedWindowRegistry = new PathRegistry<string, NamedWindowMetaData>(PathRegistryObjectType.NAMEDWINDOW);
            var eventTypePathRegistry = new PathRegistry<string, EventType>(PathRegistryObjectType.EVENTTYPE);
            var pathContextRegistry = new PathRegistry<string, ContextMetaData>(PathRegistryObjectType.CONTEXT);
            EventBeanService eventBeanService = new EventBeanServiceImpl(
                eventTypeRepositoryPreconfigured, eventTypePathRegistry, eventBeanTypedEventFactory);

            PatternSubexpressionPoolRuntimeSvc patternSubexpressionPoolSvc;
            if (configs.Runtime.Patterns.MaxSubexpressions != null) {
                patternSubexpressionPoolSvc = new PatternSubexpressionPoolRuntimeSvcImpl(
                    configs.Runtime.Patterns.MaxSubexpressions.Value,
                    configs.Runtime.Patterns.IsMaxSubexpressionPreventStart);
            }
            else {
                patternSubexpressionPoolSvc = PatternSubexpressionPoolRuntimeSvcNoOp.INSTANCE;
            }

            var exprDeclaredPathRegistry = new PathRegistry<string, ExpressionDeclItem>(PathRegistryObjectType.EXPRDECL);
            var scriptPathRegistry = new PathRegistry<NameAndParamNum, ExpressionScriptProvided>(PathRegistryObjectType.SCRIPT);

            RowRecogStatePoolRuntimeSvc rowRecogStatePoolEngineSvc = null;
            if (configs.Runtime.MatchRecognize.MaxStates != null) {
                rowRecogStatePoolEngineSvc = new RowRecogStatePoolRuntimeSvc(
                    configs.Runtime.MatchRecognize.MaxStates.Value,
                    configs.Runtime.MatchRecognize.IsMaxStatesPreventStart);
            }

            var rowRecogStateRepoFactory = MakeRowRecogStateRepoFactory();

            DatabaseConfigServiceRuntime databaseConfigServiceRuntime =
                new DatabaseConfigServiceImpl(
                    container,
                    configs.Common.DatabaseReferences,
                    importServiceRuntime);
            var historicalDataCacheFactory = MakeHistoricalDataCacheFactory(epServicesHA.RuntimeExtensionServices);

            var dataflowService = new EPDataFlowServiceImpl(container);
            var dataFlowFilterServiceAdapter = MakeDataFlowFilterServiceAdapter();

            var threadingService = MakeThreadingService(configs);
            var eventRenderer = new EPRenderEventServiceImpl();

            var eventSerdeFactory = MakeEventSerdeFactory(epServicesHA.RuntimeExtensionServices);
            var eventTypeSerdeRepository = MakeEventTypeSerdeRepository(eventTypeRepositoryPreconfigured, eventTypePathRegistry);
            var classLoaderParent = new ParentClassLoader(importServiceRuntime.ClassLoader);

            var stageRecoveryService = MakeStageRecoveryService(epServicesHA);

            var classProvidedPathRegistry = new PathRegistry<string, ClassProvided>(PathRegistryObjectType.CLASSPROVIDED);

            return new EPServicesContext(
                container,
                aggregationServiceFactoryService,
                beanEventTypeFactoryPrivate,
                beanEventTypeStemService,
                ClassForNameProviderDefault.INSTANCE,
                classLoaderParent,
                classProvidedPathRegistry,
                configs,
                contextManagementService,
                pathContextRegistry,
                contextServiceFactory,
                dataflowService,
                dataFlowFilterServiceAdapter,
                databaseConfigServiceRuntime,
                deploymentLifecycleService,
                dispatchService,
                runtimeEnvContext,
                runtimeSettingsService,
                epRuntime.URI,
                importServiceRuntime,
                epStatementFactory,
                exprDeclaredPathRegistry,
                eventProcessingRWLock,
                epServicesHA,
                epRuntime,
                eventBeanService,
                eventBeanTypedEventFactory,
                eventRenderer,
                eventSerdeFactory,
                eventTableIndexService,
                eventTypeAvroHandler,
                eventTypeFactory,
                eventTypeIdResolver,
                eventTypePathRegistry,
                eventTypeRepositoryPreconfigured,
                eventTypeResolvingBeanFactory,
                eventTypeSerdeRepository,
                exceptionHandlingService,
                expressionResultCacheSharable,
                filterBooleanExpressionFactory,
                filterServiceSPI,
                filterSharedBoolExprRepository,
                filterSharedLookupableRepository,
                historicalDataCacheFactory,
                internalEventRouter,
                metricsReporting,
                multiMatchHandlerFactory,
                namedWindowConsumerManagementService,
                namedWindowDispatchService,
                namedWindowFactoryService,
                namedWindowManagementService,
                pathNamedWindowRegistry,
                patternFactoryService,
                patternSubexpressionPoolSvc,
                resultSetProcessorHelperFactory,
                rowRecogStateRepoFactory,
                rowRecogStatePoolEngineSvc,
                schedulingService,
                scriptPathRegistry,
                scriptCompiler,
                stageRecoveryService,
                statementLifecycleService,
                statementAgentInstanceLockFactory,
                statementResourceHolderBuilder,
                tableExprEvaluatorContext,
                tableManagementService,
                tablePathRegistry,
                threadingService,
                timeAbacus,
                timeSourceService,
                timerService,
                variableManagementService,
                variablePathRegistry,
                viewableActivatorFactory,
                viewFactoryService,
                viewServicePreviousFactory,
                xmlFragmentEventTypeFactory);
        }