Example #1
0
 public ICollection <int> GetAgentInstanceIds(ContextPartitionSelector selector)
 {
     if (selector is ContextPartitionSelectorById)
     {
         var byId = (ContextPartitionSelectorById)selector;
         var ids  = byId.ContextPartitionIds;
         if (ids == null || ids.IsEmpty())
         {
             return(Collections.GetEmptyList <int>());
         }
         var agentInstanceIds = new List <int>(ids);
         agentInstanceIds.RetainAll(_agentInstances.Keys);
         return(agentInstanceIds);
     }
     else if (selector is ContextPartitionSelectorAll)
     {
         return(new List <int>(_agentInstances.Keys));
     }
     else
     {
         var visitor = new ContextPartitionVisitorAgentInstanceId(1);
         _rootContext.VisitSelectedPartitions(selector, visitor);
         return(visitor.AgentInstanceIds);
     }
 }
Example #2
0
        public EPContextPartitionExtract ExtractPaths(String contextName, ContextPartitionSelector selector)
        {
            ContextManager             contextManager = CheckedGetContextManager(contextName);
            ContextStatePathDescriptor contextPaths   = contextManager.ExtractPaths(selector);

            return(DescriptorToExtract(contextManager.NumNestingLevels, contextPaths));
        }
        public EPContextPartitionExtract ExtractDestroyPaths(String contextName, ContextPartitionSelector selector)
        {
            var contextManager = CheckedGetContextManager(contextName);
            var descriptor     = contextManager.ExtractDestroyPaths(selector);

            return(DescriptorToExtract(contextManager.NumNestingLevels, descriptor));
        }
        public ContextPartitionCollection StopContextPartitions(String contextName, ContextPartitionSelector selector)
        {
            var contextManager = CheckedGetContextManager(contextName);
            var descriptor     = contextManager.ExtractStopPaths(selector);

            return(new ContextPartitionCollection(descriptor.ContextPartitionInformation));
        }
Example #5
0
 public SafeEnumerator<EventBean> GetSafeEnumerator(
     int statementId,
     ContextPartitionSelector selector)
 {
     var instances = GetAgentInstancesForStmt(statementId, selector);
     return new AgentInstanceArraySafeEnumerator(instances);
 }
Example #6
0
 private ICollection <int> GetAgentInstancesForSelector(ContextPartitionSelector selector)
 {
     if (selector is ContextPartitionSelectorById)
     {
         var byId = (ContextPartitionSelectorById)selector;
         var ids  = byId.ContextPartitionIds;
         if (ids == null || ids.IsEmpty())
         {
             return(Collections.GetEmptyList <int>());
         }
         var agentInstanceIds = new List <int>(ids);
         agentInstanceIds.RetainAll(_contextPartitionIdManager.Ids);
         return(agentInstanceIds);
     }
     else if (selector is ContextPartitionSelectorAll)
     {
         return(new List <int>(_contextPartitionIdManager.Ids));
     }
     else if (selector is ContextPartitionSelectorNested)
     {
         var nested  = (ContextPartitionSelectorNested)selector;
         var visitor = new ContextPartitionVisitorAgentInstanceIdWPath(_nestedContextFactories.Length);
         foreach (var item in nested.Selectors)
         {
             RecursivePopulateSelector(_rootContext, 1, item, visitor);
         }
         return(visitor.AgentInstanceIds);
     }
     throw ContextControllerSelectorUtil.GetInvalidSelector(
               new Type[]
     {
         typeof(ContextPartitionSelectorNested)
     }, selector, true);
 }
