Exemple #1
0
        public ViewServiceCreateResult CreateViews(
            Viewable eventStreamViewable,
            IList <ViewFactory> viewFactories,
            AgentInstanceViewFactoryChainContext viewFactoryChainContext,
            bool hasPreviousNode)
        {
            // Attempt to find existing views under the stream that match specs.
            // The viewSpecList may have been changed by this method.
            Pair <Viewable, IList <View> > resultPair;

            if (hasPreviousNode)
            {
                resultPair = new Pair <Viewable, IList <View> >(eventStreamViewable, Collections.GetEmptyList <View>());
            }
            else
            {
                resultPair = ViewServiceHelper.MatchExistingViews(eventStreamViewable, viewFactories, viewFactoryChainContext.AgentInstanceContext);
            }

            var parentViewable = resultPair.First;

            if (viewFactories.IsEmpty())
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(".createView No new views created, dumping stream ... " + eventStreamViewable);
                    ViewSupport.DumpChildViews("EventStream ", eventStreamViewable);
                }

                return(new ViewServiceCreateResult(parentViewable, parentViewable, Collections.GetEmptyList <View>()));   // we know its a view here since the factory list is empty
            }

            // Instantiate remaining chain of views from the remaining factories which didn't match to existing views.
            var views = ViewServiceHelper.InstantiateChain(parentViewable, viewFactories, viewFactoryChainContext);

            // Initialize any views that need initializing after the chain is complete
            foreach (var view in views)
            {
                if (view is InitializableView)
                {
                    var initView = (InitializableView)view;
                    initView.Initialize();
                }
            }

            if (Log.IsDebugEnabled)
            {
                Log.Debug(".createView New views created for stream, all views ... " + eventStreamViewable);
                ViewSupport.DumpChildViews("EventStream ", eventStreamViewable);
            }

            return(new ViewServiceCreateResult(views[views.Count - 1], views[0], views));
        }
        public void TestInstantiateChain()
        {
            SupportBeanClassView topView                 = new SupportBeanClassView(TEST_CLASS);
            IList <ViewFactory>  viewFactories           = SupportViewSpecFactory.MakeFactoryListOne(topView.EventType);
            AgentInstanceViewFactoryChainContext context = SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext();

            // Check correct views created
            IList <View> views = ViewServiceHelper.InstantiateChain(topView, viewFactories, context);

            Assert.AreEqual(3, views.Count);
            Assert.AreEqual(typeof(LengthWindowView), views[0].GetType());
            Assert.AreEqual(typeof(UnivariateStatisticsView), views[1].GetType());
            Assert.AreEqual(typeof(LastElementView), views[2].GetType());

            // Check that the context is set
            viewFactories = SupportViewSpecFactory.MakeFactoryListFive(topView.EventType);
            views         = ViewServiceHelper.InstantiateChain(topView, viewFactories, context);
            TimeWindowView timeWindow = (TimeWindowView)views[0];
        }