Beispiel #1
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_UPDATE, triggerEvents, matchingEvents);
            }

            if ((matchingEvents == null) || (matchingEvents.Length == 0))
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AInfraOnAction();
                }
                return;
            }

            var eventsPerStream = new EventBean[3];

            var newData = new OneEventCollection();
            var oldData = new OneEventCollection();

            foreach (var triggerEvent in triggerEvents)
            {
                eventsPerStream[1] = triggerEvent;
                foreach (var matchingEvent in matchingEvents)
                {
                    var copy = _parent.UpdateHelper.UpdateWCopy(matchingEvent, eventsPerStream, base.ExprEvaluatorContext);
                    newData.Add(copy);
                    oldData.Add(matchingEvent);
                }
            }

            if (!newData.IsEmpty())
            {
                // Events to delete are indicated via old data
                RootView.Update(newData.ToArray(), oldData.ToArray());

                // The on-delete listeners receive the events deleted, but only if there is interest
                if (_parent.StatementResultService.IsMakeNatural || _parent.StatementResultService.IsMakeSynthetic)
                {
                    UpdateChildren(newData.ToArray(), oldData.ToArray());
                }
            }

            // Keep the last delete records
            _lastResult = matchingEvents;
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
Beispiel #2
0
        public override void HandleMatching(
            EventBean[] triggerEvents,
            EventBean[] matchingEvents)
        {
            agentInstanceContext.InstrumentationProvider.QInfraOnAction(
                OnTriggerType.ON_UPDATE,
                triggerEvents,
                matchingEvents);

            if (matchingEvents == null || matchingEvents.Length == 0) {
                agentInstanceContext.InstrumentationProvider.AInfraOnAction();
                return;
            }

            var eventsPerStream = new EventBean[3];

            var newData = new OneEventCollection();
            var oldData = new OneEventCollection();

            foreach (var triggerEvent in triggerEvents) {
                eventsPerStream[1] = triggerEvent;
                foreach (var matchingEvent in matchingEvents) {
                    var copy = parent.UpdateHelperNamedWindow.Invoke(
                        matchingEvent,
                        eventsPerStream,
                        ExprEvaluatorContext);
                    newData.Add(copy);
                    oldData.Add(matchingEvent);
                }
            }

            if (!newData.IsEmpty()) {
                // Events to delete are indicated via old data
                rootView.Update(newData.ToArray(), oldData.ToArray());

                // The on-delete listeners receive the events deleted, but only if there is interest
                var statementResultService = agentInstanceContext.StatementResultService;
                if (statementResultService.IsMakeNatural || statementResultService.IsMakeSynthetic) {
                    Child?.Update(newData.ToArray(), oldData.ToArray());
                }
            }

            // Keep the last delete records
            agentInstanceContext.InstrumentationProvider.AInfraOnAction();
        }
Beispiel #3
0
        public static void ApplyDelta(
            OneEventCollection newData,
            OneEventCollection oldData,
            InfraOnMergeViewFactory parent,
            NamedWindowRootViewInstance rootView,
            AgentInstanceContext agentInstanceContext,
            ViewSupport viewable)
        {
            if (!newData.IsEmpty() || oldData != null && !oldData.IsEmpty()) {
                var metricHandle = rootView.AgentInstanceContext.StatementContext.EpStatementHandle.MetricsHandle;
                if (metricHandle.IsEnabled && !newData.IsEmpty()) {
                    agentInstanceContext.MetricReportingService.AccountTime(
                        metricHandle,
                        default(PerformanceMetrics),
                        newData.ToArray().Length);
                }

                var statementResultService = agentInstanceContext.StatementResultService;

                // Events to delete are indicated via old data
                // The on-merge listeners receive the events deleted, but only if there is interest
                if (statementResultService.IsMakeNatural) {
                    var eventsPerStreamNaturalNew = newData.IsEmpty() ? null : newData.ToArray();
                    var eventsPerStreamNaturalOld = oldData == null || oldData.IsEmpty() ? null : oldData.ToArray();
                    rootView.Update(
                        EventBeanUtility.Denaturalize(eventsPerStreamNaturalNew),
                        EventBeanUtility.Denaturalize(eventsPerStreamNaturalOld));
                    viewable.Child.Update(eventsPerStreamNaturalNew, eventsPerStreamNaturalOld);
                }
                else {
                    var eventsPerStreamNew = newData.IsEmpty() ? null : newData.ToArray();
                    var eventsPerStreamOld = oldData == null || oldData.IsEmpty() ? null : oldData.ToArray();
                    rootView.Update(eventsPerStreamNew, eventsPerStreamOld);
                    if (statementResultService.IsMakeSynthetic) {
                        viewable.Child.Update(eventsPerStreamNew, eventsPerStreamOld);
                    }
                }
            }
        }
        public void Stop(AgentInstanceStopServices services)
        {
            if (!newToOldEventMap.IsEmpty()) {
                var oldEvents = new OneEventCollection();
                foreach (var oldEvent in newToOldEventMap) {
                    oldEvents.Add(oldEvent.Value);
                }

                if (!oldEvents.IsEmpty()) {
                    Child.Update(null, oldEvents.ToArray());
                }

                newToOldEventMap.Clear();
            }
        }