Example #7
0
        public IDictionary <int, ContextPartitionDescriptor> StartPaths(ContextPartitionSelector selector)
        {
            var visitor = GetContextPartitionPathsInternal(selector);

            foreach (var entry in visitor.ControllerAgentInstances)
            {
                var treeEntry = _subcontexts.Get(entry.Key);

                foreach (var leaf in entry.Value)
                {
                    int agentInstanceId = leaf.Value.OptionalContextPartitionId.GetValueOrDefault();
                    var list            = treeEntry.AgentInstances.Get(agentInstanceId);
                    if (list.State == ContextPartitionState.STARTED)
                    {
                        continue;
                    }
                    foreach (var statement in _statements)
                    {
                        var instance = StartStatement(
                            agentInstanceId, statement.Value, _rootContext, list.InitPartitionKey,
                            list.InitContextProperties, false);
                        list.AgentInstances.Add(instance);
                    }
                    list.State       = ContextPartitionState.STARTED;
                    leaf.Value.State = ContextPartitionState.STARTED;
                    _rootContext.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, leaf.Key, leaf.Value);
                }
            }
            ContextManagerImpl.SetState(visitor.AgentInstanceInfo, ContextPartitionState.STARTED);
            return(visitor.AgentInstanceInfo);
        }
Example #8
0
        public ContextPartitionVisitorStateWithPath GetContextPartitionPathsInternal(ContextPartitionSelector selector)
        {
            var visitor = new ContextPartitionVisitorStateWithPath(_nestedContextFactories, _subcontexts);
            IList <ContextPartitionSelector[]> selectors;

            if (selector is ContextPartitionSelectorNested)
            {
                var nested = (ContextPartitionSelectorNested)selector;
                selectors = nested.Selectors;
            }
            else if (selector is ContextPartitionSelectorAll)
            {
                var all = new ContextPartitionSelector[NumNestingLevels];
                all.Fill(selector);
                selectors = Collections.SingletonList(all);
            }
            else
            {
                throw new ArgumentException("Invalid selector for nested context");
            }
            foreach (var item in selectors)
            {
                RecursivePopulateSelector(_rootContext, 1, item, visitor);
            }
            return(visitor);
        }
Example #9
0
        public ContextStatePathDescriptor ExtractPaths(ContextPartitionSelector selector)
        {
            var visitor = new ContextPartitionVisitorState();

            _rootContext.VisitSelectedPartitions(selector, visitor);
            return(new ContextStatePathDescriptor(visitor.States, visitor.ContextPartitionInfo));
        }
Example #10
0
 public IEnumerator<EventBean> GetEnumerator(
     int statementId,
     ContextPartitionSelector selector)
 {
     var instances = GetAgentInstancesForStmt(statementId, selector);
     return AgentInstanceArrayIterator.Create(instances);
 }
Example #11
0
        private AgentInstance[] GetAgentInstancesForStmt(int statementId, ContextPartitionSelector selector)
        {
            var agentInstanceIds = GetAgentInstanceIds(selector);

            if (agentInstanceIds == null || agentInstanceIds.IsEmpty())
            {
                return(new AgentInstance[0]);
            }

            IList <AgentInstance> instances = new List <AgentInstance>(agentInstanceIds.Count);

            foreach (var agentInstanceId in agentInstanceIds)
            {
                var instancesList = _agentInstances.Get(agentInstanceId);
                if (instancesList != null)
                {
                    foreach (var instance in instancesList.AgentInstances)
                    {
                        if (instance.AgentInstanceContext.StatementContext.StatementId == statementId)
                        {
                            instances.Add(instance);
                        }
                    }
                }
            }
            return(instances.ToArray());
        }
Example #12
0
        public ContextPartitionCollection GetContextPartitions(ContextPartitionSelector selector)
        {
            if (selector is ContextPartitionSelectorAll) {
                IDictionary<int, ContextPartitionIdentifier> map = new Dictionary<int, ContextPartitionIdentifier>();
                var idsInner = ContextPartitionIdService.Ids;
                foreach (var id in idsInner) {
                    var partitionKeys = ContextPartitionIdService.GetPartitionKeys(id);
                    if (partitionKeys != null) {
                        var identifier = GetContextPartitionIdentifier(partitionKeys);
                        map.Put(id, identifier);
                    }
                }

                return new ContextPartitionCollection(map);
            }

            var ids = Realization.GetAgentInstanceIds(selector);
            IDictionary<int, ContextPartitionIdentifier>
                identifiers = new Dictionary<int, ContextPartitionIdentifier>();
            foreach (var id in ids) {
                var partitionKeys = ContextPartitionIdService.GetPartitionKeys(id);
                if (partitionKeys == null) {
                    continue;
                }

                var identifier = GetContextPartitionIdentifier(partitionKeys);
                identifiers.Put(id, identifier);
            }

            return new ContextPartitionCollection(identifiers);
        }
