Пример #1
0
        public AgentInstanceContext(
            StatementContext statementContext,
            EPStatementAgentInstanceHandle epStatementAgentInstanceHandle,
            int agentInstanceId,
            AgentInstanceFilterProxy agentInstanceFilterProxy,
            MappedEventBean agentInstanceProperties,
            AgentInstanceScriptContext agentInstanceScriptContext)
        {
            StatementContext = statementContext;
            EpStatementAgentInstanceHandle = epStatementAgentInstanceHandle;
            AgentInstanceId            = agentInstanceId;
            AgentInstanceFilterProxy   = agentInstanceFilterProxy;
            _agentInstanceProperties   = agentInstanceProperties;
            AgentInstanceScriptContext = agentInstanceScriptContext;

            if (statementContext.IsStatelessSelect)
            {
                ExpressionResultCacheService = statementContext.ExpressionResultCacheServiceSharable;
            }
            else
            {
                ExpressionResultCacheService = new ExpressionResultCacheServiceAgentInstance();
            }

            _terminationCallbacks = null;
        }
Пример #2
0
 public ContextAgentInstanceInfo(
     MappedEventBean contextProperties,
     AgentInstanceFilterProxy filterProxy)
 {
     ContextProperties = contextProperties;
     FilterProxy = filterProxy;
 }
Пример #3
0
        private static AgentInstanceContext MakeNewAgentInstanceContextCanNull(
            int agentInstanceId,
            StatementContext statementContext,
            bool partitioned)
        {
            // re-allocate lock: for unpartitoned cases we use the same lock associated to the statement (no need to produce more locks)
            var @lock = statementContext.StatementAIFactoryProvider.Factory
                .ObtainAgentInstanceLock(statementContext, agentInstanceId);
            var epStatementAgentInstanceHandle = new EPStatementAgentInstanceHandle(
                statementContext.EpStatementHandle,
                agentInstanceId,
                @lock);

            // filter fault handler for create-context statements
            var contextName = statementContext.ContextName;
            MappedEventBean contextProperties = null;
            AgentInstanceFilterProxy agentInstanceFilterProxy = null;
            if (contextName != null) {
                var contextDeploymentId = statementContext.ContextRuntimeDescriptor.ContextDeploymentId;
                var contextManager =
                    statementContext.ContextManagementService.GetContextManager(contextDeploymentId, contextName);
                epStatementAgentInstanceHandle.FilterFaultHandler = contextManager;

                // the context partition may have been deleted
                var info = contextManager.GetContextAgentInstanceInfo(
                    statementContext,
                    agentInstanceId);
                if (info == null) {
                    return null;
                }

                agentInstanceFilterProxy = info.FilterProxy;
                contextProperties = info.ContextProperties;
            }

            // re-allocate context
            var auditProvider = statementContext.StatementInformationals.AuditProvider;
            var instrumentationProvider =
                statementContext.StatementInformationals.InstrumentationProvider;
            return new AgentInstanceContext(
                statementContext,
                agentInstanceId,
                epStatementAgentInstanceHandle,
                agentInstanceFilterProxy,
                contextProperties,
                auditProvider,
                instrumentationProvider);
        }
Пример #4
0
 public AgentInstanceContext(
     StatementContext statementContext,
     EPStatementAgentInstanceHandle epStatementAgentInstanceHandle,
     int agentInstanceId,
     AgentInstanceFilterProxy agentInstanceFilterProxy,
     MappedEventBean agentInstanceProperties,
     AgentInstanceScriptContext agentInstanceScriptContext)
 {
     StatementContext = statementContext;
     EpStatementAgentInstanceHandle = epStatementAgentInstanceHandle;
     AgentInstanceId                    = agentInstanceId;
     AgentInstanceFilterProxy           = agentInstanceFilterProxy;
     _agentInstanceProperties           = agentInstanceProperties;
     AllocateAgentInstanceScriptContext = agentInstanceScriptContext;
     _terminationCallbacks              = null;
 }
Пример #5
0
 public AgentInstanceContext(
     StatementContext statementContext,
     EPStatementAgentInstanceHandle epStatementAgentInstanceHandle,
     AgentInstanceFilterProxy agentInstanceFilterProxy,
     MappedEventBean contextProperties,
     AuditProvider auditProvider,
     InstrumentationCommon instrumentationProvider)
 {
     StatementContext = statementContext;
     FilterVersionAfterAllocation = statementContext.FilterService.FiltersVersion;
     EpStatementAgentInstanceHandle = epStatementAgentInstanceHandle;
     AgentInstanceFilterProxy = agentInstanceFilterProxy;
     _contextProperties = contextProperties;
     AuditProvider = auditProvider;
     InstrumentationProvider = instrumentationProvider;
 }