Beispiel #5
0
 public void Stop()
 {
     if (!_newToOldEventMap.IsEmpty())
     {
         var oldEvents = new OneEventCollection();
         foreach (var oldEvent in _newToOldEventMap)
         {
             oldEvents.Add(oldEvent.Value);
         }
         if (!oldEvents.IsEmpty())
         {
             UpdateChildren(null, oldEvents.ToArray());
         }
         _newToOldEventMap.Clear();
     }
 }
Beispiel #6
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_MERGE, triggerEvents, matchingEvents);
            }

            var newData = new OneEventCollection();
            OneEventCollection oldData = null;
            var eventsPerStream        = new EventBean[3]; // first:named window, second: trigger, third:before-update (optional)

            if ((matchingEvents == null) || (matchingEvents.Length == 0))
            {
                var unmatched = _parent.NamedWindowOnMergeHelper.Unmatched;

                foreach (var triggerEvent in triggerEvents)
                {
                    eventsPerStream[1] = triggerEvent;

                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().QInfraMergeWhenThens(false, triggerEvent, unmatched.Count);
                    }

                    var count = -1;
                    foreach (var action in unmatched)
                    {
                        count++;

                        if (InstrumentationHelper.ENABLED)
                        {
                            InstrumentationHelper.Get().QInfraMergeWhenThenItem(false, count);
                        }
                        if (!action.IsApplies(eventsPerStream, base.ExprEvaluatorContext))
                        {
                            if (InstrumentationHelper.ENABLED)
                            {
                                InstrumentationHelper.Get().AInfraMergeWhenThenItem(false, false);
                            }
                            continue;
                        }
                        action.Apply(null, eventsPerStream, newData, oldData, base.ExprEvaluatorContext);
                        if (InstrumentationHelper.ENABLED)
                        {
                            InstrumentationHelper.Get().AInfraMergeWhenThenItem(false, true);
                        }
                        break;      // apply no other actions
                    }

                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().AInfraMergeWhenThens(false);
                    }
                }
            }
            else
            {
                // handle update/
                oldData = new OneEventCollection();

                var matched = _parent.NamedWindowOnMergeHelper.Matched;

                foreach (var triggerEvent in triggerEvents)
                {
                    eventsPerStream[1] = triggerEvent;
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().QInfraMergeWhenThens(true, triggerEvent, matched.Count);
                    }

                    foreach (var matchingEvent in matchingEvents)
                    {
                        eventsPerStream[0] = matchingEvent;

                        var count = -1;
                        foreach (var action in matched)
                        {
                            count++;

                            if (InstrumentationHelper.ENABLED)
                            {
                                InstrumentationHelper.Get().QInfraMergeWhenThenItem(true, count);
                            }
                            if (!action.IsApplies(eventsPerStream, base.ExprEvaluatorContext))
                            {
                                if (InstrumentationHelper.ENABLED)
                                {
                                    InstrumentationHelper.Get().AInfraMergeWhenThenItem(true, false);
                                }
                                continue;
                            }
                            action.Apply(matchingEvent, eventsPerStream, newData, oldData, base.ExprEvaluatorContext);
                            if (InstrumentationHelper.ENABLED)
                            {
                                InstrumentationHelper.Get().AInfraMergeWhenThenItem(true, true);
                            }
                            break;      // apply no other actions
                        }
                    }

                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().AInfraMergeWhenThens(true);
                    }
                }
            }

            if (!newData.IsEmpty() || (oldData != null && !oldData.IsEmpty()))
            {
                if ((MetricReportingPath.IsMetricsEnabled) && (_parent.CreateNamedWindowMetricHandle.IsEnabled) && !newData.IsEmpty())
                {
                    _parent.MetricReportingService.AccountTime(_parent.CreateNamedWindowMetricHandle, 0, 0, newData.ToArray().Length);
                }

                // Events to delete are indicated via old data
                // The on-merge listeners receive the events deleted, but only if there is interest
                if (_parent.StatementResultService.IsMakeNatural)
                {
                    var eventsPerStreamNaturalNew = newData.IsEmpty() ? null : newData.ToArray();
                    var eventsPerStreamNaturalOld = (oldData == null || oldData.IsEmpty()) ? null : oldData.ToArray();
                    RootView.Update(EventBeanUtility.Denaturalize(eventsPerStreamNaturalNew), EventBeanUtility.Denaturalize(eventsPerStreamNaturalOld));
                    UpdateChildren(eventsPerStreamNaturalNew, eventsPerStreamNaturalOld);
                }
                else
                {
                    var eventsPerStreamNew = newData.IsEmpty() ? null : newData.ToArray();
                    var eventsPerStreamOld = (oldData == null || oldData.IsEmpty()) ? null : oldData.ToArray();
                    RootView.Update(eventsPerStreamNew, eventsPerStreamOld);
                    if (_parent.StatementResultService.IsMakeSynthetic)
                    {
                        UpdateChildren(eventsPerStreamNew, eventsPerStreamOld);
                    }
                }
            }

            // Keep the last delete records
            _lastResult = matchingEvents;
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
Beispiel #7
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QViewProcessIRStream(this, _rankWindowViewFactory.ViewName, newData, oldData);
            }

            var removedEvents = new OneEventCollection();

            // Remove old data
            if (oldData != null)
            {
                for (var i = 0; i < oldData.Length; i++)
                {
                    var uniqueKey       = GetUniqueValues(oldData[i]);
                    var existingSortKey = _uniqueKeySortKeys.Get(uniqueKey);

                    if (existingSortKey == null)
                    {
                        continue;
                    }

                    var theEvent = RemoveFromSortedEvents(existingSortKey, uniqueKey);
                    if (theEvent != null)
                    {
                        _numberOfEvents--;
                        _uniqueKeySortKeys.Remove(uniqueKey);
                        removedEvents.Add(theEvent);
                        InternalHandleRemovedKey(existingSortKey, oldData[i]);
                    }
                }
            }

            // Add new data
            if (newData != null)
            {
                for (var i = 0; i < newData.Length; i++)
                {
                    var uniqueKey       = GetUniqueValues(newData[i]);
                    var newSortKey      = GetSortValues(newData[i]);
                    var existingSortKey = _uniqueKeySortKeys.Get(uniqueKey);

                    // not currently found: its a new entry
                    if (existingSortKey == null)
                    {
                        CompareAndAddOrPassthru(newData[i], uniqueKey, newSortKey, removedEvents);
                    }
                    // same unique-key event found already, remove and add again
                    else
                    {
                        // key did not change, perform in-place substitute of event
                        if (existingSortKey.Equals(newSortKey))
                        {
                            var replaced = InplaceReplaceSortedEvents(existingSortKey, uniqueKey, newData[i]);
                            if (replaced != null)
                            {
                                removedEvents.Add(replaced);
                            }
                            InternalHandleReplacedKey(newSortKey, newData[i], replaced);
                        }
                        else
                        {
                            var removed = RemoveFromSortedEvents(existingSortKey, uniqueKey);
                            if (removed != null)
                            {
                                _numberOfEvents--;
                                removedEvents.Add(removed);
                                InternalHandleRemovedKey(existingSortKey, removed);
                            }
                            CompareAndAddOrPassthru(newData[i], uniqueKey, newSortKey, removedEvents);
                        }
                    }
                }
            }

            // Remove data that sorts to the bottom of the window
            if (_numberOfEvents > _sortWindowSize)
            {
                while (_numberOfEvents > _sortWindowSize)
                {
                    var lastKey  = _sortedEvents.Keys.Last();
                    var existing = _sortedEvents.Get(lastKey);
                    if (existing is IList <EventBean> )
                    {
                        var existingList = (IList <EventBean>)existing;
                        while (_numberOfEvents > _sortWindowSize && !existingList.IsEmpty())
                        {
                            var newestEvent = existingList.DeleteAt(0);
                            var uniqueKey   = GetUniqueValues(newestEvent);
                            _uniqueKeySortKeys.Remove(uniqueKey);
                            _numberOfEvents--;
                            removedEvents.Add(newestEvent);
                            InternalHandleRemovedKey(existing, newestEvent);
                        }
                        if (existingList.IsEmpty())
                        {
                            _sortedEvents.Remove(lastKey);
                        }
                    }
                    else
                    {
                        var lastSortedEvent = (EventBean)existing;
                        var uniqueKey       = GetUniqueValues(lastSortedEvent);
                        _uniqueKeySortKeys.Remove(uniqueKey);
                        _numberOfEvents--;
                        removedEvents.Add(lastSortedEvent);
                        _sortedEvents.Remove(lastKey);
                        InternalHandleRemovedKey(lastKey, lastSortedEvent);
                    }
                }
            }

            // If there are child views, fireStatementStopped Update method
            if (_optionalRankedRandomAccess != null)
            {
                _optionalRankedRandomAccess.Refresh(_sortedEvents, _numberOfEvents, _sortWindowSize);
            }
            if (HasViews)
            {
                EventBean[] expiredArr = null;
                if (!removedEvents.IsEmpty())
                {
                    expiredArr = removedEvents.ToArray();
                }

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QViewIndicate(this, _rankWindowViewFactory.ViewName, newData, expiredArr);
                }
                UpdateChildren(newData, expiredArr);
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AViewIndicate();
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AViewProcessIRStream();
            }
        }