Example #13
0
        public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor)
        {
            int nestingLevel = _factory.FactoryContext.NestingLevel;

            if (contextPartitionSelector is ContextPartitionSelectorHash)
            {
                var hash = (ContextPartitionSelectorHash)contextPartitionSelector;
                if (hash.Hashes == null || hash.Hashes.IsEmpty())
                {
                    return;
                }
                foreach (int hashCode in hash.Hashes)
                {
                    var handle = _partitionKeys.Get(hashCode);
                    if (handle != null)
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, hashCode, this, handle);
                    }
                }
                return;
            }
            if (contextPartitionSelector is ContextPartitionSelectorFiltered)
            {
                var filter         = (ContextPartitionSelectorFiltered)contextPartitionSelector;
                var identifierHash = new ContextPartitionIdentifierHash();
                foreach (var entry in _partitionKeys)
                {
                    identifierHash.Hash = entry.Key;
                    identifierHash.ContextPartitionId = entry.Value.ContextPartitionOrPathId;
                    if (filter.Filter(identifierHash))
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value);
                    }
                }
                return;
            }
            if (contextPartitionSelector is ContextPartitionSelectorAll)
            {
                foreach (var entry in _partitionKeys)
                {
                    visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value);
                }
                return;
            }
            if (contextPartitionSelector is ContextPartitionSelectorById)
            {
                var byId = (ContextPartitionSelectorById)contextPartitionSelector;
                foreach (var entry in _partitionKeys)
                {
                    int cpid = entry.Value.ContextPartitionOrPathId;
                    if (byId.ContextPartitionIds.Contains(cpid))
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, entry.Key, this, entry.Value);
                    }
                }
                return;
            }
            throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[] { typeof(ContextPartitionSelectorHash) }, contextPartitionSelector);
        }
Example #14
0
 public ISet<int> GetContextPartitionIds(
     string deploymentId,
     string contextName,
     ContextPartitionSelector selector)
 {
     var contextManager = CheckedGetContextManager(deploymentId, contextName);
     return contextManager.GetContextPartitionIds(selector);
 }
Example #15
0
 public IEnumerator <EventBean> GetSafeEnumerator(int statementId, ContextPartitionSelector selector)
 {
     using (_uLock.Acquire())
     {
         var instances = GetAgentInstancesForStmt(statementId, selector);
         return(GetEnumeratorWithInstanceLock(instances));
     }
 }
