Exemplo n.º 1
0
        public static IDictionary <ExprPreviousNode, ExprPreviousEvalStrategy> CompilePreviousNodeStrategies(ViewResourceDelegateVerified viewResourceDelegate, AgentInstanceViewFactoryChainContext[] contexts)
        {
            if (!viewResourceDelegate.HasPrevious)
            {
                return(EmptyMap);
            }

            IDictionary <ExprPreviousNode, ExprPreviousEvalStrategy> strategies = new Dictionary <ExprPreviousNode, ExprPreviousEvalStrategy>();

            for (int streamNum = 0; streamNum < contexts.Length; streamNum++)
            {
                // get stream-specific info
                ViewResourceDelegateVerifiedStream @delegate = viewResourceDelegate.PerStream[streamNum];

                // obtain getter
                HandlePrevious(@delegate.PreviousRequests, contexts[streamNum].PreviousNodeGetter, strategies);
            }

            return(strategies);
        }
        public static ViewResourceDelegateVerified VerifyPreviousAndPriorRequirements(ViewFactoryChain[] unmaterializedViewChain, ViewResourceDelegateUnverified @delegate)
        {
            var hasPriorNodes    = [email protected]();
            var hasPreviousNodes = [email protected]();

            var numStreams = unmaterializedViewChain.Length;
            var perStream  = new ViewResourceDelegateVerifiedStream[numStreams];

            // verify "previous"
            var previousPerStream = new IList <ExprPreviousNode> [numStreams];

            foreach (var previousNode in @delegate.PreviousRequests)
            {
                var stream    = previousNode.StreamNumber;
                var factories = unmaterializedViewChain[stream].FactoryChain;

                var pass = InspectViewFactoriesForPrevious(factories);
                if (!pass)
                {
                    throw new ExprValidationException("Previous function requires a single data window view onto the stream");
                }

                var found = factories.OfType <DataWindowViewWithPrevious>().Any();
                if (!found)
                {
                    throw new ExprValidationException("Required data window not found for the 'prev' function, specify a data window for which previous events are retained");
                }

                if (previousPerStream[stream] == null)
                {
                    previousPerStream[stream] = new List <ExprPreviousNode>();
                }
                previousPerStream[stream].Add(previousNode);
            }

            // verify "prior"
            var priorPerStream = new IDictionary <int, IList <ExprPriorNode> > [numStreams];

            foreach (var priorNode in @delegate.PriorRequests)
            {
                var stream = priorNode.StreamNumber;

                if (priorPerStream[stream] == null)
                {
                    priorPerStream[stream] = new SortedDictionary <int, IList <ExprPriorNode> >();
                }

                var treemap      = priorPerStream[stream];
                var callbackList = treemap.Get(priorNode.ConstantIndexNumber);
                if (callbackList == null)
                {
                    callbackList = new List <ExprPriorNode>();
                    treemap.Put(priorNode.ConstantIndexNumber, callbackList);
                }
                callbackList.Add(priorNode);
            }

            // build per-stream info
            for (var i = 0; i < numStreams; i++)
            {
                if (previousPerStream[i] == null)
                {
                    previousPerStream[i] = Collections.GetEmptyList <ExprPreviousNode>();
                }
                if (priorPerStream[i] == null)
                {
                    priorPerStream[i] = new OrderedDictionary <int, IList <ExprPriorNode> >();
                }

                // determine match-recognize "prev"
                var matchRecognizePrevious = Collections.GetEmptySet <ExprPreviousMatchRecognizeNode>();
                if (i == 0)
                {
                    foreach (var viewFactory in unmaterializedViewChain[i].FactoryChain)
                    {
                        if (viewFactory is EventRowRegexNFAViewFactory)
                        {
                            var matchRecognize = (EventRowRegexNFAViewFactory)viewFactory;
                            matchRecognizePrevious = matchRecognize.PreviousExprNodes;
                        }
                    }
                }

                perStream[i] = new ViewResourceDelegateVerifiedStream(previousPerStream[i], priorPerStream[i], matchRecognizePrevious);
            }

            return(new ViewResourceDelegateVerified(hasPriorNodes, hasPreviousNodes, perStream));
        }
Exemplo n.º 3
0
        public static AgentInstanceViewFactoryChainContext Create(IList <ViewFactory> viewFactoryChain, AgentInstanceContext agentInstanceContext, ViewResourceDelegateVerifiedStream viewResourceDelegate)
        {
            Object previousNodeGetter = null;

            if (viewResourceDelegate.PreviousRequests != null && !viewResourceDelegate.PreviousRequests.IsEmpty())
            {
                DataWindowViewWithPrevious factoryFound = EPStatementStartMethodHelperPrevious.FindPreviousViewFactory(viewFactoryChain);
                previousNodeGetter = factoryFound.MakePreviousGetter();
            }

            ViewUpdatedCollection priorViewUpdatedCollection = null;

            if (viewResourceDelegate.PriorRequests != null && !viewResourceDelegate.PriorRequests.IsEmpty())
            {
                var priorEventViewFactory = EPStatementStartMethodHelperPrior.FindPriorViewFactory(viewFactoryChain);
                var callbacksPerIndex     = viewResourceDelegate.PriorRequests;
                priorViewUpdatedCollection = priorEventViewFactory.MakeViewUpdatedCollection(callbacksPerIndex, agentInstanceContext.AgentInstanceId);
            }

            bool removedStream = false;

            if (viewFactoryChain.Count > 1)
            {
                int countDataWindow = 0;
                foreach (ViewFactory viewFactory in viewFactoryChain)
                {
                    if (viewFactory is DataWindowViewFactory)
                    {
                        countDataWindow++;
                    }
                }
                removedStream = countDataWindow > 1;
            }

            return(new AgentInstanceViewFactoryChainContext(agentInstanceContext, removedStream, previousNodeGetter, priorViewUpdatedCollection));
        }