Пример #1
0
        public void TestMakeSubviews()
        {
            EventStream eventStream = new SupportStreamImpl(typeof(SupportMarketDataBean), 4);
            var         expressions = SupportExprNodeFactory.MakeIdentNodesMD("Symbol");
            GroupByView groupView   = new GroupByViewImpl(_agentInstanceContext, expressions, ExprNodeUtility.GetEvaluators(expressions));

            eventStream.AddView(groupView);

            var groupByValue = new Object[] { "IBM" };

            // Invalid for no child nodes
            try
            {
                GroupByViewImpl.MakeSubViews(groupView, "Symbol".Split(','), groupByValue, _agentInstanceContext);
                Assert.IsTrue(false);
            }
            catch (EPException)
            {
                // Expected exception
            }

            // Invalid for child node is a merge node - doesn't make sense to group and merge only
            var mergeViewOne = new MergeView(_agentInstanceContext, SupportExprNodeFactory.MakeIdentNodesMD("Symbol"), null, false);

            groupView.AddView(mergeViewOne);
            try
            {
                GroupByViewImpl.MakeSubViews(groupView, "Symbol".Split(','), groupByValue, _agentInstanceContext);
                Assert.IsTrue(false);
            }
            catch (EPException)
            {
                // Expected exception
            }

            // Add a size view parent of merge view
            groupView = new GroupByViewImpl(_agentInstanceContext, expressions, ExprNodeUtility.GetEvaluators(expressions));

            var firstElementView_1 = new FirstElementView(null);

            groupView.AddView(firstElementView_1);
            groupView.Parent = eventStream;
            mergeViewOne     = new MergeView(_agentInstanceContext, SupportExprNodeFactory.MakeIdentNodesMD("Symbol"), null, false);
            firstElementView_1.AddView(mergeViewOne);

            var subViews = GroupByViewImpl.MakeSubViews(groupView, "Symbol".Split(','), groupByValue, _agentInstanceContext);

            Assert.IsTrue(subViews is FirstElementView);
            Assert.IsTrue(subViews != firstElementView_1);

            var firstEleView = (FirstElementView)subViews;

            Assert.AreEqual(1, firstEleView.Views.Length);
            Assert.IsTrue(firstEleView.Views[0] is AddPropertyValueView);

            var md = (AddPropertyValueView)firstEleView.Views[0];

            Assert.AreEqual(1, md.Views.Length);
            Assert.IsTrue(md.Views[0] == mergeViewOne);
        }
Пример #2
0
 public void VisitViewContainer(ViewDataVisitorContained viewDataVisitor)
 {
     viewDataVisitor.VisitPrimary(GroupByViewImpl.VIEWNAME, _subViewsPerKey.Count);
     foreach (var entry in _subViewsPerKey)
     {
         GroupByViewImpl.VisitView(viewDataVisitor, entry.Key, entry.Value.SubviewHolder);
     }
 }
Пример #3
0
        private void HandleEvent(EventBean theEvent, bool isNew)
        {
            var groupByValuesKey = GetGroupKey(theEvent);

            // Get child views that belong to this group-by value combination
            var subViews = _subViewsPerKey.Get(groupByValuesKey);

            // If this is a new group-by value, the list of subviews is null and we need to make clone sub-views
            if (subViews == null)
            {
                var subviewsList = GroupByViewImpl.MakeSubViews(this, _propertyNames, groupByValuesKey, _agentInstanceContext);
                var currentTime  = _agentInstanceContext.StatementContext.TimeProvider.Time;
                subViews = new GroupByViewAgedEntry(subviewsList, currentTime);
                _subViewsPerKey.Put(groupByValuesKey, subViews);
            }
            else
            {
                subViews.LastUpdateTime = _agentInstanceContext.StatementContext.TimeProvider.Time;
            }

            // Construct a pair of lists to hold the events for the grouped value if not already there
            var pair = _groupedEvents.Get(subViews);

            if (pair == null)
            {
                pair = new Pair <Object, Object>(null, null);
                _groupedEvents.Put(subViews, pair);
            }

            // Add event to a child view event list for later child Update that includes new and old events
            if (isNew)
            {
                pair.First = GroupByViewImpl.AddUpgradeToDequeIfPopulated(pair.First, theEvent);
            }
            else
            {
                pair.Second = GroupByViewImpl.AddUpgradeToDequeIfPopulated(pair.Second, theEvent);
            }
        }
Пример #4
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            var currentTime = _agentInstanceContext.TimeProvider.Time;

            if ((_nextSweepTime == null) || (_nextSweepTime <= currentTime))
            {
                if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
                {
                    Log.Debug("Reclaiming groups older then " + _reclaimMaxAge + " msec and every " + _reclaimFrequency + "msec in frequency");
                }
                _nextSweepTime = currentTime + _reclaimFrequency;
                Sweep(currentTime);
            }

            // Algorithm for single new event
            if ((newData != null) && (oldData == null) && (newData.Length == 1))
            {
                var theEvent      = newData[0];
                var newDataToPost = new EventBean[] { theEvent };

                var groupByValuesKey = GetGroupKey(theEvent);

                // Get child views that belong to this group-by value combination
                var subViews = _subViewsPerKey.Get(groupByValuesKey);

                // If this is a new group-by value, the list of subviews is null and we need to make clone sub-views
                if (subViews == null)
                {
                    var subviewsList = GroupByViewImpl.MakeSubViews(this, _propertyNames, groupByValuesKey, _agentInstanceContext);
                    subViews = new GroupByViewAgedEntry(subviewsList, currentTime);
                    _subViewsPerKey.Put(groupByValuesKey, subViews);
                }
                else
                {
                    subViews.LastUpdateTime = currentTime;
                }

                GroupByViewImpl.UpdateChildViews(subViews.SubviewHolder, newDataToPost, null);
            }
            else
            {
                // Algorithm for dispatching multiple events
                if (newData != null)
                {
                    foreach (var newValue in newData)
                    {
                        HandleEvent(newValue, true);
                    }
                }

                if (oldData != null)
                {
                    foreach (var oldValue in oldData)
                    {
                        HandleEvent(oldValue, false);
                    }
                }

                // Update child views
                foreach (var entry in _groupedEvents)
                {
                    var newEvents = GroupByViewImpl.ConvertToArray(entry.Value.First);
                    var oldEvents = GroupByViewImpl.ConvertToArray(entry.Value.Second);
                    GroupByViewImpl.UpdateChildViews(entry.Key, newEvents, oldEvents);
                }

                _groupedEvents.Clear();
            }
        }