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 TestMatch() { SupportStreamImpl stream = new SupportStreamImpl(TEST_CLASS, 10); IList <ViewFactory> viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); // No views under stream, no matches Pair <Viewable, IList <View> > result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // One top view under the stream that doesn't match SupportBeanClassView testView = new SupportBeanClassView(TEST_CLASS); stream.AddView(new FirstElementView(null)); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // Another top view under the stream that doesn't matche again testView = new SupportBeanClassView(TEST_CLASS); stream.AddView(new LengthWindowView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(), null, 999, null)); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(stream, result.First); Assert.AreEqual(3, viewFactories.Count); Assert.AreEqual(0, result.Second.Count); // One top view under the stream that does actually match LengthWindowView myLengthWindowView = new LengthWindowView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext(), null, 1000, null); stream.AddView(myLengthWindowView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(myLengthWindowView, result.First); Assert.AreEqual(2, viewFactories.Count); Assert.AreEqual(1, result.Second.Count); Assert.AreEqual(myLengthWindowView, result.Second[0]); // One child view under the top view that does not match testView = new SupportBeanClassView(TEST_CLASS); viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); EventType type = UnivariateStatisticsView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1); UnivariateStatisticsViewFactory factory = new UnivariateStatisticsViewFactory(); factory.EventType = type; factory.FieldExpression = SupportExprNodeFactory.MakeIdentNodeBean("LongBoxed"); myLengthWindowView.AddView(new UnivariateStatisticsView(factory, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(1, result.Second.Count); Assert.AreEqual(myLengthWindowView, result.Second[0]); Assert.AreEqual(myLengthWindowView, result.First); Assert.AreEqual(2, viewFactories.Count); // Add child view under the top view that does match viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); UnivariateStatisticsViewFactory factoryTwo = new UnivariateStatisticsViewFactory(); factoryTwo.EventType = type; factoryTwo.FieldExpression = SupportExprNodeFactory.MakeIdentNodeBean("IntPrimitive"); UnivariateStatisticsView myUnivarView = new UnivariateStatisticsView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext()); myLengthWindowView.AddView(myUnivarView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(myUnivarView, result.First); Assert.AreEqual(1, viewFactories.Count); // Add ultimate child view under the child view that does match viewFactories = SupportViewSpecFactory.MakeFactoryListOne(stream.EventType); LastElementView lastElementView = new LastElementView(null); myUnivarView.AddView(lastElementView); result = ViewServiceHelper.MatchExistingViews(stream, viewFactories); Assert.AreEqual(lastElementView, result.First); Assert.AreEqual(0, viewFactories.Count); }