コード例 #1
0
        public void ActivateVariable(
            string name,
            DataInputOutputSerde serde)
        {
            var variable = ModuleIncidentals.Variables.Get(name);
            if (variable == null) {
                throw new ArgumentException("Failed to find variable information for '" + name + "'");
            }

            string contextDeploymentId = null;
            if (variable.OptionalContextName != null) {
                contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId(
                    variable.OptionalContextModule,
                    variable.OptionalContextVisibility,
                    variable.OptionalContextName,
                    DeploymentId, ServicesContext.ContextPathRegistry);
            }

            ServicesContext.VariableManagementService.AddVariable(DeploymentId, variable, contextDeploymentId, serde);

            // for non-context variables we allocate the state
            if (contextDeploymentId == null) {
                ServicesContext.VariableManagementService.AllocateVariableState(
                    DeploymentId, name, DEFAULT_AGENT_INSTANCE_ID, IsRecovery, null, ServicesContext.EventBeanTypedEventFactory);
            }
        }
コード例 #2
0
        private static StatementLightweight InitStatement(
            bool recovery,
            string moduleName,
            StatementProvider statementProvider,
            string deploymentId,
            int statementId,
            EventTypeResolver eventTypeResolver,
            ModuleIncidentals moduleIncidentals,
            StatementNameRuntimeOption statementNameResolverRuntime,
            StatementUserObjectRuntimeOption userObjectResolverRuntime,
            ClassLoader moduleClassLoader,
            EPServicesContext services)
        {
            var informationals = statementProvider.Informationals;

            // set instrumentation unless already provided
            if (informationals.InstrumentationProvider == null)
            {
                informationals.InstrumentationProvider = InstrumentationDefault.INSTANCE;
            }

            var statementResultService = new StatementResultServiceImpl(informationals, services);
            FilterSharedLookupableRegistery filterSharedLookupableRegistery = new ProxyFilterSharedLookupableRegistery()
            {
                ProcRegisterLookupable = (
                    eventTypeX,
                    lookupable) => {
                    services.FilterSharedLookupableRepository.RegisterLookupable(statementId, eventTypeX, lookupable);
                },
            };

            FilterSharedBoolExprRegistery filterSharedBoolExprRegistery = new ProxyFilterSharedBoolExprRegistery()
            {
                ProcRegisterBoolExpr = (node) => { services.FilterSharedBoolExprRepository.RegisterBoolExpr(statementId, node); },
            };

            IDictionary <int, FilterSpecActivatable> filterSpecActivatables        = new Dictionary <int, FilterSpecActivatable>();
            FilterSpecActivatableRegistry            filterSpecActivatableRegistry = new ProxyFilterSpecActivatableRegistry()
            {
                ProcRegister = (filterSpecActivatable) => { filterSpecActivatables.Put(filterSpecActivatable.FilterCallbackId, filterSpecActivatable); },
            };

            var contextPartitioned       = informationals.OptionalContextName != null;
            var statementResourceService = new StatementResourceService(contextPartitioned);

            // determine statement name
            var statementName = informationals.StatementNameCompileTime;

            if (statementNameResolverRuntime != null)
            {
                string statementNameAssigned = statementNameResolverRuntime.Invoke(
                    new StatementNameRuntimeContext(
                        deploymentId,
                        statementName,
                        statementId,
                        (string)informationals.Properties.Get(StatementProperty.EPL),
                        informationals.Annotations));
                if (statementNameAssigned != null)
                {
                    statementName = statementNameAssigned;
                }
            }

            statementName = statementName.Trim();

            var epInitServices = new EPStatementInitServicesImpl(
                statementName,
                informationals.Properties,
                informationals.Annotations,
                deploymentId,
                eventTypeResolver,
                filterSpecActivatableRegistry,
                filterSharedBoolExprRegistery,
                filterSharedLookupableRegistery,
                moduleIncidentals,
                recovery,
                statementResourceService,
                statementResultService,
                services);

            if (!services.EpServicesHA.RuntimeExtensionServices.IsHAEnabled)
            {
                statementProvider.Initialize(epInitServices);
            }
            else
            {
                // for HA we set the context classloader as state may be loaded considering the module provider's classloader
                // - NEsper doesn't support HA like this, and we wouldn't want to deliver this information in
                // - this manner.  An alternative delivery mechanism must be established to carry the information
                // - without relying on the "current" thread to carry that detail.

                // ClassLoader originalClassLoader = Thread.CurrentThread().ContextClassLoader;
                // try {
                //  Thread.CurrentThread().ContextClassLoader = moduleClassLoader;
                //  statementProvider.Initialize(epInitServices);
                // }
                // finally {
                //  Thread.CurrentThread().ContextClassLoader = originalClassLoader;
                // }
            }

            var multiMatchHandler = services.MultiMatchHandlerFactory.Make(informationals.HasSubquery, informationals.IsNeedDedup);

            var stmtMetric = services.MetricReportingService.GetStatementHandle(statementId, deploymentId, statementName);

            var optionalEPL = (string)informationals.Properties.Get(StatementProperty.EPL);
            InsertIntoLatchFactory insertIntoFrontLatchFactory = null;
            InsertIntoLatchFactory insertIntoBackLatchFactory  = null;

            if (informationals.InsertIntoLatchName != null)
            {
                var latchFactoryNameBack  = "insert_stream_B_" + informationals.InsertIntoLatchName + "_" + statementName;
                var latchFactoryNameFront = "insert_stream_F_" + informationals.InsertIntoLatchName + "_" + statementName;
                var msecTimeout           = services.RuntimeSettingsService.ConfigurationRuntime.Threading.InsertIntoDispatchTimeout;
                var locking           = services.RuntimeSettingsService.ConfigurationRuntime.Threading.InsertIntoDispatchLocking;
                var latchFactoryFront = new InsertIntoLatchFactory(
                    latchFactoryNameFront,
                    informationals.IsStateless,
                    msecTimeout,
                    locking,
                    services.TimeSourceService);
                var latchFactoryBack = new InsertIntoLatchFactory(
                    latchFactoryNameBack,
                    informationals.IsStateless,
                    msecTimeout,
                    locking,
                    services.TimeSourceService);
                insertIntoFrontLatchFactory = latchFactoryFront;
                insertIntoBackLatchFactory  = latchFactoryBack;
            }

            var statementHandle = new EPStatementHandle(
                statementName,
                deploymentId,
                statementId,
                optionalEPL,
                informationals.Priority,
                informationals.IsPreemptive,
                informationals.IsCanSelfJoin,
                multiMatchHandler,
                informationals.HasVariables,
                informationals.HasTableAccess,
                stmtMetric,
                insertIntoFrontLatchFactory,
                insertIntoBackLatchFactory);

            // determine context
            StatementAIResourceRegistry statementAgentInstanceRegistry = null;
            ContextRuntimeDescriptor    contextRuntimeDescriptor       = null;
            var optionalContextName = informationals.OptionalContextName;

            if (optionalContextName != null)
            {
                var contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId(
                    informationals.OptionalContextModuleName,
                    informationals.OptionalContextVisibility,
                    optionalContextName,
                    deploymentId,
                    services.ContextPathRegistry);
                var contextManager = services.ContextManagementService.GetContextManager(contextDeploymentId, optionalContextName);
                contextRuntimeDescriptor = contextManager.ContextRuntimeDescriptor;
                var registryRequirements = statementProvider.StatementAIFactoryProvider.Factory.RegistryRequirements;
                statementAgentInstanceRegistry = contextManager.AllocateAgentInstanceResourceRegistry(registryRequirements);
            }

            var statementCPCacheService = new StatementCPCacheService(
                contextPartitioned,
                statementResourceService,
                statementAgentInstanceRegistry);

            var eventType = statementProvider.StatementAIFactoryProvider.Factory.StatementEventType;

            var configurationThreading = services.RuntimeSettingsService.ConfigurationRuntime.Threading;
            var preserveDispatchOrder  = configurationThreading.IsListenerDispatchPreserveOrder && !informationals.IsStateless;
            var isSpinLocks            = configurationThreading.ListenerDispatchLocking == Locking.SPIN;
            var msecBlockingTimeout    = configurationThreading.ListenerDispatchTimeout;
            UpdateDispatchViewBase dispatchChildView;

            if (preserveDispatchOrder)
            {
                if (isSpinLocks)
                {
                    dispatchChildView = new UpdateDispatchViewBlockingSpin(
                        eventType,
                        statementResultService,
                        services.DispatchService,
                        msecBlockingTimeout,
                        services.TimeSourceService);
                }
                else
                {
                    dispatchChildView = new UpdateDispatchViewBlockingWait(eventType, statementResultService, services.DispatchService, msecBlockingTimeout);
                }
            }
            else
            {
                dispatchChildView = new UpdateDispatchViewNonBlocking(eventType, statementResultService, services.DispatchService);
            }

            var countSubexpressions = services.ConfigSnapshot.Runtime.Patterns.MaxSubexpressions != null;
            PatternSubexpressionPoolStmtSvc patternSubexpressionPoolStmtSvc = null;

            if (countSubexpressions)
            {
                var stmtCounter = new PatternSubexpressionPoolStmtHandler();
                patternSubexpressionPoolStmtSvc = new PatternSubexpressionPoolStmtSvc(services.PatternSubexpressionPoolRuntimeSvc, stmtCounter);
                services.PatternSubexpressionPoolRuntimeSvc.AddPatternContext(statementId, statementName, stmtCounter);
            }

            var countMatchRecogStates = services.ConfigSnapshot.Runtime.MatchRecognize.MaxStates != null;
            RowRecogStatePoolStmtSvc rowRecogStatePoolStmtSvc = null;

            if (countMatchRecogStates && informationals.HasMatchRecognize)
            {
                var stmtCounter = new RowRecogStatePoolStmtHandler();
                rowRecogStatePoolStmtSvc = new RowRecogStatePoolStmtSvc(services.RowRecogStatePoolEngineSvc, stmtCounter);
                services.RowRecogStatePoolEngineSvc.AddPatternContext(new DeploymentIdNamePair(deploymentId, statementName), stmtCounter);
            }

            // get user object for runtime
            object userObjectRuntime = null;

            if (userObjectResolverRuntime != null)
            {
                userObjectRuntime = userObjectResolverRuntime.GetUserObject(
                    new StatementUserObjectRuntimeContext(
                        deploymentId,
                        statementName,
                        statementId,
                        (string)informationals.Properties.Get(StatementProperty.EPL),
                        informationals.Annotations));
            }

            var statementContext = new StatementContext(
                services.Container,
                contextRuntimeDescriptor,
                deploymentId,
                statementId,
                statementName,
                moduleName,
                informationals,
                userObjectRuntime,
                services.StatementContextRuntimeServices,
                statementHandle,
                filterSpecActivatables,
                patternSubexpressionPoolStmtSvc,
                rowRecogStatePoolStmtSvc,
                new ScheduleBucket(statementId),
                statementAgentInstanceRegistry,
                statementCPCacheService,
                statementProvider.StatementAIFactoryProvider,
                statementResultService,
                dispatchChildView,
                services.FilterService,
                services.SchedulingService,
                services.InternalEventRouteDest
                );

            foreach (var readyCallback in epInitServices.ReadyCallbacks)
            {
                readyCallback.Ready(statementContext, moduleIncidentals, recovery);
            }

            return(new StatementLightweight(statementProvider, informationals, statementResultService, statementContext));
        }
