Example #1
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);
                    }
                }
            }
        }
Example #2
0
        public override ContextControllerStatementCtxCache ValidateStatement(ContextControllerStatementBase statement)
        {
            StatementSpecCompiledAnalyzerResult streamAnalysis = StatementSpecCompiledAnalyzer.AnalyzeFilters(statement.StatementSpec);

            ContextControllerPartitionedUtil.ValidateStatementForContext(FactoryContext.ContextName, statement, streamAnalysis, GetItemEventTypes(_segmentedSpec), FactoryContext.ServicesContext.NamedWindowMgmtService);
            return(new ContextControllerStatementCtxCacheFilters(streamAnalysis.Filters));
        }
        public override ContextControllerStatementCtxCache ValidateStatement(ContextControllerStatementBase statement)
        {
            var streamAnalysis = StatementSpecCompiledAnalyzer.AnalyzeFilters(statement.StatementSpec);

            ValidateStatementForContext(statement, streamAnalysis);
            return(new ContextControllerStatementCtxCacheFilters(streamAnalysis.Filters));
        }
Example #4
0
        internal static void ValidateStatementForContext(String contextName, ContextControllerStatementBase statement, StatementSpecCompiledAnalyzerResult streamAnalysis, ICollection <EventType> itemEventTypes, NamedWindowService namedWindowService)
        {
            IList <FilterSpecCompiled> filters = streamAnalysis.Filters;

            bool isCreateWindow = statement.StatementSpec.CreateWindowDesc != null;

            // if no create-window: at least one of the filters must match one of the filters specified by the context
            if (!isCreateWindow)
            {
                foreach (FilterSpecCompiled filter in filters)
                {
                    foreach (EventType itemEventType in itemEventTypes)
                    {
                        EventType stmtFilterType = filter.FilterForEventType;
                        if (stmtFilterType == itemEventType)
                        {
                            return;
                        }
                        if (EventTypeUtility.IsTypeOrSubTypeOf(stmtFilterType, itemEventType))
                        {
                            return;
                        }

                        NamedWindowProcessor processor = namedWindowService.GetProcessor(stmtFilterType.Name);
                        if (processor != null && processor.ContextName != null && processor.ContextName.Equals(contextName))
                        {
                            return;
                        }
                    }
                }

                if (filters.IsNotEmpty())
                {
                    throw new ExprValidationException(GetTypeValidationMessage(contextName, filters[0].FilterForEventType.Name));
                }
                return;
            }

            // validate create-window with column definition: not allowed, requires typed
            if (statement.StatementSpec.CreateWindowDesc.Columns != null &&
                statement.StatementSpec.CreateWindowDesc.Columns.Count > 0)
            {
                throw new ExprValidationException("Segmented context '" + contextName +
                                                  "' requires that named windows are associated to an existing event type and that the event type is listed among the partitions defined by the create-context statement");
            }

            // validate create-window declared type
            String declaredAsName = statement.StatementSpec.CreateWindowDesc.AsEventTypeName;

            if (declaredAsName != null)
            {
                if (itemEventTypes.Any(itemEventType => itemEventType.Name == declaredAsName))
                {
                    return;
                }

                throw new ExprValidationException(GetTypeValidationMessage(contextName, declaredAsName));
            }
        }
Example #5
0
        public void AddStatement(String contextName, ContextControllerStatementBase statement, bool isRecoveringResilient)
        {
            ContextManagerEntry entry = _contexts.Get(contextName);

            if (entry == null)
            {
                throw new ExprValidationException(GetNotDecaredText(contextName));
            }
            entry.AddStatement(statement.StatementContext.StatementId);
            entry.ContextManager.AddStatement(statement, isRecoveringResilient);
        }
Example #6
0
        public override ContextControllerStatementCtxCache ValidateStatement(ContextControllerStatementBase statement)
        {
            var streamAnalysis = StatementSpecCompiledAnalyzer.AnalyzeFilters(statement.StatementSpec);

            ContextControllerPartitionedUtil.ValidateStatementForContext(
                _factoryContext.ContextName, statement, streamAnalysis, GetItemEventTypes(_hashedSpec),
                _factoryContext.ServicesContext.NamedWindowMgmtService);
            // register non-property expression to be able to recreated indexes
            foreach (var entry in _nonPropertyExpressions)
            {
                _factoryContext.ServicesContext.FilterNonPropertyRegisteryService.RegisterNonPropertyExpression(statement.StatementContext.StatementName, entry.Key, entry.Value);
            }
            return(new ContextControllerStatementCtxCacheFilters(streamAnalysis.Filters));
        }
Example #7
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);
                        }
                    }
                }
            }
        }
        private void ValidateStatementForContext(ContextControllerStatementBase statement, StatementSpecCompiledAnalyzerResult streamAnalysis)

        {
            var filters = streamAnalysis.Filters;

            var isCreateWindow = statement.StatementSpec.CreateWindowDesc != null;
            var message        = "Category context '" + _factoryContext.ContextName + "' requires that any of the events types that are listed in the category context also appear in any of the filter expressions of the statement";

            // if no create-window: at least one of the filters must match one of the filters specified by the context
            if (!isCreateWindow)
            {
                foreach (var filter in filters)
                {
                    var stmtFilterType = filter.FilterForEventType;
                    var contextType    = _categorySpec.FilterSpecCompiled.FilterForEventType;
                    if (Equals(stmtFilterType, contextType))
                    {
                        return;
                    }
                    if (EventTypeUtility.IsTypeOrSubTypeOf(stmtFilterType, contextType))
                    {
                        return;
                    }
                }

                if (!filters.IsEmpty())
                {
                    throw new ExprValidationException(message);
                }
                return;
            }

            // validate create-window
            var declaredAsName = statement.StatementSpec.CreateWindowDesc.AsEventTypeName;

            if (declaredAsName != null)
            {
                if (_categorySpec.FilterSpecCompiled.FilterForEventType.Name.Equals(declaredAsName))
                {
                    return;
                }
                throw new ExprValidationException(message);
            }
        }
Example #9
0
 public override ContextControllerStatementCtxCache ValidateStatement(ContextControllerStatementBase statement)
 {
     return(null);
 }
 public abstract ContextControllerStatementCtxCache ValidateStatement(ContextControllerStatementBase statement);