Example #16
0
 public IEnumerator <EventBean> GetEnumerator(int statementId, ContextPartitionSelector selector)
 {
     using (_uLock.Acquire())
     {
         var instances = GetAgentInstancesForStmt(statementId, selector);
         return(instances.SelectMany(instance => instance.FinalView).GetEnumerator());
     }
 }
        public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor)
        {
            var nestingLevel = _factory.FactoryContext.NestingLevel;

            if (contextPartitionSelector is ContextPartitionSelectorFiltered filtered)
            {
                var identifier = new ContextPartitionIdentifierPartitioned();
                foreach (var entry in _partitionKeys)
                {
                    identifier.ContextPartitionId = entry.Value.ContextPartitionOrPathId;
                    var identifierOA = GetKeyObjectsAccountForMultikey(entry.Key);
                    identifier.Keys = identifierOA;

                    if (filtered.Filter(identifier))
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, identifierOA, this, entry.Value);
                    }
                }
                return;
            }
            else if (contextPartitionSelector is ContextPartitionSelectorSegmented partitioned)
            {
                if (partitioned.PartitionKeys?.IsEmpty() != false)
                {
                    return;
                }
                foreach (var keyObjects in partitioned.PartitionKeys)
                {
                    var key            = GetKeyObjectForLookup(keyObjects);
                    var instanceHandle = _partitionKeys.Get(key);
                    if (instanceHandle != null)
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, keyObjects, this, instanceHandle);
                    }
                }
                return;
            }
            else if (contextPartitionSelector is ContextPartitionSelectorById filteredById)
            {
                foreach (var entry in _partitionKeys)
                {
                    if (filteredById.ContextPartitionIds.Contains(entry.Value.ContextPartitionOrPathId))
                    {
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, GetKeyObjectsAccountForMultikey(entry.Key), this, entry.Value);
                    }
                }
                return;
            }
            else if (contextPartitionSelector is ContextPartitionSelectorAll)
            {
                foreach (var entry in _partitionKeys)
                {
                    visitor.Visit(nestingLevel, _pathId, _factory.Binding, GetKeyObjectsAccountForMultikey(entry.Key), this, entry.Value);
                }
                return;
            }
            throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[] { typeof(ContextPartitionSelectorSegmented) }, contextPartitionSelector);
        }
Example #18
0
        public ICollection<int> GetAgentInstanceIds(ContextPartitionSelector selector)
        {
            if (selector is ContextPartitionSelectorById) {
                var byId = (ContextPartitionSelectorById) selector;
                var ids = byId.ContextPartitionIds;
                if (ids == null || ids.IsEmpty()) {
                    return Collections.GetEmptyList<int>();
                }

                var agentInstanceIds = new List<int>(ids);
                agentInstanceIds.RetainAll(ContextManager.ContextPartitionIdService.Ids);
                return agentInstanceIds;
            }

            if (selector is ContextPartitionSelectorAll) {
                return ContextManager.ContextPartitionIdService.Ids;
            }

            if (selector is ContextPartitionSelectorNested) {
                if (ContextControllers.Length == 1) {
                    throw ContextControllerSelectorUtil.GetInvalidSelector(
                        new[] {typeof(ContextPartitionSelectorNested)},
                        selector,
                        true);
                }

                var nested = (ContextPartitionSelectorNested) selector;
                var visitor = new ContextPartitionVisitorAgentInstanceId(ContextControllers.Length);
                foreach (var stack in nested.Selectors) {
                    ContextControllers[0].VisitSelectedPartitions(IntSeqKeyRoot.INSTANCE, stack[0], visitor, stack);
                }

                return visitor.Ids;
            }
            else {
                if (ContextControllers.Length > 1) {
                    throw ContextControllerSelectorUtil.GetInvalidSelector(
                        new[] {
                            typeof(ContextPartitionSelectorAll), typeof(ContextPartitionSelectorById),
                            typeof(ContextPartitionSelectorNested)
                        },
                        selector,
                        true);
                }

                var visitor = new ContextPartitionVisitorAgentInstanceId(ContextControllers.Length);
                ContextControllers[0]
                    .VisitSelectedPartitions(
                        IntSeqKeyRoot.INSTANCE,
                        selector,
                        visitor,
                        new[] {selector});
                return visitor.Ids;
            }
        }
Example #19
0
 protected internal static ICollection<int> AgentInstanceIds(
     FireAndForgetProcessor processor,
     ContextPartitionSelector optionalSelector,
     ContextManagementService contextManagementService)
 {
     var contextManager = contextManagementService.GetContextManager(
         processor.ContextDeploymentId,
         processor.ContextName);
     return contextManager.Realization.GetAgentInstanceIds(
         optionalSelector == null ? ContextPartitionSelectorAll.INSTANCE : optionalSelector);
 }
        private void RunQueryAll(String epl, String fields, Object[][] expected, int numStreams)
        {
            ContextPartitionSelector[] selectors = new ContextPartitionSelector[numStreams];
            for (int i = 0; i < numStreams; i++)
            {
                selectors[i] = ContextPartitionSelectorAll.INSTANCE;
            }

            RunQuery(epl, fields, expected, selectors);

            // run same query without selector
            EPOnDemandQueryResult result = _epService.EPRuntime.ExecuteQuery(epl);

            EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.Split(','), expected);
        }
