/// <summary> /// Loads and initializes adapter loaders. /// </summary> /// <param name="services">is the engine instance services</param> private void LoadAdapters(EPServicesContext services) { var pluginLoaders = _configSnapshot.PluginLoaders; if ((pluginLoaders == null) || (pluginLoaders.Count == 0)) { return; } foreach (var config in pluginLoaders) { var className = config.TypeName; Type pluginLoaderClass; try { pluginLoaderClass = services.EngineImportService.GetClassForNameProvider().ClassForName(className); } catch (TypeLoadException ex) { throw new ConfigurationException("Failed to load adapter loader class '" + className + "'", ex); } Object pluginLoaderObj; try { pluginLoaderObj = Activator.CreateInstance(pluginLoaderClass); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + pluginLoaderClass + "' cannot be instantiated"); } catch (MissingMethodException e) { throw new ConfigurationException( "Error instantiating class - Default constructor was not found", e); } catch (MethodAccessException e) { throw new ConfigurationException( "Error instantiating class - Caller does not have permission to use constructor", e); } catch (ArgumentException e) { throw new ConfigurationException("Error instantiating class - Type is not a RuntimeType", e); } if (!(pluginLoaderObj is PluginLoader)) { throw new ConfigurationException( "Failed to cast adapter loader class '" + className + "' to " + typeof(PluginLoader).FullName); } var pluginLoader = (PluginLoader)pluginLoaderObj; var context = new PluginLoaderInitContext( config.LoaderName, config.ConfigProperties, config.ConfigurationXML, this); pluginLoader.Init(context); // register adapter loader in JNDI context tree services.EngineEnvContext.Bind("plugin-loader/" + config.LoaderName, pluginLoader); } }
/// <summary>Constructor - takes the services context as argument. </summary> /// <param name="adminContext">administrative context</param> public EPAdministratorImpl(EPAdministratorContext adminContext) { _services = adminContext.Services; _configurationOperations = adminContext.ConfigurationOperations; _defaultStreamSelector = adminContext.DefaultStreamSelector; ConfigurationEngineDefaults.AlternativeContext alternativeContext = adminContext.Services.ConfigSnapshot.EngineDefaults.AlternativeContextConfig; StatementIdGenerator statementIdGenerator = null; if (alternativeContext != null && alternativeContext.StatementIdGeneratorFactory != null) { var statementIdGeneratorFactory = TypeHelper.Instantiate <StatementIdGeneratorFactory>(alternativeContext.StatementIdGeneratorFactory); statementIdGenerator = statementIdGeneratorFactory.Invoke(new StatementIdGeneratorFactoryContext(_services.EngineURI)); } _deploymentAdminService = new EPDeploymentAdminImpl( this, adminContext.Services.DeploymentStateService, adminContext.Services.StatementEventTypeRefService, adminContext.Services.EventAdapterService, adminContext.Services.StatementIsolationService, statementIdGenerator, adminContext.Services.FilterService, _services.ConfigSnapshot.EngineDefaults.ExpressionConfig.TimeZone); }
public static StatementContextEngineServices GetStmtCtxEngineServices(EPServicesContext services) { return(new StatementContextEngineServices( services.EngineURI, services.EventAdapterService, services.NamedWindowMgmtService, services.VariableService, services.TableService, services.EngineSettingsService, services.ValueAddEventService, services.ConfigSnapshot, services.MetricsReportingService, services.ViewService, services.ExceptionHandlingService, services.ExpressionResultCacheSharable, services.StatementEventTypeRefService, services.TableService.TableExprEvaluatorContext, services.EngineLevelExtensionServicesContext, services.RegexHandlerFactory, services.StatementLockFactory, services.ContextManagementService, services.ViewServicePreviousFactory, services.EventTableIndexService, services.PatternNodeFactory, services.FilterBooleanExpressionFactory, services.TimeSource, services.EngineImportService, services.AggregationFactoryFactory, services.SchedulingService )); }
/// <summary>Ctor. </summary> /// <param name="isolatedServiceName">name of the isolated service</param> /// <param name="services">isolated services</param> /// <param name="unisolatedServices">engine services</param> /// <param name="isolatedRuntime">the runtime for this isolated service</param> public EPAdministratorIsolatedImpl(string isolatedServiceName, EPIsolationUnitServices services, EPServicesContext unisolatedServices, EPRuntimeIsolatedSPI isolatedRuntime) { _isolatedServiceName = isolatedServiceName; _services = services; _unisolatedServices = unisolatedServices; _isolatedRuntime = isolatedRuntime; }
/// <summary> /// Compile an EPL statement. /// </summary> /// <param name="eplStatement">to compile</param> /// <param name="eplStatementForErrorMsg">the statement to use for indicating error messages</param> /// <param name="addPleaseCheck">true to add please-check message text</param> /// <param name="statementName">the name of statement</param> /// <param name="services">engine services</param> /// <param name="defaultStreamSelector">stream selector</param> /// <returns>compiled statement</returns> public static StatementSpecRaw CompileEPL( string eplStatement, string eplStatementForErrorMsg, bool addPleaseCheck, string statementName, EPServicesContext services, SelectClauseStreamSelectorEnum defaultStreamSelector) { return(CompileEPL( services.Container, eplStatement, eplStatementForErrorMsg, addPleaseCheck, statementName, defaultStreamSelector, services.EngineImportService, services.VariableService, services.SchedulingService, services.EngineURI, services.ConfigSnapshot, services.PatternNodeFactory, services.ContextManagementService, services.ExprDeclaredService, services.TableService)); }
public EPServiceEngine( IContainer container, EPServicesContext services, EPRuntimeSPI runtimeSPI, EPAdministratorSPI admin) { Container = container; Services = services; Runtime = runtimeSPI; Admin = admin; }
/// <summary> /// Ctor. /// </summary> /// <param name="runtimeSPI">The runtime SPI.</param> /// <param name="services">engine services</param> /// <param name="configurationOperations">configuration snapshot</param> /// <param name="defaultStreamSelector">default stream selection</param> public EPAdministratorContext(EPRuntimeSPI runtimeSPI, EPServicesContext services, ConfigurationOperations configurationOperations, SelectClauseStreamSelectorEnum defaultStreamSelector ) { RuntimeSPI = runtimeSPI; ConfigurationOperations = configurationOperations; DefaultStreamSelector = defaultStreamSelector; Services = services; }
/// <summary>Ctor. </summary> /// <param name="name">name of isolated service</param> /// <param name="isolatedServices">filter and scheduling service isolated</param> /// <param name="unisolatedSvc">engine services</param> /// <param name="providers">names and isolated service providers</param> public EPServiceProviderIsolatedImpl(String name, EPIsolationUnitServices isolatedServices, EPServicesContext unisolatedSvc, IDictionary <String, EPServiceProviderIsolatedImpl> providers) { _name = name; _providers = providers; _isolatedServices = isolatedServices; _runtime = new EPRuntimeIsolatedImpl(isolatedServices, unisolatedSvc); _admin = new EPAdministratorIsolatedImpl(name, isolatedServices, unisolatedSvc, _runtime); }
/// <summary>Ctor. </summary> /// <param name="svc">isolated services</param> /// <param name="unisolatedSvc">engine services</param> public EPRuntimeIsolatedImpl(EPIsolationUnitServices svc, EPServicesContext unisolatedSvc) { _services = svc; _unisolatedServices = unisolatedSvc; _threadWorkQueue = new ThreadWorkQueue(); _isSubselectPreeval = unisolatedSvc.EngineSettingsService.EngineSettings.Expression.IsSelfSubselectPreeval; _isPrioritized = unisolatedSvc.EngineSettingsService.EngineSettings.Execution.IsPrioritized; _isLatchStatementInsertStream = unisolatedSvc.EngineSettingsService.EngineSettings.Threading.IsInsertIntoDispatchPreserveOrder; _threadLocalData = ThreadLocalManager.Create(CreateLocalData); }
private void StartEngineMetrics(EPServicesContext services, EPRuntime runtime) { lock (this) { #if false MetricName filterName = MetricNameFactory.Name(services.EngineURI, "filter"); CommonJMXUtil.RegisterMbean(services.FilterService, filterName); MetricName scheduleName = MetricNameFactory.Name(services.EngineURI, "schedule"); CommonJMXUtil.RegisterMbean(services.SchedulingService, scheduleName); MetricName runtimeName = MetricNameFactory.Name(services.EngineURI, "runtime"); CommonJMXUtil.RegisterMbean(runtime, runtimeName); #endif } }
/// <summary>Constructor - takes the services context as argument. </summary> /// <param name="adminContext">administrative context</param> public EPAdministratorImpl(EPAdministratorContext adminContext) { _services = adminContext.Services; _configurationOperations = adminContext.ConfigurationOperations; _defaultStreamSelector = adminContext.DefaultStreamSelector; _deploymentAdminService = new EPDeploymentAdminImpl( this, adminContext.Services.DeploymentStateService, adminContext.Services.StatementEventTypeRefService, adminContext.Services.EventAdapterService, adminContext.Services.StatementIsolationService, adminContext.Services.FilterService, _services.ConfigSnapshot.EngineDefaults.ExpressionConfig.TimeZone, _services.ConfigSnapshot.EngineDefaults.ExceptionHandlingConfig.UndeployRethrowPolicy); }
public static StatementContextEngineServices GetStmtCtxEngineServices(EPServicesContext services) { return(new StatementContextEngineServices( services.EngineURI, services.EventAdapterService, services.NamedWindowService, services.VariableService, services.TableService, services.EngineSettingsService, services.ValueAddEventService, services.ConfigSnapshot, services.MetricsReportingService, services.ViewService, services.ExceptionHandlingService, services.ExpressionResultCacheSharable, services.StatementEventTypeRefService, services.TableService.TableExprEvaluatorContext, services.EngineLevelExtensionServicesContext, services.RegexHandlerFactory, services.StatementLockFactory )); }
public static StatementSpecRaw CompilePattern(String expression, String expressionForErrorMessage, bool addPleaseCheck, EPServicesContext services, SelectClauseStreamSelectorEnum defaultStreamSelector) { // Parse ParseResult parseResult = ParseHelper.Parse(expression, expressionForErrorMessage, addPleaseCheck, PatternParseRule, true); var ast = parseResult.Tree; if (Log.IsDebugEnabled) { ASTUtil.DumpAST(ast); } // Walk EPLTreeWalkerListener walker = new EPLTreeWalkerListener( parseResult.TokenStream, services.EngineImportService, services.VariableService, services.SchedulingService, defaultStreamSelector, services.EngineURI, services.ConfigSnapshot, services.PatternNodeFactory, services.ContextManagementService, parseResult.Scripts, services.ExprDeclaredService, services.TableService); try { ParseHelper.Walk(ast, walker, expression, expressionForErrorMessage); } catch (ASTWalkException ex) { Log.Debug(".createPattern Error validating expression", ex); throw new EPStatementException(ex.Message, expression); } catch (EPStatementSyntaxException ex) { throw; } catch (Exception ex) { String message = "Error in expression"; Log.Debug(message, ex); throw new EPStatementException(GetNullableErrortext(message, ex.Message), expression); } var walkerStatementSpec = walker.GetStatementSpec(); if (walkerStatementSpec.StreamSpecs.Count > 1) { throw new IllegalStateException("Unexpected multiple stream specifications encountered"); } // Get pattern specification var patternStreamSpec = (PatternStreamSpecRaw)walkerStatementSpec.StreamSpecs[0]; // Create statement spec, set pattern stream, set wildcard select var statementSpec = new StatementSpecRaw(SelectClauseStreamSelectorEnum.ISTREAM_ONLY); statementSpec.StreamSpecs.Add(patternStreamSpec); statementSpec.SelectClauseSpec.SelectExprList.Clear(); statementSpec.SelectClauseSpec.SelectExprList.Add(new SelectClauseElementWildcard()); statementSpec.Annotations = walkerStatementSpec.Annotations; statementSpec.ExpressionNoAnnotations = parseResult.ExpressionWithoutAnnotations; return(statementSpec); }
public static bool DetermineHasTableAccess(IList <ExprSubselectNode> subselectNodes, StatementSpecRaw statementSpecRaw, EPServicesContext engineServices) { var hasTableAccess = (statementSpecRaw.TableExpressions != null && !statementSpecRaw.TableExpressions.IsEmpty()) || statementSpecRaw.IntoTableSpec != null; hasTableAccess = hasTableAccess || IsJoinWithTable(statementSpecRaw, engineServices.TableService) || IsSubqueryWithTable(subselectNodes, engineServices.TableService) || IsInsertIntoTable(statementSpecRaw, engineServices.TableService); return(hasTableAccess); }
public StatementContext MakeContext( int statementId, string statementName, string expression, StatementType statementType, EPServicesContext engineServices, IDictionary <string, object> optAdditionalContext, bool isFireAndForget, Attribute[] annotations, EPIsolationUnitServices isolationUnitServices, bool stateless, StatementSpecRaw statementSpecRaw, IList <ExprSubselectNode> subselectNodes, bool writesToTables, object statementUserObject) { // Allocate the statement's schedule bucket which stays constant over it's lifetime. // The bucket allows callbacks for the same time to be ordered (within and across statements) and thus deterministic. var scheduleBucket = engineServices.SchedulingMgmtService.AllocateBucket(); // Create a lock for the statement IReaderWriterLock defaultStatementAgentInstanceLock; // For on-delete statements, use the create-named-window statement lock var optCreateWindowDesc = statementSpecRaw.CreateWindowDesc; var optOnTriggerDesc = statementSpecRaw.OnTriggerDesc; if ((optOnTriggerDesc != null) && (optOnTriggerDesc is OnTriggerWindowDesc)) { var windowName = ((OnTriggerWindowDesc)optOnTriggerDesc).WindowName; if (engineServices.TableService.GetTableMetadata(windowName) == null) { defaultStatementAgentInstanceLock = engineServices.NamedWindowMgmtService.GetNamedWindowLock(windowName); if (defaultStatementAgentInstanceLock == null) { throw new EPStatementException("Named window or table '" + windowName + "' has not been declared", expression); } } else { defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock(statementName, annotations, stateless); } } // For creating a named window, save the lock for use with on-delete/on-merge/on-Update etc. statements else if (optCreateWindowDesc != null) { defaultStatementAgentInstanceLock = engineServices.NamedWindowMgmtService.GetNamedWindowLock(optCreateWindowDesc.WindowName); if (defaultStatementAgentInstanceLock == null) { defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock( statementName, annotations, false); engineServices.NamedWindowMgmtService.AddNamedWindowLock( optCreateWindowDesc.WindowName, defaultStatementAgentInstanceLock, statementName); } } else { defaultStatementAgentInstanceLock = engineServices.StatementLockFactory.GetStatementLock( statementName, annotations, stateless); } StatementMetricHandle stmtMetric = null; if (!isFireAndForget) { stmtMetric = engineServices.MetricsReportingService.GetStatementHandle(statementId, statementName); } var annotationData = AnnotationAnalysisResult.AnalyzeAnnotations(annotations); var hasVariables = statementSpecRaw.HasVariables || (statementSpecRaw.CreateContextDesc != null); var hasTableAccess = StatementContextFactoryUtil.DetermineHasTableAccess(subselectNodes, statementSpecRaw, engineServices); var epStatementHandle = new EPStatementHandle( statementId, statementName, expression, statementType, expression, hasVariables, stmtMetric, annotationData.Priority, annotationData.IsPremptive, hasTableAccess, engineServices.MultiMatchHandlerFactory.GetDefaultHandler()); var patternContextFactory = new PatternContextFactoryDefault(); var optionalCreateNamedWindowName = statementSpecRaw.CreateWindowDesc != null ? statementSpecRaw.CreateWindowDesc.WindowName : null; var viewResolutionService = new ViewResolutionServiceImpl( _viewRegistry, optionalCreateNamedWindowName, _systemVirtualDwViewFactory); var patternResolutionService = new PatternObjectResolutionServiceImpl(_patternObjectClasses); var schedulingService = engineServices.SchedulingService; var filterService = engineServices.FilterService; if (isolationUnitServices != null) { filterService = isolationUnitServices.FilterService; schedulingService = isolationUnitServices.SchedulingService; } var scheduleAudit = AuditEnum.SCHEDULE.GetAudit(annotations); if (scheduleAudit != null) { schedulingService = new SchedulingServiceAudit( engineServices.EngineURI, statementName, schedulingService); } StatementAIResourceRegistry statementAgentInstanceRegistry = null; ContextDescriptor contextDescriptor = null; var optionalContextName = statementSpecRaw.OptionalContextName; if (optionalContextName != null) { contextDescriptor = engineServices.ContextManagementService.GetContextDescriptor(optionalContextName); // allocate a per-instance registry of aggregations and prev/prior/subselect if (contextDescriptor != null) { statementAgentInstanceRegistry = contextDescriptor.AiResourceRegistryFactory.Invoke(); } } var countSubexpressions = engineServices.ConfigSnapshot.EngineDefaults.PatternsConfig.MaxSubexpressions != null; PatternSubexpressionPoolStmtSvc patternSubexpressionPoolStmtSvc = null; if (countSubexpressions) { var stmtCounter = new PatternSubexpressionPoolStmtHandler(); patternSubexpressionPoolStmtSvc = new PatternSubexpressionPoolStmtSvc(engineServices.PatternSubexpressionPoolSvc, stmtCounter); engineServices.PatternSubexpressionPoolSvc.AddPatternContext(statementName, stmtCounter); } var countMatchRecogStates = engineServices.ConfigSnapshot.EngineDefaults.MatchRecognizeConfig.MaxStates != null; MatchRecognizeStatePoolStmtSvc matchRecognizeStatePoolStmtSvc = null; if (countMatchRecogStates && statementSpecRaw.MatchRecognizeSpec != null) { var stmtCounter = new MatchRecognizeStatePoolStmtHandler(); matchRecognizeStatePoolStmtSvc = new MatchRecognizeStatePoolStmtSvc(engineServices.MatchRecognizeStatePoolEngineSvc, stmtCounter); engineServices.MatchRecognizeStatePoolEngineSvc.AddPatternContext(statementName, stmtCounter); } AgentInstanceScriptContext defaultAgentInstanceScriptContext = null; if (statementSpecRaw.ScriptExpressions != null && !statementSpecRaw.ScriptExpressions.IsEmpty()) { defaultAgentInstanceScriptContext = new AgentInstanceScriptContext(); } // allow a special context controller factory for testing var contextControllerFactoryService = GetContextControllerFactoryService(annotations); // may use resource tracking var statementResourceService = new StatementResourceService(optionalContextName != null); StatementExtensionSvcContext extensionSvcContext = new ProxyStatementExtensionSvcContext { ProcStmtResources = () => statementResourceService, ProcExtractStatementResourceHolder = resultOfStart => StatementResourceHolderUtil.PopulateHolder(resultOfStart) }; // Create statement context return(new StatementContext( _stmtEngineServices, schedulingService, scheduleBucket, epStatementHandle, viewResolutionService, patternResolutionService, extensionSvcContext, new StatementStopServiceImpl(), patternContextFactory, filterService, new StatementResultServiceImpl( statementName, engineServices.StatementLifecycleSvc, engineServices.MetricsReportingService, engineServices.ThreadingService), engineServices.InternalEventEngineRouteDest, annotations, statementAgentInstanceRegistry, defaultStatementAgentInstanceLock, contextDescriptor, patternSubexpressionPoolStmtSvc, matchRecognizeStatePoolStmtSvc, stateless, contextControllerFactoryService, defaultAgentInstanceScriptContext, AggregationServiceFactoryServiceImpl.DEFAULT_FACTORY, engineServices.ScriptingService, writesToTables, statementUserObject, StatementSemiAnonymousTypeRegistryImpl.INSTANCE, annotationData.Priority)); }
/// <summary>Performs the initialization. </summary> protected void DoInitialize(long?startTime) { Log.Info("Initializing engine URI '{0}' version {1}", URI, Version.VERSION); // This setting applies to all engines in a given VM ExecutionPathDebugLog.IsEnabled = _configSnapshot.EngineDefaults.LoggingConfig.IsEnableExecutionDebug; ExecutionPathDebugLog.IsTimerDebugEnabled = _configSnapshot.EngineDefaults.LoggingConfig.IsEnableTimerDebug; // This setting applies to all engines in a given VM MetricReportingPath.IsMetricsEnabled = _configSnapshot.EngineDefaults.MetricsReportingConfig.IsEnableMetricsReporting; // This setting applies to all engines in a given VM AuditPath.AuditPattern = _configSnapshot.EngineDefaults.LoggingConfig.AuditPattern; // This setting applies to all engines in a given VM ThreadingOption.IsThreadingEnabled = ThreadingOption.IsThreadingEnabled || _configSnapshot.EngineDefaults.ThreadingConfig.IsThreadPoolTimerExec || _configSnapshot.EngineDefaults.ThreadingConfig.IsThreadPoolInbound || _configSnapshot.EngineDefaults.ThreadingConfig.IsThreadPoolRouteExec || _configSnapshot.EngineDefaults.ThreadingConfig.IsThreadPoolOutbound; if (_engine != null) { _engine.Services.TimerService.StopInternalClock(false); // Give the timer thread a little moment to catch up Thread.Sleep(100); _engine.Runtime.Initialize(); _engine.Services.Dispose(); } // Make EP services context factory String epServicesContextFactoryClassName = _configSnapshot.EPServicesContextFactoryClassName; EPServicesContextFactory epServicesContextFactory; if (epServicesContextFactoryClassName == null) { // Check system properties epServicesContextFactoryClassName = Environment.GetEnvironmentVariable("ESPER_EPSERVICE_CONTEXT_FACTORY_CLASS"); } if (epServicesContextFactoryClassName == null) { epServicesContextFactory = new EPServicesContextFactoryDefault(); } else { Type clazz; try { clazz = TypeHelper.ResolveType(epServicesContextFactoryClassName, true); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + epServicesContextFactoryClassName + "' cannot be loaded"); } Object obj; try { obj = Activator.CreateInstance(clazz); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated"); } catch (MissingMethodException e) { throw new ConfigurationException( "Error instantiating class - Default constructor was not found", e); } catch (MethodAccessException e) { throw new ConfigurationException( "Error instantiating class - Caller does not have permission to use constructor", e); } catch (ArgumentException e) { throw new ConfigurationException("Error instantiating class - Type is not a RuntimeType", e); } epServicesContextFactory = (EPServicesContextFactory)obj; } EPServicesContext services = epServicesContextFactory.CreateServicesContext(this, _configSnapshot); // New runtime EPRuntimeSPI runtimeSPI; InternalEventRouteDest routeDest; TimerCallback timerCallback; String runtimeClassName = _configSnapshot.EngineDefaults.AlternativeContextConfig.Runtime; if (runtimeClassName == null) { // Check system properties runtimeClassName = Environment.GetEnvironmentVariable("ESPER_EPRUNTIME_CLASS"); } if (runtimeClassName == null) { EPRuntimeImpl runtimeImpl = new EPRuntimeImpl(services); runtimeSPI = runtimeImpl; routeDest = runtimeImpl; timerCallback = runtimeImpl.TimerCallback; } else { Type clazz; try { clazz = TypeHelper.ResolveType(runtimeClassName, true); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + runtimeClassName + "' cannot be loaded"); } Object obj; try { ConstructorInfo c = clazz.GetConstructor(new[] { typeof(EPServicesContext) }); obj = c.Invoke(new object[] { services }); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated"); } catch (MissingMethodException) { throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated, constructor accepting services was not found"); } catch (MethodAccessException) { throw new ConfigurationException("Illegal access instantiating class '" + clazz + "'"); } runtimeSPI = (EPRuntimeSPI)obj; routeDest = (InternalEventRouteDest)obj; timerCallback = (TimerCallback)obj; } routeDest.InternalEventRouter = services.InternalEventRouter; services.InternalEventEngineRouteDest = routeDest; // set current time, if applicable if (startTime != null) { services.SchedulingService.Time = startTime.Value; } // Configure services to use the new runtime services.TimerService.Callback = timerCallback; // Statement lifecycle init services.StatementLifecycleSvc.Init(); // Filter service init services.FilterService.Init(); // Schedule service init services.SchedulingService.Init(); // New admin var configOps = new ConfigurationOperationsImpl( services.EventAdapterService, services.EventTypeIdGenerator, services.EngineImportService, services.VariableService, services.EngineSettingsService, services.ValueAddEventService, services.MetricsReportingService, services.StatementEventTypeRefService, services.StatementVariableRefService, services.PlugInViews, services.FilterService, services.PatternSubexpressionPoolSvc, services.MatchRecognizeStatePoolEngineSvc, services.TableService); var defaultStreamSelector = _configSnapshot.EngineDefaults.StreamSelectionConfig.DefaultStreamSelector.MapFromSODA(); EPAdministratorSPI adminSPI; var adminClassName = _configSnapshot.EngineDefaults.AlternativeContextConfig.Admin; var adminContext = new EPAdministratorContext(runtimeSPI, services, configOps, defaultStreamSelector); if (adminClassName == null) { // Check system properties adminClassName = Environment.GetEnvironmentVariable("ESPER_EPADMIN_CLASS"); } if (adminClassName == null) { adminSPI = new EPAdministratorImpl(adminContext); } else { Type clazz; try { clazz = TypeHelper.ResolveType(adminClassName, true); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + epServicesContextFactoryClassName + "' cannot be loaded"); } Object obj; try { ConstructorInfo c = clazz.GetConstructor(new[] { typeof(EPAdministratorContext) }); obj = c.Invoke(new[] { adminContext }); } catch (TypeLoadException) { throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated"); } catch (MissingMethodException) { throw new ConfigurationException("Class '" + clazz + "' cannot be instantiated, constructor accepting context was not found"); } catch (MethodAccessException) { throw new ConfigurationException("Illegal access instantiating class '" + clazz + "'"); } adminSPI = (EPAdministratorSPI)obj; } // Start clocking if (_configSnapshot.EngineDefaults.ThreadingConfig.IsInternalTimerEnabled) { services.TimerService.StartInternalClock(); } // Give the timer thread a little moment to start up Thread.Sleep(100); // Save engine instance _engine = new EPServiceEngine(services, runtimeSPI, adminSPI); // Load and initialize adapter loader classes LoadAdapters(services); // Initialize extension services if (services.EngineLevelExtensionServicesContext != null) { services.EngineLevelExtensionServicesContext.Init(services, runtimeSPI, adminSPI); } // Start metrics reporting, if any if (_configSnapshot.EngineDefaults.MetricsReportingConfig.IsEnableMetricsReporting) { services.MetricsReportingService.SetContext(runtimeSPI, services); } // register with the statement lifecycle service services.StatementLifecycleSvc.LifecycleEvent += HandleLifecycleEvent; // call initialize listeners try { if (ServiceInitialized != null) { ServiceInitialized(this, new ServiceProviderEventArgs(this)); } } catch (Exception ex) { Log.Error("Runtime exception caught during an ServiceInitialized event:" + ex.Message, ex); } }
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); }
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); }
/// <summary> /// Set the engine service context. /// </summary> /// <param name="epServicesContext">services context</param> public void SetEpServicesContext(EPServicesContext epServicesContext) { _epServicesContext = epServicesContext; }
public EPContextPartitionAdminImpl(EPServicesContext services) { _services = services; }
/// <summary>Destroys an engine instance. </summary> public void Dispose() { _services = null; _configurationOperations = null; }
public EPServiceEngine(EPServicesContext services, EPRuntimeSPI runtimeSPI, EPAdministratorSPI admin) { Services = services; Runtime = runtimeSPI; Admin = admin; }