예제 #1
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);
            }
        }
예제 #2
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();
            }
        }