// Compare filters in statement with filters in segmented context, addendum filter compilation
        private static void GetAddendumFilters(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums,
            ContextDetailCategoryItem category,
            ContextDetailCategory categorySpec,
            IList <FilterSpecCompiled> filters,
            ContextControllerStatementDesc statement)
        {
            // determine whether create-named-window
            var isCreateWindow = statement != null && statement.Statement.StatementSpec.CreateWindowDesc != null;

            if (!isCreateWindow)
            {
                foreach (var filtersSpec in filters)
                {
                    var typeOrSubtype = EventTypeUtility.IsTypeOrSubTypeOf(filtersSpec.FilterForEventType, categorySpec.FilterSpecCompiled.FilterForEventType);
                    if (!typeOrSubtype)
                    {
                        continue;       // does not apply
                    }
                    AddAddendums(addendums, filtersSpec, category, categorySpec);
                }
            }
            // handle segmented context for create-window
            else
            {
                var declaredAsName = statement.Statement.StatementSpec.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName != null)
                {
                    foreach (var filtersSpec in filters)
                    {
                        AddAddendums(addendums, filtersSpec, category, categorySpec);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void AddStatement(ContextControllerStatementBase statement, bool isRecoveringResilient)
        {
            // validation down the hierarchy
            var caches = _factory.ValidateStatement(statement);

            // add statement
            var desc = new ContextControllerStatementDesc(statement, new ContextControllerStatementCtxCache[] { caches });

            _statements.Put(statement.StatementContext.StatementId, desc);

            // activate if this is the first statement
            if (_statements.Count == 1)
            {
                Activate();     // this may itself trigger a callback
            }
            // activate statement in respect to existing context partitions
            else
            {
                foreach (var entry in _agentInstances)
                {
                    if (entry.Value.State == ContextPartitionState.STARTED)
                    {
                        var agentInstance = StartStatement(entry.Key, desc, _rootContext, entry.Value.InitPartitionKey, entry.Value.InitContextProperties, isRecoveringResilient);
                        entry.Value.AgentInstances.Add(agentInstance);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private AgentInstance StartStatement(
            int contextId,
            ContextControllerStatementDesc statementDesc,
            ContextController originator,
            Object partitionKey,
            IDictionary <String, Object> contextProperties,
            bool isRecoveringResilient)
        {
            // build filters
            var proxy = GetMergedFilterAddendums(statementDesc, originator, partitionKey, contextId);

            // build built-in context properties
            var properties = ContextPropertyEventType.GetNestedBeanBase(_contextName, contextId);

            properties.Put(
                _nestedContextFactories[_nestedContextFactories.Length - 1].FactoryContext.ContextName,
                contextProperties);
            RecursivePopulateBuiltinProps(originator, properties);
            properties.Put(ContextPropertyEventType.PROP_CTX_NAME, _contextName);
            properties.Put(ContextPropertyEventType.PROP_CTX_ID, contextId);
            var contextBean =
                (MappedEventBean)
                _servicesContext.EventAdapterService.AdapterForTypedMap(
                    properties, _contextDescriptor.ContextPropertyRegistry.ContextEventType);

            // activate
            var result = StatementAgentInstanceUtil.Start(
                _servicesContext, statementDesc.Statement, false, contextId, contextBean, proxy, isRecoveringResilient);

            return(new AgentInstance(result.StopCallback, result.AgentInstanceContext, result.FinalView));
        }
        public override void PopulateFilterAddendums(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> filterAddendum,
            ContextControllerStatementDesc statement,
            object categoryIndex,
            int contextId)
        {
            var statementInfo = (ContextControllerStatementCtxCacheFilters)statement.Caches[_factoryContext.NestingLevel - 1];
            var category      = _categorySpec.Items[categoryIndex.AsInt()];

            GetAddendumFilters(filterAddendum, category, _categorySpec, statementInfo.FilterSpecs, statement);
        }
Ejemplo n.º 5
0
        public override void PopulateFilterAddendums(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> filterAddendum,
            ContextControllerStatementDesc statement,
            object key,
            int contextId)
        {
            ContextControllerStatementCtxCacheFilters statementInfo =
                (ContextControllerStatementCtxCacheFilters)statement.Caches[FactoryContext.NestingLevel - 1];

            ContextControllerPartitionedUtil.PopulateAddendumFilters(
                key, statementInfo.FilterSpecs, _segmentedSpec, statement.Statement.StatementSpec, filterAddendum);
        }
Ejemplo n.º 6
0
        public override void PopulateFilterAddendums(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> filterAddendum,
            ContextControllerStatementDesc statement,
            Object key,
            int contextId)
        {
            var factoryContext           = base.FactoryContext;
            var statementInfo            = (ContextControllerStatementCtxCacheFilters)statement.Caches[factoryContext.NestingLevel - 1];
            var assignedContextPartition = (int)key;
            var code = assignedContextPartition % _hashedSpec.Granularity;

            GetAddendumFilters(filterAddendum, code, statementInfo.FilterSpecs, _hashedSpec, statement);
        }
Ejemplo n.º 7
0
        public static FilterValueSetParam[][] GetAddendumFilters(
            FilterSpecCompiled filterSpecCompiled,
            int hashCode,
            ContextDetailHash hashSpec,
            ContextControllerStatementDesc statementDesc)
        {
            // determine whether create-named-window
            var isCreateWindow = statementDesc != null && statementDesc.Statement.StatementSpec.CreateWindowDesc != null;
            ContextDetailHashItem foundPartition = null;

            if (!isCreateWindow)
            {
                foundPartition = FindHashItemSpec(hashSpec, filterSpecCompiled);
            }
            else
            {
                string declaredAsName = statementDesc.Statement.StatementSpec.CreateWindowDesc.AsEventTypeName;
                foreach (var partitionItem in hashSpec.Items)
                {
                    if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                    {
                        foundPartition = partitionItem;
                        break;
                    }
                }
            }

            if (foundPartition == null)
            {
                return(null);
            }

            var filter = new FilterValueSetParamImpl(foundPartition.Lookupable, FilterOperator.EQUAL, hashCode);

            var addendum = new FilterValueSetParam[1][];

            addendum[0] = new FilterValueSetParam[]
            {
                filter
            };

            var partitionFilters = foundPartition.ParametersCompiled;

            if (partitionFilters != null)
            {
                addendum = ContextControllerAddendumUtil.AddAddendum(partitionFilters, filter);
            }
            return(addendum);
        }
Ejemplo n.º 8
0
        public void AddStatement(ContextControllerStatementBase statement, bool isRecoveringResilient)
        {
            // validation down the hierarchy
            var caches = new ContextControllerStatementCtxCache[_nestedContextFactories.Length];

            for (var i = 0; i < _nestedContextFactories.Length; i++)
            {
                var nested = _nestedContextFactories[i];
                caches[i] = nested.ValidateStatement(statement);
            }

            // save statement
            var desc = new ContextControllerStatementDesc(statement, caches);

            _statements.Put(statement.StatementContext.StatementId, desc);

            // activate if this is the first statement
            if (_statements.Count == 1)
            {
                Activate(); // this may itself trigger a callback
            }
            // activate statement in respect to existing context partitions
            else
            {
                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 (var entry in subcontext.Value.AgentInstances)
                    {
                        if (entry.Value.State == ContextPartitionState.STARTED)
                        {
                            var agentInstance = StartStatement(
                                entry.Key, desc, subcontext.Key, entry.Value.InitPartitionKey,
                                entry.Value.InitContextProperties, isRecoveringResilient);
                            entry.Value.AgentInstances.Add(agentInstance);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private AgentInstanceFilterProxy GetMergedFilterAddendums(
            ContextControllerStatementDesc statement,
            ContextController originator,
            Object partitionKey,
            int contextId)
        {
            var result = new IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]>();

            originator.Factory.PopulateFilterAddendums(result, statement, partitionKey, contextId);
            var originatorEntry = _subcontexts.Get(originator);

            if (originatorEntry != null)
            {
                RecursivePopulateFilterAddendum(statement, originatorEntry, contextId, result);
            }
            return(new AgentInstanceFilterProxyImpl(result));
        }
Ejemplo n.º 10
0
        private AgentInstance StartStatement(int contextId, ContextControllerStatementDesc statementDesc, ContextController originator, Object partitionKey, IDictionary <String, Object> contextProperties, bool isRecoveringResilient)
        {
            // build filters
            var filterAddendum = new IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]>();

            originator.Factory.PopulateFilterAddendums(filterAddendum, statementDesc, partitionKey, contextId);
            AgentInstanceFilterProxy proxy = new AgentInstanceFilterProxyImpl(filterAddendum);

            // build built-in context properties
            contextProperties.Put(ContextPropertyEventType.PROP_CTX_NAME, _contextName);
            contextProperties.Put(ContextPropertyEventType.PROP_CTX_ID, contextId);
            var contextBean = (MappedEventBean)_servicesContext.EventAdapterService.AdapterForTypedMap(contextProperties, _contextDescriptor.ContextPropertyRegistry.ContextEventType);

            // activate
            var result = StatementAgentInstanceUtil.Start(_servicesContext, statementDesc.Statement, false, contextId, contextBean, proxy, isRecoveringResilient);

            // save only instance data
            return(new AgentInstance(result.StopCallback, result.AgentInstanceContext, result.FinalView));
        }
Ejemplo n.º 11
0
        private void RecursivePopulateFilterAddendum(
            ContextControllerStatementDesc statement,
            ContextControllerTreeEntry originatorEntry,
            int contextId,
            IdentityDictionary <FilterSpecCompiled, FilterValueSetParam[][]> result)
        {
            if (originatorEntry.Parent == null)
            {
                return;
            }
            originatorEntry.Parent.Factory.PopulateFilterAddendums(
                result, statement, originatorEntry.InitPartitionKey, contextId);

            var parentEntry = _subcontexts.Get(originatorEntry.Parent);

            if (parentEntry != null)
            {
                RecursivePopulateFilterAddendum(statement, parentEntry, contextId, result);
            }
        }
Ejemplo n.º 12
0
        // Compare filters in statement with filters in segmented context, addendum filter compilation
        public static void GetAddendumFilters(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums,
            int hashCode,
            IList <FilterSpecCompiled> filtersSpecs,
            ContextDetailHash hashSpec,
            ContextControllerStatementDesc statementDesc)
        {
            foreach (var filtersSpec in filtersSpecs)
            {
                var addendum = GetAddendumFilters(filtersSpec, hashCode, hashSpec, statementDesc);
                if (addendum == null)
                {
                    continue;
                }

                var existing = addendums.Get(filtersSpec);
                if (existing != null)
                {
                    addendum = ContextControllerAddendumUtil.MultiplyAddendum(existing, addendum);
                }
                addendums.Put(filtersSpec, addendum);
            }
        }
Ejemplo n.º 13
0
 public override void PopulateFilterAddendums(IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> filterAddendum, ContextControllerStatementDesc statement, object key, int contextId)
 {
 }
Ejemplo n.º 14
0
        // Compare filters in statement with filters in segmented context, addendum filter compilation
        /// <summary>
        /// Gets the addendum filters.
        /// </summary>
        /// <param name="addendums">The addendums.</param>
        /// <param name="agentInstanceId">The agent instance identifier.</param>
        /// <param name="filtersSpecs">The filters specs.</param>
        /// <param name="hashSpec">The hash spec.</param>
        /// <param name="statementDesc">The statement desc.</param>
        private static void GetAddendumFilters(
            IDictionary <FilterSpecCompiled, FilterValueSetParam[][]> addendums,
            int agentInstanceId,
            IList <FilterSpecCompiled> filtersSpecs,
            ContextDetailHash hashSpec,
            ContextControllerStatementDesc statementDesc)
        {
            // determine whether create-named-window
            var isCreateWindow = statementDesc != null && statementDesc.Statement.StatementSpec.CreateWindowDesc != null;

            if (!isCreateWindow)
            {
                foreach (var filtersSpec in filtersSpecs)
                {
                    var foundPartition = FindHashItemSpec(hashSpec, filtersSpec);
                    if (foundPartition == null)
                    {
                        continue;
                    }

                    FilterValueSetParam filter = new FilterValueSetParamImpl(foundPartition.Lookupable, FilterOperator.EQUAL, agentInstanceId);

                    var addendum = new FilterValueSetParam[1][];
                    addendum[0] = new FilterValueSetParam[] { filter };

                    var partitionFilters = foundPartition.ParametersCompiled;
                    if (partitionFilters != null)
                    {
                        addendum = ContextControllerAddendumUtil.AddAddendum(partitionFilters, filter);
                    }

                    FilterValueSetParam[][] existing = addendums.Get(filtersSpec);
                    if (existing != null)
                    {
                        addendum = ContextControllerAddendumUtil.MultiplyAddendum(existing, addendum);
                    }

                    addendums[filtersSpec] = addendum;
                }
            }
            // handle segmented context for create-window
            else
            {
                var declaredAsName = statementDesc.Statement.StatementSpec.CreateWindowDesc.AsEventTypeName;
                if (declaredAsName != null)
                {
                    foreach (var filterSpec in filtersSpecs)
                    {
                        ContextDetailHashItem foundPartition = null;
                        foreach (var partitionItem in hashSpec.Items)
                        {
                            if (partitionItem.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                            {
                                foundPartition = partitionItem;
                                break;
                            }
                        }

                        if (foundPartition == null)
                        {
                            continue;
                        }

                        FilterValueSetParam filter = new FilterValueSetParamImpl(foundPartition.Lookupable, FilterOperator.EQUAL, agentInstanceId);

                        var addendum = new FilterValueSetParam[1][];
                        addendum[0] = new FilterValueSetParam[] { filter };

                        var existing = addendums.Get(filterSpec);
                        if (existing != null)
                        {
                            addendum = ContextControllerAddendumUtil.MultiplyAddendum(existing, addendum);
                        }

                        addendums[filterSpec] = addendum;
                    }
                }
            }
        }