Example #21
0
        public ContextStatePathDescriptor ExtractDestroyPaths(ContextPartitionSelector selector)
        {
            var states = ExtractPaths(selector);

            foreach (var entry in states.Paths)
            {
                var agentInstanceId = entry.Value.OptionalContextPartitionId.Value;
                var descriptor      = states.ContextPartitionInformation.Get(agentInstanceId);
                _rootContext.DeletePath(descriptor.Identifier);
                var list = _agentInstances.Delete(agentInstanceId);
                StatementAgentInstanceUtil.StopAgentInstances(list.AgentInstances, null, _servicesContext, false, false);
                list.ClearAgentInstances();
                _rootContext.Factory.FactoryContext.StateCache.RemoveContextPath(_contextName, entry.Key.Level, entry.Key.ParentPath, entry.Key.SubPath);
            }
            return(states);
        }
Example #22
0
        public ContextStatePathDescriptor ExtractStopPaths(ContextPartitionSelector selector)
        {
            var states = ExtractPaths(selector);

            foreach (var entry in states.Paths)
            {
                var agentInstanceId = entry.Value.OptionalContextPartitionId.Value;
                var list            = _agentInstances.Get(agentInstanceId);
                list.State = ContextPartitionState.STOPPED;
                StatementAgentInstanceUtil.StopAgentInstances(list.AgentInstances, null, _servicesContext, false, false);
                list.ClearAgentInstances();
                entry.Value.State = ContextPartitionState.STOPPED;
                _rootContext.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, entry.Key, entry.Value);
            }
            return(states);
        }
Example #23
0
        public void VisitSelectedPartitions(ContextPartitionSelector contextPartitionSelector, ContextPartitionVisitor visitor)
        {
            var nestingLevel = _factory.FactoryContext.NestingLevel;

            if (contextPartitionSelector is ContextPartitionSelectorFiltered)
            {
                var filter     = (ContextPartitionSelectorFiltered)contextPartitionSelector;
                var identifier = new ContextPartitionIdentifierInitiatedTerminated();
                foreach (var entry in EndConditions)
                {
                    identifier.EndTime            = entry.Value.EndTime;
                    identifier.StartTime          = entry.Value.StartTime;
                    identifier.Properties         = entry.Value.StartProperties;
                    identifier.ContextPartitionId = entry.Value.InstanceHandle.ContextPartitionOrPathId;
                    if (filter.Filter(identifier))
                    {
                        var state = new ContextControllerInitTermState(_factory.FactoryContext.ServicesContext.SchedulingService.Time, entry.Value.StartProperties);
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, state, this, entry.Value.InstanceHandle);
                    }
                }
                return;
            }
            if (contextPartitionSelector is ContextPartitionSelectorById)
            {
                var filter = (ContextPartitionSelectorById)contextPartitionSelector;
                foreach (var entry in EndConditions)
                {
                    if (filter.ContextPartitionIds.Contains(entry.Value.InstanceHandle.ContextPartitionOrPathId))
                    {
                        var state = new ContextControllerInitTermState(_factory.FactoryContext.ServicesContext.SchedulingService.Time, entry.Value.StartProperties);
                        visitor.Visit(nestingLevel, _pathId, _factory.Binding, state, this, entry.Value.InstanceHandle);
                    }
                }
                return;
            }
            if (contextPartitionSelector is ContextPartitionSelectorAll)
            {
                foreach (var entry in EndConditions)
                {
                    var state = new ContextControllerInitTermState(_factory.FactoryContext.ServicesContext.SchedulingService.Time, entry.Value.StartProperties);
                    visitor.Visit(nestingLevel, _pathId, _factory.Binding, state, this, entry.Value.InstanceHandle);
                }
                return;
            }
            throw ContextControllerSelectorUtil.GetInvalidSelector(new Type[0], contextPartitionSelector);
        }