Пример #6
0
 public static AgentInstance StartStatement(
     StatementContextRuntimeServices services,
     int assignedContextId,
     ContextControllerStatementDesc statementDesc,
     MappedEventBean contextBean,
     AgentInstanceFilterProxy proxy)
 {
     var result = AgentInstanceUtil.Start(
         services,
         statementDesc,
         assignedContextId,
         contextBean,
         proxy,
         false);
     return new AgentInstance(result.StopCallback, result.AgentInstanceContext, result.FinalView);
 }
        public static StatementAgentInstanceFactoryResult Start(EPServicesContext servicesContext, ContextControllerStatementBase statement, bool isSingleInstanceContext, int agentInstanceId, MappedEventBean agentInstanceProperties, AgentInstanceFilterProxy agentInstanceFilterProxy, bool isRecoveringResilient)
        {
            var statementContext = statement.StatementContext;

            // for on-trigger statements against named windows we must use the named window lock
            OnTriggerDesc optOnTriggerDesc = statement.StatementSpec.OnTriggerDesc;
            String        namedWindowName  = null;

            if ((optOnTriggerDesc != null) && (optOnTriggerDesc is OnTriggerWindowDesc))
            {
                String windowName = ((OnTriggerWindowDesc)optOnTriggerDesc).WindowName;
                if (servicesContext.TableService.GetTableMetadata(windowName) == null)
                {
                    namedWindowName = windowName;
                }
            }

            // determine lock to use
            IReaderWriterLock agentInstanceLock;

            if (namedWindowName != null)
            {
                NamedWindowProcessor         processor = servicesContext.NamedWindowMgmtService.GetProcessor(namedWindowName);
                NamedWindowProcessorInstance instance  = processor.GetProcessorInstance(agentInstanceId);
                agentInstanceLock = instance.RootViewInstance.AgentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock;
            }
            else
            {
                if (isSingleInstanceContext)
                {
                    agentInstanceLock = statementContext.DefaultAgentInstanceLock;
                }
                else
                {
                    agentInstanceLock = servicesContext.StatementLockFactory.GetStatementLock(
                        statementContext.StatementName, statementContext.Annotations, statementContext.IsStatelessSelect);
                }
            }

            // share the filter version between agent instance handle (callbacks) and agent instance context
            var filterVersion = new StatementAgentInstanceFilterVersion();

            // create handle that comtains lock for use in scheduling and filter callbacks
            var agentInstanceHandle = new EPStatementAgentInstanceHandle(statementContext.EpStatementHandle, agentInstanceLock, agentInstanceId, filterVersion, statementContext.FilterFaultHandlerFactory);

            // create agent instance context
            AgentInstanceScriptContext agentInstanceScriptContext = null;

            if (statementContext.DefaultAgentInstanceScriptContext != null)
            {
                agentInstanceScriptContext = AgentInstanceScriptContext.From(statementContext.EventAdapterService);
            }
            var agentInstanceContext       = new AgentInstanceContext(statementContext, agentInstanceHandle, agentInstanceId, agentInstanceFilterProxy, agentInstanceProperties, agentInstanceScriptContext);
            var statementAgentInstanceLock = agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock;

            using (Instrument.With(
                       i => i.QContextPartitionAllocate(agentInstanceContext),
                       i => i.AContextPartitionAllocate()))
            {
                using (statementAgentInstanceLock.AcquireWriteLock())
                {
                    try
                    {
                        // start
                        var startResult = statement.Factory.NewContext(agentInstanceContext, isRecoveringResilient);

                        // hook up with listeners+subscribers
                        startResult.FinalView.AddView(statement.MergeView); // hook output to merge view

                        // assign agents for expression-node based strategies
                        var aiExprSvc        = statementContext.StatementAgentInstanceRegistry.AgentInstanceExprService;
                        var aiAggregationSvc =
                            statementContext.StatementAgentInstanceRegistry.AgentInstanceAggregationService;

                        // allocate aggregation service
                        if (startResult.OptionalAggegationService != null)
                        {
                            aiAggregationSvc.AssignService(agentInstanceId, startResult.OptionalAggegationService);
                        }

                        // allocate subquery
                        foreach (var item in startResult.SubselectStrategies)
                        {
                            var node           = item.Key;
                            var strategyHolder = item.Value;

                            aiExprSvc.GetSubselectService(node).AssignService(agentInstanceId, strategyHolder.Stategy);
                            aiExprSvc.GetSubselectAggregationService(node)
                            .AssignService(agentInstanceId, strategyHolder.SubselectAggregationService);

                            // allocate prior within subquery
                            foreach (var priorEntry in strategyHolder.PriorStrategies)
                            {
                                aiExprSvc.GetPriorServices(priorEntry.Key).AssignService(agentInstanceId, priorEntry.Value);
                            }

                            // allocate previous within subquery
                            foreach (var prevEntry in strategyHolder.PreviousNodeStrategies)
                            {
                                aiExprSvc.GetPreviousServices(prevEntry.Key)
                                .AssignService(agentInstanceId, prevEntry.Value);
                            }
                        }

                        // allocate prior-expressions
                        foreach (var item in startResult.PriorNodeStrategies)
                        {
                            aiExprSvc.GetPriorServices(item.Key).AssignService(agentInstanceId, item.Value);
                        }

                        // allocate previous-expressions
                        foreach (var item in startResult.PreviousNodeStrategies)
                        {
                            aiExprSvc.GetPreviousServices(item.Key).AssignService(agentInstanceId, item.Value);
                        }

                        // allocate match-recognize previous expressions
                        var regexExprPreviousEvalStrategy = startResult.RegexExprPreviousEvalStrategy;
                        aiExprSvc.GetMatchRecognizePrevious().AssignService(agentInstanceId, regexExprPreviousEvalStrategy);

                        // allocate table-access-expressions
                        foreach (var item in startResult.TableAccessEvalStrategies)
                        {
                            aiExprSvc.GetTableAccessServices(item.Key).AssignService(agentInstanceId, item.Value);
                        }

                        // execute preloads, if any
                        foreach (var preload in startResult.PreloadList)
                        {
                            preload.ExecutePreload(agentInstanceContext);
                        }

                        if (statementContext.StatementExtensionServicesContext != null &&
                            statementContext.StatementExtensionServicesContext.StmtResources != null)
                        {
                            var holder = statementContext.StatementExtensionServicesContext.ExtractStatementResourceHolder(startResult);
                            statementContext.StatementExtensionServicesContext.StmtResources.SetPartitioned(agentInstanceId, holder);
                        }

                        // instantiate
                        return(startResult);
                    }
                    finally
                    {
                        if (agentInstanceContext.StatementContext.EpStatementHandle.HasTableAccess)
                        {
                            agentInstanceContext.TableExprEvaluatorContext.ReleaseAcquiredLocks();
                        }
                    }
                }
            }
        }
