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);
        }
Exemplo n.º 2
0
        private static ModuleCompileTimeServices GetServices(
            CompilerArguments arguments,
            string moduleName,
            ICollection<string> moduleUses,
            bool isFireAndForget)
        {
            var configuration = arguments.Configuration;
            var path = arguments.Path;
            var options = arguments.Options;
            
            // script
            var scriptCompiler = MakeScriptCompiler(configuration);

            // imports
            var importServiceCompileTime = MakeImportService(configuration);
            var classLoaderParent = new ParentClassLoader(importServiceCompileTime.ClassLoader);
            var container = importServiceCompileTime.Container;

            // resolve pre-configured bean event types, make bean-stem service
            var resolvedBeanEventTypes = BeanEventTypeRepoUtil.ResolveBeanEventTypes(
                configuration.Common.EventTypeNames,
                importServiceCompileTime);
            var beanEventTypeStemService = BeanEventTypeRepoUtil.MakeBeanEventTypeStemService(
                configuration,
                resolvedBeanEventTypes,
                EventBeanTypedEventFactoryCompileTime.INSTANCE);

            // allocate repositories
            var eventTypeRepositoryPreconfigured = new EventTypeRepositoryImpl(true);
            var eventTypeCompileRegistry = new EventTypeCompileTimeRegistry(eventTypeRepositoryPreconfigured);
            var beanEventTypeFactoryPrivate = new BeanEventTypeFactoryPrivate(
                EventBeanTypedEventFactoryCompileTime.INSTANCE, EventTypeFactoryImpl.GetInstance(container), beanEventTypeStemService);
            var variableRepositoryPreconfigured = new VariableRepositoryPreconfigured();

            // allocate path registries
            var pathEventTypes = new PathRegistry<string, EventType>(PathRegistryObjectType.EVENTTYPE);
            var pathNamedWindows = new PathRegistry<string, NamedWindowMetaData>(PathRegistryObjectType.NAMEDWINDOW);
            var pathTables = new PathRegistry<string, TableMetaData>(PathRegistryObjectType.TABLE);
            var pathContexts = new PathRegistry<string, ContextMetaData>(PathRegistryObjectType.CONTEXT);
            var pathVariables = new PathRegistry<string, VariableMetaData>(PathRegistryObjectType.VARIABLE);
            var pathExprDeclared = new PathRegistry<string, ExpressionDeclItem>(PathRegistryObjectType.EXPRDECL);
            var pathScript = new PathRegistry<NameAndParamNum, ExpressionScriptProvided>(PathRegistryObjectType.SCRIPT);
            var pathClassProvided = new PathRegistry<string, ClassProvided>(PathRegistryObjectType.CLASSPROVIDED);

            // add runtime-path which is the information an existing runtime may have
            if (path.CompilerPathables != null) {
                foreach (EPCompilerPathable pathable in path.CompilerPathables) {
                    EPCompilerPathableImpl impl = (EPCompilerPathableImpl) pathable;
                    pathVariables.MergeFrom(impl.VariablePathRegistry);
                    pathEventTypes.MergeFrom(impl.EventTypePathRegistry);
                    pathExprDeclared.MergeFrom(impl.ExprDeclaredPathRegistry);
                    pathNamedWindows.MergeFrom(impl.NamedWindowPathRegistry);
                    pathTables.MergeFrom(impl.TablePathRegistry);
                    pathContexts.MergeFrom(impl.ContextPathRegistry);
                    pathScript.MergeFrom(impl.ScriptPathRegistry);
                    pathClassProvided.MergeFrom(impl.ClassProvidedPathRegistry);
                    eventTypeRepositoryPreconfigured.MergeFrom(impl.EventTypePreconfigured);
                    variableRepositoryPreconfigured.MergeFrom(impl.VariablePreconfigured);

                    JsonEventTypeUtility.AddJsonUnderlyingClass(pathEventTypes, classLoaderParent);
                }
            }
            
            // build preconfigured type system
            EventTypeRepositoryBeanTypeUtil.BuildBeanTypes(
                beanEventTypeStemService,
                eventTypeRepositoryPreconfigured,
                resolvedBeanEventTypes,
                beanEventTypeFactoryPrivate,
                configuration.Common.EventTypesBean);
            EventTypeRepositoryMapTypeUtil.BuildMapTypes(
                eventTypeRepositoryPreconfigured,
                configuration.Common.MapTypeConfigurations,
                configuration.Common.EventTypesMapEvents,
                configuration.Common.EventTypesNestableMapEvents,
                beanEventTypeFactoryPrivate,
                importServiceCompileTime);
            EventTypeRepositoryOATypeUtil.BuildOATypes(
                eventTypeRepositoryPreconfigured,
                configuration.Common.ObjectArrayTypeConfigurations,
                configuration.Common.EventTypesNestableObjectArrayEvents,
                beanEventTypeFactoryPrivate,
                importServiceCompileTime);
            XMLFragmentEventTypeFactory xmlFragmentEventTypeFactory = new XMLFragmentEventTypeFactory(
                beanEventTypeFactoryPrivate,
                eventTypeCompileRegistry,
                eventTypeRepositoryPreconfigured);
            EventTypeRepositoryXMLTypeUtil.BuildXMLTypes(
                eventTypeRepositoryPreconfigured,
                configuration.Common.EventTypesXMLDOM,
                beanEventTypeFactoryPrivate,
                xmlFragmentEventTypeFactory,
                container.ResourceManager());
            EventTypeAvroHandler eventTypeAvroHandler = EventTypeAvroHandlerFactory.Resolve(
                importServiceCompileTime,
                configuration.Common.EventMeta.AvroSettings,
                EventTypeAvroHandlerConstants.COMPILE_TIME_HANDLER_IMPL);
            EventTypeRepositoryAvroTypeUtil.BuildAvroTypes(
                eventTypeRepositoryPreconfigured,
                configuration.Common.EventTypesAvro,
                eventTypeAvroHandler,
                beanEventTypeFactoryPrivate.EventBeanTypedEventFactory);
            EventTypeRepositoryVariantStreamUtil.BuildVariantStreams(
                eventTypeRepositoryPreconfigured,
                configuration.Common.VariantStreams,
                EventTypeFactoryImpl.GetInstance(container));

            // build preconfigured variables
            VariableUtil.ConfigureVariables(
                variableRepositoryPreconfigured,
                configuration.Common.Variables,
                importServiceCompileTime,
                EventBeanTypedEventFactoryCompileTime.INSTANCE,
                eventTypeRepositoryPreconfigured,
                beanEventTypeFactoryPrivate);

            var deploymentNumber = -1;

            foreach (var unit in path.Compileds) {
                deploymentNumber++;
                var provider = ModuleProviderUtil.Analyze(unit, classLoaderParent, pathClassProvided);
                var unitModuleName = provider.ModuleProvider.ModuleName;

                // initialize event types
                var moduleTypes = new Dictionary<string, EventType>();
                var eventTypeResolver = new EventTypeResolverImpl(
                    moduleTypes,
                    pathEventTypes,
                    eventTypeRepositoryPreconfigured,
                    beanEventTypeFactoryPrivate,
                    EventSerdeFactoryDefault.INSTANCE);
                var eventTypeCollector = new EventTypeCollectorImpl(
                    container,
                    moduleTypes,
                    beanEventTypeFactoryPrivate,
                    provider.ClassLoader,
                    EventTypeFactoryImpl.GetInstance(container),
                    beanEventTypeStemService,
                    eventTypeResolver,
                    xmlFragmentEventTypeFactory,
                    eventTypeAvroHandler,
                    EventBeanTypedEventFactoryCompileTime.INSTANCE,
                    importServiceCompileTime);

                try {
                    provider.ModuleProvider.InitializeEventTypes(
                        new EPModuleEventTypeInitServicesImpl(eventTypeCollector, eventTypeResolver));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }
                
                JsonEventTypeUtility.AddJsonUnderlyingClass(moduleTypes, classLoaderParent, null);

                // initialize named windows
                var moduleNamedWindows = new Dictionary<string, NamedWindowMetaData>();
                var namedWindowCollector = new NamedWindowCollectorImpl(moduleNamedWindows);
                try {
                    provider.ModuleProvider.InitializeNamedWindows(
                        new EPModuleNamedWindowInitServicesImpl(namedWindowCollector, eventTypeResolver));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize tables
                var moduleTables = new Dictionary<string, TableMetaData>();
                var tableCollector = new TableCollectorImpl(moduleTables);
                try {
                    provider.ModuleProvider.InitializeTables(
                        new EPModuleTableInitServicesImpl(tableCollector, eventTypeResolver));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize create-index indexes
                var indexCollector = new IndexCollectorCompileTime(
                    moduleNamedWindows,
                    moduleTables,
                    pathNamedWindows,
                    pathTables);
                try {
                    provider.ModuleProvider.InitializeIndexes(new EPModuleIndexInitServicesImpl(indexCollector));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize create-contexts
                var moduleContexts = new Dictionary<string, ContextMetaData>();
                var contextCollector = new ContextCollectorImpl(moduleContexts);
                try {
                    provider.ModuleProvider.InitializeContexts(
                        new EPModuleContextInitServicesImpl(contextCollector, eventTypeResolver));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize variables
                var moduleVariables = new Dictionary<string, VariableMetaData>();
                var variableCollector = new VariableCollectorImpl(moduleVariables);
                try {
                    provider.ModuleProvider.InitializeVariables(
                        new EPModuleVariableInitServicesImpl(variableCollector, eventTypeResolver));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize module expressions
                var moduleExprDeclareds = new Dictionary<string, ExpressionDeclItem>();
                var exprDeclaredCollector = new ExprDeclaredCollectorCompileTime(moduleExprDeclareds);
                try {
                    provider.ModuleProvider.InitializeExprDeclareds(
                        new EPModuleExprDeclaredInitServicesImpl(exprDeclaredCollector));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize module scripts
                var moduleScripts = new Dictionary<NameAndParamNum, ExpressionScriptProvided>();
                var scriptCollector = new ScriptCollectorCompileTime(moduleScripts);
                try {
                    provider.ModuleProvider.InitializeScripts(new EPModuleScriptInitServicesImpl(scriptCollector));
                }
                catch (Exception e) {
                    throw new EPException(e);
                }

                // initialize inlined classes
                var moduleClassProvideds = new Dictionary<string, ClassProvided>();
                var classProvidedCollector = new ClassProvidedCollectorCompileTime(moduleClassProvideds, classLoaderParent);
                try {
                    provider.ModuleProvider.InitializeClassProvided(new EPModuleClassProvidedInitServicesImpl(classProvidedCollector));
                } catch (Exception e) {
                    throw new EPException(e);
                }
                
                // save path-visibility event types and named windows to the path
                var deploymentId = "D" + deploymentNumber;
                try {
                    foreach (var type in moduleTypes) {
                        if (type.Value.Metadata.AccessModifier.IsNonPrivateNonTransient()) {
                            pathEventTypes.Add(type.Key, unitModuleName, type.Value, deploymentId);
                        }
                    }

                    foreach (var entry in moduleNamedWindows) {
                        if (entry.Value.EventType.Metadata.AccessModifier.IsNonPrivateNonTransient()) {
                            pathNamedWindows.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }

                    foreach (var entry in moduleTables) {
                        if (entry.Value.TableVisibility.IsNonPrivateNonTransient()) {
                            pathTables.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }

                    foreach (var entry in moduleContexts) {
                        if (entry.Value.ContextVisibility.IsNonPrivateNonTransient()) {
                            pathContexts.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }

                    foreach (var entry in moduleVariables) {
                        if (entry.Value.VariableVisibility.IsNonPrivateNonTransient()) {
                            pathVariables.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }

                    foreach (var entry in moduleExprDeclareds) {
                        if (entry.Value.Visibility.IsNonPrivateNonTransient()) {
                            pathExprDeclared.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }

                    foreach (var entry in moduleScripts) {
                        if (entry.Value.Visibility.IsNonPrivateNonTransient()) {
                            pathScript.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }
                    
                    foreach (var entry in moduleClassProvideds) {
                        if (entry.Value.Visibility.IsNonPrivateNonTransient()) {
                            pathClassProvided.Add(entry.Key, unitModuleName, entry.Value, deploymentId);
                        }
                    }
                }
                catch (PathException ex) {
                    throw new EPCompileException(
                        "Invalid path: " + ex.Message,
                        ex,
                        new EmptyList<EPCompileExceptionItem>());
                }
            }

            var moduleDependencies = new ModuleDependenciesCompileTime();

            // build bean space of public and protected
            var eventTypeCompileTimeResolver = new EventTypeCompileTimeResolver(
                moduleName,
                moduleUses,
                eventTypeCompileRegistry,
                eventTypeRepositoryPreconfigured,
                pathEventTypes,
                moduleDependencies,
                isFireAndForget);

            // build named window registry
            var namedWindowCompileTimeRegistry = new NamedWindowCompileTimeRegistry();
            var namedWindowCompileTimeResolver = new NamedWindowCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                namedWindowCompileTimeRegistry,
                pathNamedWindows,
                moduleDependencies,
                isFireAndForget);

            // build context registry
            var contextCompileTimeRegistry = new ContextCompileTimeRegistry();
            var contextCompileTimeResolver = new ContextCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                contextCompileTimeRegistry,
                pathContexts,
                moduleDependencies,
                isFireAndForget);

            // build variable registry
            var variableCompileTimeRegistry = new VariableCompileTimeRegistry();
            var variableCompileTimeResolver = new VariableCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                variableRepositoryPreconfigured,
                variableCompileTimeRegistry,
                pathVariables,
                moduleDependencies,
                isFireAndForget);

            // build declared-expression registry
            var exprDeclaredCompileTimeRegistry = new ExprDeclaredCompileTimeRegistry();
            var exprDeclaredCompileTimeResolver = new ExprDeclaredCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                exprDeclaredCompileTimeRegistry,
                pathExprDeclared,
                moduleDependencies,
                isFireAndForget);

            // build table-registry
            var localTables = new Dictionary<string, TableMetaData>();
            var tableCompileTimeRegistry = new TableCompileTimeRegistry(localTables);
            var tableCompileTimeResolver = new TableCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                tableCompileTimeRegistry,
                pathTables,
                moduleDependencies,
                isFireAndForget);

            // build script registry
            var scriptCompileTimeRegistry = new ScriptCompileTimeRegistry();
            var scriptCompileTimeResolver = new ScriptCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                scriptCompileTimeRegistry,
                pathScript,
                moduleDependencies,
                isFireAndForget);

            // build classes registry
            var classProvidedCompileTimeRegistry = new ClassProvidedCompileTimeRegistry();
            var classProvidedCompileTimeResolver = new ClassProvidedCompileTimeResolverImpl(
                moduleName,
                moduleUses,
                classProvidedCompileTimeRegistry,
                pathClassProvided,
                moduleDependencies,
                isFireAndForget);

            // view resolution
            var plugInViews = new PluggableObjectCollection();
            plugInViews.AddViews(
                configuration.Compiler.PlugInViews,
                configuration.Compiler.PlugInVirtualDataWindows,
                importServiceCompileTime);
            var viewRegistry = new PluggableObjectRegistryImpl(new[] {ViewEnumHelper.BuiltinViews, plugInViews});
            ViewResolutionService viewResolutionService = new ViewResolutionServiceImpl(viewRegistry);

            var plugInPatternObj = new PluggableObjectCollection();
            plugInPatternObj.AddPatternObjects(configuration.Compiler.PlugInPatternObjects, importServiceCompileTime);
            plugInPatternObj.AddObjects(PatternObjectHelper.BuiltinPatternObjects);
            PatternObjectResolutionService patternResolutionService =
                new PatternObjectResolutionServiceImpl(plugInPatternObj);

            var indexCompileTimeRegistry = new IndexCompileTimeRegistry(new Dictionary<IndexCompileTimeKey, IndexDetailForge>());

            var moduleVisibilityRules = new ModuleAccessModifierServiceImpl(options, configuration.Compiler.ByteCode);

            var databaseConfigServiceCompileTime =
                new DatabaseConfigServiceImpl(
                    container,
                    configuration.Common.DatabaseReferences,
                    importServiceCompileTime);

            var compilerServices = new CompilerServicesImpl();

            var targetHA = configuration.GetType().Name.EndsWith("ConfigurationHA");
            var serdeEventTypeRegistry = new SerdeEventTypeCompileTimeRegistryImpl(targetHA);
            SerdeCompileTimeResolver serdeResolver = targetHA
                ? MakeSerdeResolver(configuration.Compiler.Serde, configuration.Common.TransientConfiguration)
                : SerdeCompileTimeResolverNonHA.INSTANCE;

            return new ModuleCompileTimeServices(
                container,
                compilerServices,
                configuration,
                contextCompileTimeRegistry,
                contextCompileTimeResolver,
                beanEventTypeStemService,
                beanEventTypeFactoryPrivate,
                classProvidedCompileTimeRegistry,
                classProvidedCompileTimeResolver,
                databaseConfigServiceCompileTime,
                importServiceCompileTime,
                exprDeclaredCompileTimeRegistry,
                exprDeclaredCompileTimeResolver,
                eventTypeAvroHandler,
                eventTypeCompileRegistry,
                eventTypeCompileTimeResolver,
                eventTypeRepositoryPreconfigured,
                isFireAndForget,
                indexCompileTimeRegistry,
                moduleDependencies,
                moduleVisibilityRules,
                namedWindowCompileTimeResolver,
                namedWindowCompileTimeRegistry,
                classLoaderParent,
                patternResolutionService,
                scriptCompileTimeRegistry,
                scriptCompileTimeResolver,
                scriptCompiler,
                serdeEventTypeRegistry,
                serdeResolver,
                tableCompileTimeRegistry,
                tableCompileTimeResolver,
                variableCompileTimeRegistry,
                variableCompileTimeResolver,
                viewResolutionService,
                xmlFragmentEventTypeFactory);
        }