コード例 #3
0
        private static EPStatementSPI DeployStatement(
            bool recovery,
            StatementLightweight lightweight,
            EPRuntimeSPI epRuntime)
        {
            // statement-create: safe operation for registering things
            var statementAgentInstanceFactory = lightweight.StatementContext.StatementAIFactoryProvider.Factory;

            statementAgentInstanceFactory.StatementCreate(lightweight.StatementContext);

            // add statement
            var stmt = MakeStatement(
                lightweight.StatementContext.UpdateDispatchView,
                lightweight.StatementContext,
                (StatementResultServiceImpl)lightweight.StatementResultService,
                epRuntime);

            // add statement to globals
            epRuntime.ServicesContext.StatementLifecycleService.AddStatement(stmt);             // it is now available for lookup

            Viewable finalView;
            StatementDestroyCallback statementDestroyCallback;
            ICollection <StatementAgentInstancePreload> preloads = null;
            var contextName = lightweight.StatementInformationals.OptionalContextName;

            if (contextName == null)
            {
                var result = StartStatementNoContext(lightweight, recovery, epRuntime.ServicesContext);
                finalView = result.FinalView;
                preloads  = result.PreloadList;
                var createContextStmt = result is StatementAgentInstanceFactoryCreateContextResult;
                statementDestroyCallback = new ProxyStatementDestroyCallback()
                {
                    ProcDestroy = (
                        destroyServices,
                        statementContext) => {
                        // All statements other that create-context: get the agent-instance-context and stop
                        // Create-context statements already got destroyed when the last statement associated to context was removed.
                        if (!createContextStmt)
                        {
                            var holder = statementContext.StatementCPCacheService.MakeOrGetEntryCanNull(-1, statementContext);
                            holder.AgentInstanceStopCallback.Stop(new AgentInstanceStopServices(holder.AgentInstanceContext));
                        }

                        // Invoke statement-destroy
                        statementAgentInstanceFactory.StatementDestroy(lightweight.StatementContext);
                    },
                };

                // assign
                StatementAIFactoryAssignments assignments = new StatementAIFactoryAssignmentsImpl(
                    result.OptionalAggegationService,
                    result.PriorStrategies,
                    result.PreviousGetterStrategies,
                    result.SubselectStrategies,
                    result.TableAccessStrategies,
                    result.RowRecogPreviousStrategy);
                lightweight.StatementContext.StatementAIFactoryProvider.Assign(assignments);
            }
            else
            {
                var contextModuleName           = lightweight.StatementInformationals.OptionalContextModuleName;
                var statementAIResourceRegistry = lightweight.StatementContext.StatementAIResourceRegistry;

                var contextVisibility   = lightweight.StatementInformationals.OptionalContextVisibility;
                var contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId(
                    contextModuleName,
                    contextVisibility,
                    contextName,
                    lightweight.StatementContext.DeploymentId,
                    lightweight.StatementContext.PathContextRegistry);

                var contextMergeView = lightweight.StatementInformationals.StatementType.IsOnTriggerInfra()
                                        ? new ContextMergeViewForwarding(null)
                                        : new ContextMergeView(null);
                finalView = contextMergeView;
                var statement = new ContextControllerStatementDesc(lightweight, contextMergeView);

                // assignments before add-statement, since add-statement creates context partitions which may preload
                lightweight.StatementContext.StatementAIFactoryProvider.Assign(new StatementAIFactoryAssignmentContext(statementAIResourceRegistry));

                // add statement
                epRuntime.ServicesContext.ContextManagementService.AddStatement(contextDeploymentId, contextName, statement, recovery);
                statementDestroyCallback = new ProxyStatementDestroyCallback()
                {
                    ProcDestroy = (
                        destroyServices,
                        statementContext) => {
                        var ctx = statement.Lightweight.StatementContext;
                        epRuntime.ServicesContext.ContextManagementService.StoppedStatement(
                            contextDeploymentId,
                            contextName,
                            ctx.StatementId,
                            ctx.StatementName,
                            ctx.DeploymentId);
                        statementAgentInstanceFactory.StatementDestroy(lightweight.StatementContext);
                    },
                };
            }

            // make dispatch view
            finalView.Child = lightweight.StatementContext.UpdateDispatchView;

            // assign parent view
            stmt.StatementContext.DestroyCallback = statementDestroyCallback;
            stmt.ParentView = finalView;

            // execute preloads
            if (preloads != null)
            {
                foreach (var preload in preloads)
                {
                    preload.ExecutePreload();
                }
            }

            return(stmt);
        }