Пример #8
0
        public static StatementAgentInstanceFactoryResult Start(
            StatementContextRuntimeServices services,
            ContextControllerStatementDesc statement,
            int agentInstanceId,
            MappedEventBean contextProperties,
            AgentInstanceFilterProxy agentInstanceFilterProxy,
            bool isRecoveringResilient)
        {
            var statementContext = statement.Lightweight.StatementContext;

            // create handle that comtains lock for use in scheduling and filter callbacks
            var @lock =
                statementContext.StatementAIFactoryProvider.Factory.ObtainAgentInstanceLock(
                    statementContext,
                    agentInstanceId);
            var agentInstanceHandle =
                new EPStatementAgentInstanceHandle(statementContext.EpStatementHandle, agentInstanceId, @lock);

            var auditProvider = statementContext.StatementInformationals.AuditProvider;
            var instrumentationProvider =
                statementContext.StatementInformationals.InstrumentationProvider;
            var agentInstanceContext = new AgentInstanceContext(
                statementContext,
                agentInstanceHandle,
                agentInstanceFilterProxy,
                contextProperties,
                auditProvider,
                instrumentationProvider);
            if (agentInstanceId != -1) {
                agentInstanceContext.AuditProvider.ContextPartition(true, agentInstanceContext);
            }

            var statementAgentInstanceLock =
                agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock;

            agentInstanceContext.InstrumentationProvider.QContextPartitionAllocate(agentInstanceContext);

            using (statementAgentInstanceLock.AcquireWriteLock()) {
                try {
                    // start
                    var startResult =
                        statement.Lightweight.StatementProvider.StatementAIFactoryProvider.Factory.NewContext(
                            agentInstanceContext,
                            isRecoveringResilient);

                    // hook up with listeners+subscribers
                    startResult.FinalView.Child = statement.ContextMergeView; // hook output to merge view

                    // assign agents for expression-node based strategies
                    var aiResourceRegistry = statementContext.StatementAIResourceRegistry;
                    AIRegistryUtil.AssignFutures(
                        aiResourceRegistry,
                        agentInstanceId,
                        startResult.OptionalAggegationService,
                        startResult.PriorStrategies,
                        startResult.PreviousGetterStrategies,
                        startResult.SubselectStrategies,
                        startResult.TableAccessStrategies,
                        startResult.RowRecogPreviousStrategy);

                    // execute preloads, if any
                    if (startResult.PreloadList != null) {
                        foreach (var preload in startResult.PreloadList) {
                            preload.ExecutePreload();
                        }
                    }
                    
                    // handle any pattern-match-event that was produced during startup, relevant for "timer:interval(0)" in conjunction with contexts
                    startResult.PostContextMergeRunnable?.Invoke();

                    var holder =
                        services.StatementResourceHolderBuilder.Build(agentInstanceContext, startResult);
                    statementContext.StatementCPCacheService.StatementResourceService.SetPartitioned(
                        agentInstanceId,
                        holder);

                    // instantiated
                    return startResult;
                }
                finally {
                    if (agentInstanceContext.StatementContext.EpStatementHandle.HasTableAccess) {
                        agentInstanceContext.TableExprEvaluatorContext.ReleaseAcquiredLocks();
                    }

                    agentInstanceContext.InstrumentationProvider.AContextPartitionAllocate();
                }
            }
        }