Example #24
0
        private AgentInstance[] GetAgentInstancesForStmt(
            int statementId,
            ContextPartitionSelector selector)
        {
            var agentInstanceIds = GetAgentInstanceIds(selector);
            if (agentInstanceIds == null || agentInstanceIds.IsEmpty()) {
                return new AgentInstance[0];
            }

            foreach (var entry in Statements) {
                if (entry.Value.Lightweight.StatementContext.StatementId == statementId) {
                    var agentInstances = ContextManagerUtil.GetAgentInstances(entry.Value, agentInstanceIds);
                    return agentInstances.ToArray();
                }
            }

            return null;
        }
        private ICollection <EventBean> GetStreamFilterSnapshot(int streamNum, ContextPartitionSelector contextPartitionSelector)
        {
            var streamSpec = _statementSpec.StreamSpecs[streamNum];
            IList <ExprNode> filterExpressions = Collections.GetEmptyList <ExprNode>();

            if (streamSpec is NamedWindowConsumerStreamSpec)
            {
                var namedSpec = (NamedWindowConsumerStreamSpec)streamSpec;
                filterExpressions = namedSpec.FilterExpressions;
            }
            else
            {
                var tableSpec = (TableQueryStreamSpec)streamSpec;
                filterExpressions = tableSpec.FilterExpressions;
            }

            var fireAndForgetProcessor = _processors[streamNum];

            // handle the case of a single or matching agent instance
            var processorInstance = fireAndForgetProcessor.GetProcessorInstance(_agentInstanceContext);

            if (processorInstance != null)
            {
                EPPreparedExecuteTableHelper.AssignTableAccessStrategies(_services, _statementSpec.TableNodes, _agentInstanceContext);
                return(GetStreamSnapshotInstance(streamNum, filterExpressions, processorInstance));
            }

            // context partition runtime query
            var contextPartitions = EPPreparedExecuteMethodHelper.GetAgentInstanceIds(fireAndForgetProcessor, contextPartitionSelector, _services.ContextManagementService, fireAndForgetProcessor.ContextName);

            // collect events
            var events = new ArrayDeque <EventBean>();

            foreach (int agentInstanceId in contextPartitions)
            {
                processorInstance = fireAndForgetProcessor.GetProcessorInstanceContextById(agentInstanceId);
                if (processorInstance != null)
                {
                    var coll = processorInstance.SnapshotBestEffort(this, _filters[streamNum], _statementSpec.Annotations);
                    events.AddAll(coll);
                }
            }
            return(events);
        }
Example #26
0
        public IEnumerator <EventBean> GetEnumerator(ContextPartitionSelector selector)
        {
            if (StatementContext.ContextDescriptor == null)
            {
                throw GetUnsupportedNonContextEnumerator();
            }
            if (selector == null)
            {
                throw new ArgumentException("No selector provided");
            }

            // Return null if not started
            StatementContext.VariableService.SetLocalVersion();
            if (_parentView == null)
            {
                return(null);
            }
            return(StatementContext.ContextDescriptor.GetEnumerator(StatementContext.StatementId, selector));
        }
        private static void RunQueryAll(
            RegressionEnvironment env,
            RegressionPath path,
            string epl,
            string fields,
            object[][] expected,
            int numStreams)
        {
            var selectors = new ContextPartitionSelector[numStreams];
            for (var i = 0; i < numStreams; i++) {
                selectors[i] = ContextPartitionSelectorAll.INSTANCE;
            }

            RunQuery(env, path, epl, fields, expected, selectors);

            // run same query without selector
            var compiled = env.CompileFAF(epl, path);
            var result = env.Runtime.FireAndForgetService.ExecuteQuery(compiled);
            EPAssertionUtil.AssertPropsPerRowAnyOrder(result.Array, fields.SplitCsv(), expected);
        }
