public static FAFProvider QueryMethod( EPCompiled compiled, EPServicesContext services) { var classLoader = ClassProvidedImportClassLoaderFactory.GetClassLoader( compiled.Assemblies, services.ClassLoaderParent, services.ClassProvidedPathRegistry); if (compiled.Manifest.QueryProviderClassName == null) { if (compiled.Manifest.ModuleProviderClassName != null) { throw new EPException( "Cannot execute a fire-and-forget query that was compiled as module EPL, make sure to use the 'compileQuery' method of the compiler"); } throw new EPException( "Failed to find query provider class name in manifest (is this a compiled fire-and-forget query?)"); } var className = compiled.Manifest.QueryProviderClassName; // load module resource class Type clazz; try { clazz = classLoader.GetClass(className); } catch (TypeLoadException e) { throw new EPException(e); } // get FAF provider FAFProvider fafProvider; try { fafProvider = (FAFProvider) TypeHelper.Instantiate(clazz); } catch (EPException) { throw; } catch (Exception e) { throw new EPException(e); } if (classLoader is ClassProvidedImportClassLoader importClassLoader) { importClassLoader.Imported = fafProvider.ModuleDependencies.PathClasses; } // initialize event types IDictionary<string, EventType> moduleTypes = new Dictionary<string, EventType>(); EventTypeResolverImpl eventTypeResolver = new EventTypeResolverImpl( moduleTypes, services.EventTypePathRegistry, services.EventTypeRepositoryBus, services.BeanEventTypeFactoryPrivate, services.EventSerdeFactory); EventTypeCollectorImpl eventTypeCollector = new EventTypeCollectorImpl( services.Container, moduleTypes, services.BeanEventTypeFactoryPrivate, classLoader, services.EventTypeFactory, services.BeanEventTypeStemService, eventTypeResolver, services.XmlFragmentEventTypeFactory, services.EventTypeAvroHandler, services.EventBeanTypedEventFactory, services.ImportServiceRuntime); fafProvider.InitializeEventTypes(new EPModuleEventTypeInitServicesImpl(eventTypeCollector, eventTypeResolver)); // initialize query fafProvider.InitializeQuery( new EPStatementInitServicesImpl( "faf-query", EmptyDictionary<StatementProperty, object>.Instance, null, null, eventTypeResolver, null, null, null, null, false, null, null, services)); return fafProvider; }
public static DeployerModuleEPLObjects InitializeEPLObjects( ModuleProviderCLPair provider, string deploymentId, EPServicesContext services) { // keep protected types var beanEventTypeFactory = new BeanEventTypeFactoryPrivate( new EventBeanTypedEventFactoryRuntime(services.EventTypeAvroHandler), services.EventTypeFactory, services.BeanEventTypeStemService); // initialize module event types IDictionary <string, EventType> moduleEventTypes = new LinkedHashMap <string, EventType>(); var eventTypeResolver = new EventTypeResolverImpl( moduleEventTypes, services.EventTypePathRegistry, services.EventTypeRepositoryBus, services.BeanEventTypeFactoryPrivate, services.EventSerdeFactory); var eventTypeCollector = new EventTypeCollectorImpl( services.Container, moduleEventTypes, beanEventTypeFactory, provider.ClassLoader, services.EventTypeFactory, services.BeanEventTypeStemService, eventTypeResolver, services.XmlFragmentEventTypeFactory, services.EventTypeAvroHandler, services.EventBeanTypedEventFactory, services.ImportServiceRuntime); try { provider.ModuleProvider.InitializeEventTypes(new EPModuleEventTypeInitServicesImpl(eventTypeCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } JsonEventTypeUtility.AddJsonUnderlyingClass(moduleEventTypes, services.ClassLoaderParent, deploymentId); // initialize module named windows IDictionary <string, NamedWindowMetaData> moduleNamedWindows = new Dictionary <string, NamedWindowMetaData>(); NamedWindowCollector namedWindowCollector = new NamedWindowCollectorImpl(moduleNamedWindows); try { provider.ModuleProvider.InitializeNamedWindows(new EPModuleNamedWindowInitServicesImpl(namedWindowCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize module tables IDictionary <string, TableMetaData> 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 ISet <ModuleIndexMeta> moduleIndexes = new HashSet <ModuleIndexMeta>(); var indexCollector = new IndexCollectorRuntime(moduleIndexes); try { provider.ModuleProvider.InitializeIndexes(new EPModuleIndexInitServicesImpl(indexCollector)); } catch (Exception e) { throw new EPException(e); } // initialize module contexts IDictionary <string, ContextMetaData> moduleContexts = new Dictionary <string, ContextMetaData>(); ContextCollector contextCollector = new ContextCollectorImpl(moduleContexts); try { provider.ModuleProvider.InitializeContexts(new EPModuleContextInitServicesImpl(contextCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize module variables IDictionary <string, VariableMetaData> moduleVariables = new Dictionary <string, VariableMetaData>(); VariableCollector variableCollector = new VariableCollectorImpl(moduleVariables); try { provider.ModuleProvider.InitializeVariables(new EPModuleVariableInitServicesImpl(variableCollector, eventTypeResolver)); } catch (Exception e) { throw new EPException(e); } // initialize module expressions IDictionary <string, ExpressionDeclItem> moduleExpressions = new Dictionary <string, ExpressionDeclItem>(); var exprDeclaredCollector = new ExprDeclaredCollectorRuntime(moduleExpressions); try { provider.ModuleProvider.InitializeExprDeclareds(new EPModuleExprDeclaredInitServicesImpl(exprDeclaredCollector)); } catch (Exception e) { throw new EPException(e); } // initialize module scripts IDictionary <NameAndParamNum, ExpressionScriptProvided> moduleScripts = new Dictionary <NameAndParamNum, ExpressionScriptProvided>(); var scriptCollectorRuntime = new ScriptCollectorRuntime(moduleScripts); try { provider.ModuleProvider.InitializeScripts(new EPModuleScriptInitServicesImpl(scriptCollectorRuntime)); } catch (Exception e) { throw new EPException(e); } // initialize module class-provided create-class IDictionary <string, ClassProvided> moduleClasses = new Dictionary <string, ClassProvided>(); var classProvidedCollectorRuntime = new ClassProvidedCollectorRuntime(moduleClasses); try { provider.ModuleProvider.InitializeClassProvided(new EPModuleClassProvidedInitServicesImpl(classProvidedCollectorRuntime)); } catch (Exception e) { throw new EPException(e); } foreach (var moduleClass in moduleClasses) { moduleClass.Value.LoadClasses(provider.ClassLoader); } return(new DeployerModuleEPLObjects( beanEventTypeFactory, moduleEventTypes, moduleNamedWindows, moduleTables, moduleIndexes, moduleContexts, moduleVariables, moduleExpressions, moduleScripts, moduleClasses, eventTypeCollector.Serdes, eventTypeResolver)); }
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); }