Example #28
0
        public EPPreparedQueryResult Execute(
            FAFQueryMethodSelect select,
            ContextPartitionSelector[] contextPartitionSelectors,
            FAFQueryMethodAssignerSetter assignerSetter,
            ContextManagementService contextManagementService)
        {
            FireAndForgetProcessor processor = select.Processors[0];

            ContextPartitionSelector singleSelector =
                contextPartitionSelectors != null && contextPartitionSelectors.Length > 0
                    ? contextPartitionSelectors[0]
                    : null;
            ICollection<int> agentInstanceIds = AgentInstanceIds(processor, singleSelector, contextManagementService);

            ICollection<EventBean> events = new ArrayDeque<EventBean>();
            AgentInstanceContext agentInstanceContext = null;
            foreach (int agentInstanceId in agentInstanceIds) {
                FireAndForgetInstance processorInstance = processor.GetProcessorInstanceContextById(agentInstanceId);
                if (processorInstance != null) {
                    agentInstanceContext = processorInstance.AgentInstanceContext;
                    ICollection<EventBean> coll = processorInstance.SnapshotBestEffort(
                        select.QueryGraph,
                        select.Annotations);
                    events.AddAll(coll);
                }
            }

            // get RSP
            ResultSetProcessor resultSetProcessor = ProcessorWithAssign(
                select.ResultSetProcessorFactoryProvider,
                agentInstanceContext,
                assignerSetter,
                select.TableAccesses,
                select.Subselects);

            if (select.WhereClause != null) {
                events = Filtered(events, select.WhereClause, agentInstanceContext);
            }

            return ProcessedNonJoin(resultSetProcessor, events, select.DistinctKeyGetter);
        }
Example #29
0
        private AgentInstance[] GetAgentInstancesForStmt(int statementId, ContextPartitionSelector selector)
        {
            var agentInstanceIds = GetAgentInstancesForSelector(selector);

            if (agentInstanceIds == null || agentInstanceIds.IsEmpty())
            {
                return(new AgentInstance[0]);
            }

            IList <AgentInstance> instances = new List <AgentInstance>(agentInstanceIds.Count);

            foreach (var subcontext in _subcontexts)
            {
                if (subcontext.Key.Factory.FactoryContext.NestingLevel != _nestedContextFactories.Length)
                {
                    continue;
                }
                if (subcontext.Value.AgentInstances == null || subcontext.Value.AgentInstances.IsEmpty())
                {
                    continue;
                }

                foreach (int agentInstanceId in agentInstanceIds)
                {
                    var instancesList = subcontext.Value.AgentInstances.Get(agentInstanceId);
                    if (instancesList != null)
                    {
                        var instanceIt = instancesList.AgentInstances.GetEnumerator();
                        while (instanceIt.MoveNext())
                        {
                            var instance = instanceIt.Current;
                            if (instance.AgentInstanceContext.StatementContext.StatementId == statementId)
                            {
                                instances.Add(instance);
                            }
                        }
                    }
                }
            }
            return(instances.ToArray());
        }
Example #30
0
        public ContextStatePathDescriptor ExtractStopPaths(ContextPartitionSelector selector)
        {
            var visitor = GetContextPartitionPathsInternal(selector);

            foreach (var entry in visitor.ControllerAgentInstances)
            {
                var treeEntry = _subcontexts.Get(entry.Key);
                foreach (var leaf in entry.Value)
                {
                    var agentInstanceId = leaf.Value.OptionalContextPartitionId.GetValueOrDefault();
                    var list            = treeEntry.AgentInstances.Get(agentInstanceId);
                    list.State = ContextPartitionState.STOPPED;
                    StatementAgentInstanceUtil.StopAgentInstances(
                        list.AgentInstances, null, _servicesContext, false, false);
                    list.ClearAgentInstances();
                    leaf.Value.State = ContextPartitionState.STOPPED;
                    _rootContext.Factory.FactoryContext.StateCache.UpdateContextPath(_contextName, leaf.Key, leaf.Value);
                }
            }
            return(new ContextStatePathDescriptor(visitor.States, visitor.AgentInstanceInfo));
        }