Esempio n. 1
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.InstrumentationProvider.QInfraOnAction(
                OnTriggerType.ON_MERGE,
                newData,
                CollectionUtil.EVENTBEANARRAY_EMPTY);

            if (newData == null) {
                agentInstanceContext.InstrumentationProvider.AInfraOnAction();
                return;
            }

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

            foreach (var trigger in newData) {
                eventsPerStream[1] = trigger;
                factory.OnMergeHelper.InsertUnmatched.Apply(null, eventsPerStream, newColl, null, agentInstanceContext);
                OnExprViewNamedWindowMerge.ApplyDelta(newColl, null, factory, rootView, agentInstanceContext, this);
                newColl.Clear();
            }

            agentInstanceContext.InstrumentationProvider.AInfraOnAction();
        }
Esempio n. 2
0
        private EventBean[] PassFilter(
            EventBean[] eventData,
            bool isNewData,
            ExprEvaluatorContext exprEvaluatorContext,
            EventBean[] eventPerStream)
        {
            if (eventData == null || eventData.Length == 0) {
                return null;
            }

            if (eventData.Length == 1) {
                eventPerStream[0] = eventData[0];
                var result = Filter.Evaluate(eventPerStream, isNewData, exprEvaluatorContext);
                return result != null && true.Equals(result) ? eventData : null;
            }

            OneEventCollection filtered = null;
            foreach (var theEvent in eventData) {
                eventPerStream[0] = theEvent;
                var result = Filter.Evaluate(eventPerStream, isNewData, exprEvaluatorContext);
                if (result == null || false.Equals(result)) {
                    continue;
                }

                if (filtered == null) {
                    filtered = new OneEventCollection();
                }

                filtered.Add(theEvent);
            }

            return filtered?.ToArray();
        }
Esempio n. 3
0
        public override void Apply(
            EventBean matchingEvent,
            EventBean[] eventsPerStream,
            OneEventCollection newData,
            OneEventCollection oldData,
            AgentInstanceContext agentInstanceContext)
        {
            var theEvent = insertHelper.Process(eventsPerStream, true, true, agentInstanceContext);

            if (insertIntoTable != null) {
                var tableInstance = insertIntoTable.GetTableInstance(agentInstanceContext.AgentInstanceId);
                tableInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (!route) {
                newData.Add(theEvent);
                return;
            }
            
            if (insertIntoTable != null) {
                var tableInstance = insertIntoTable.GetTableInstance(agentInstanceContext.AgentInstanceId);
                tableInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (audit) {
                agentInstanceContext.AuditProvider.Insert(theEvent, agentInstanceContext);
            }

            agentInstanceContext.InternalEventRouter.Route(theEvent, agentInstanceContext, false);
        }
Esempio n. 4
0
        private void CompareAndAddOrPassthru(
            EventBean eventBean,
            object uniqueKey,
            object newSortKey,
            OneEventCollection removedEvents)
        {
            // determine full or not
            if (_numberOfEvents >= _sortWindowSize) {
                var compared = _rankWindowViewFactory.Comparer.Compare(_sortedEvents.Keys.Last(), newSortKey);

                // this new event will fall outside of the ranks or coincides with the last entry, so its an old event already
                if (compared < 0) {
                    removedEvents.Add(eventBean);
                }
                else {
                    // this new event is higher in sort key then the last entry so we are interested
                    _uniqueKeySortKeys.Put(uniqueKey, newSortKey);
                    _numberOfEvents++;
                    CollectionUtil.AddEventByKeyLazyListMapBack(newSortKey, eventBean, _sortedEvents);
                    InternalHandleAddedKey(newSortKey, eventBean);
                }
            }
            else {
                // not yet filled, need to add
                _uniqueKeySortKeys.Put(uniqueKey, newSortKey);
                _numberOfEvents++;
                CollectionUtil.AddEventByKeyLazyListMapBack(newSortKey, eventBean, _sortedEvents);
                InternalHandleAddedKey(newSortKey, eventBean);
            }
        }
Esempio n. 5
0
        public void ApplyNamedWindow(
            EventBean matchingEvent,
            EventBean[] eventsPerStream,
            OneEventCollection newData,
            OneEventCollection oldData,
            AgentInstanceContext agentInstanceContext)
        {
            InstrumentationCommon instrumentationCommon = agentInstanceContext.InstrumentationProvider;
            instrumentationCommon.QInfraMergeWhenThenActions(actions.Count);

            int count = -1;
            foreach (InfraOnMergeAction action in actions) {
                count++;
                instrumentationCommon.QInfraMergeWhenThenActionItem(count, action.Name);

                bool applies = action.IsApplies(eventsPerStream, agentInstanceContext);
                if (applies) {
                    action.Apply(matchingEvent, eventsPerStream, newData, oldData, agentInstanceContext);
                }

                instrumentationCommon.AInfraMergeWhenThenActionItem(applies);
            }

            instrumentationCommon.AInfraMergeWhenThenActions();
        }
Esempio n. 6
0
 public override void Apply(
     EventBean matchingEvent,
     EventBean[] eventsPerStream,
     OneEventCollection newData,
     OneEventCollection oldData,
     AgentInstanceContext agentInstanceContext)
 {
     oldData.Add(matchingEvent);
 }
Esempio n. 7
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewProcessIRStream(this, _lengthFirstFactory.ViewName, newData, oldData); }

            OneEventCollection newDataToPost = null;
            OneEventCollection oldDataToPost = null;

            // add data points to the window as long as its not full, ignoring later events
            if (newData != null)
            {
                foreach (EventBean aNewData in newData)
                {
                    if (_indexedEvents.Count < Size)
                    {
                        if (newDataToPost == null)
                        {
                            newDataToPost = new OneEventCollection();
                        }
                        newDataToPost.Add(aNewData);
                        _indexedEvents.Add(aNewData);
                        InternalHandleAdded(aNewData);
                    }
                }
            }

            if (oldData != null)
            {
                foreach (EventBean anOldData in oldData)
                {
                    bool removed = _indexedEvents.Remove(anOldData);
                    if (removed)
                    {
                        if (oldDataToPost == null)
                        {
                            oldDataToPost = new OneEventCollection();
                        }
                        oldDataToPost.Add(anOldData);
                        InternalHandleRemoved(anOldData);
                    }
                }
            }

            // If there are child views, call Update method
            if (HasViews && ((newDataToPost != null) || (oldDataToPost != null)))
            {
                EventBean[] nd = (newDataToPost != null) ? newDataToPost.ToArray() : null;
                EventBean[] od = (oldDataToPost != null) ? oldDataToPost.ToArray() : null;
                if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QViewIndicate(this, _lengthFirstFactory.ViewName, nd, od); }
                UpdateChildren(nd, od);
                if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewIndicate(); }
            }

            if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AViewProcessIRStream(); }
        }
Esempio n. 8
0
 public override void Apply(
     EventBean matchingEvent,
     EventBean[] eventsPerStream,
     OneEventCollection newData,
     OneEventCollection oldData,
     AgentInstanceContext agentInstanceContext)
 {
     var copy = namedWindowUpdate.Invoke(matchingEvent, eventsPerStream, agentInstanceContext);
     newData.Add(copy);
     oldData.Add(matchingEvent);
 }
 public void Add(EventBean theEvent, EventBean[] eventsPerStream, bool isNewData, ExprEvaluatorContext context)
 {
     if (_coll == null)
     {
         _coll = new OneEventCollection();
     }
     if (theEvent is NaturalEventBean)
     {
         theEvent = ((NaturalEventBean)theEvent).OptionalSynthetic;
     }
     _coll.Add(_tableMetadata.EventToPublic.Convert(theEvent, eventsPerStream, isNewData, context));
 }
Esempio n. 10
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            using (Instrument.With(
                       i => i.QViewProcessIRStream(this, _timeFirstViewFactory.ViewName, newData, oldData),
                       i => i.AViewProcessIRStream()))
            {
                OneEventCollection oldDataToPost = null;
                if (oldData != null)
                {
                    foreach (EventBean anOldData in oldData)
                    {
                        bool removed = _events.Remove(anOldData);
                        if (removed)
                        {
                            if (oldDataToPost == null)
                            {
                                oldDataToPost = new OneEventCollection();
                            }
                            oldDataToPost.Add(anOldData);
                            InternalHandleRemoved(anOldData);
                        }
                    }
                }

                // add data points to the timeWindow
                OneEventCollection newDataToPost = null;
                if ((!_isClosed) && (newData != null))
                {
                    foreach (EventBean aNewData in newData)
                    {
                        _events.Add(aNewData);
                        if (newDataToPost == null)
                        {
                            newDataToPost = new OneEventCollection();
                        }
                        newDataToPost.Add(aNewData);
                        InternalHandleAdded(aNewData);
                    }
                }

                // If there are child views, call Update method
                if ((HasViews) && ((newDataToPost != null) || (oldDataToPost != null)))
                {
                    EventBean[] nd = (newDataToPost != null) ? newDataToPost.ToArray() : null;
                    EventBean[] od = (oldDataToPost != null) ? oldDataToPost.ToArray() : null;
                    Instrument.With(
                        i => i.QViewIndicate(this, _timeFirstViewFactory.ViewName, nd, od),
                        i => i.AViewIndicate(),
                        () => UpdateChildren(nd, od));
                }
            }
        }
Esempio n. 11
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();
            }
        }
        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();
            }
        }
Esempio n. 13
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, lengthFirstFactory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(lengthFirstFactory, newData, oldData);

            OneEventCollection newDataToPost = null;
            OneEventCollection oldDataToPost = null;

            // add data points to the window as long as its not full, ignoring later events
            if (newData != null) {
                foreach (var aNewData in newData) {
                    if (indexedEvents.Count < Size) {
                        if (newDataToPost == null) {
                            newDataToPost = new OneEventCollection();
                        }

                        newDataToPost.Add(aNewData);
                        indexedEvents.Add(aNewData);
                    }
                }
            }

            if (oldData != null) {
                foreach (var anOldData in oldData) {
                    var removed = indexedEvents.Remove(anOldData);
                    if (removed) {
                        if (oldDataToPost == null) {
                            oldDataToPost = new OneEventCollection();
                        }

                        oldDataToPost.Add(anOldData);
                    }
                }
            }

            // If there are child views, call update method
            if (child != null && (newDataToPost != null || oldDataToPost != null)) {
                var nd = newDataToPost != null ? newDataToPost.ToArray() : null;
                var od = oldDataToPost != null ? oldDataToPost.ToArray() : null;
                agentInstanceContext.InstrumentationProvider.QViewIndicate(lengthFirstFactory, nd, od);
                child.Update(nd, od);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Esempio n. 14
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();
     }
 }
Esempio n. 15
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();
        }
Esempio n. 16
0
        private EventBean[] PassFilter(EventBean[] eventData, bool isNewData, ExprEvaluatorContext exprEvaluatorContext, EventBean[] eventPerStream)
        {
            if ((eventData == null) || (eventData.Length == 0))
            {
                return(null);
            }

            OneEventCollection filtered = null;

            foreach (EventBean theEvent in eventData)
            {
                eventPerStream[0] = theEvent;
                bool pass = true;
                foreach (ExprEvaluator filter in _filterList)
                {
                    var result = (bool?)filter.Evaluate(new EvaluateParams(eventPerStream, isNewData, exprEvaluatorContext));
                    if (result == null || !result.Value)
                    {
                        pass = false;
                        break;
                    }
                }

                if (pass)
                {
                    if (filtered == null)
                    {
                        filtered = new OneEventCollection();
                    }
                    filtered.Add(theEvent);
                }
            }

            if (filtered == null)
            {
                return(null);
            }
            return(filtered.ToArray());
        }
Esempio n. 17
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);
                    }
                }
            }
        }
Esempio n. 18
0
        public void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext context)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraMergeWhenThenActions(_actions.Count);
            }

            int count = -1;

            foreach (NamedWindowOnMergeAction action in _actions)
            {
                count++;

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QInfraMergeWhenThenActionItem(count, action.GetName());
                    bool applies = action.IsApplies(eventsPerStream, context);
                    if (applies)
                    {
                        action.Apply(matchingEvent, eventsPerStream, newData, oldData, context);
                    }
                    InstrumentationHelper.Get().AInfraMergeWhenThenActionItem(applies);
                    continue;
                }

                if (action.IsApplies(eventsPerStream, context))
                {
                    action.Apply(matchingEvent, eventsPerStream, newData, oldData, context);
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraMergeWhenThenActions();
            }
        }
Esempio n. 19
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();
            }
        }
Esempio n. 20
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QViewProcessIRStream(this, UniqueByPropertyViewFactory.NAME, newData, oldData);
            }
            OneEventCollection postOldData = null;

            if (HasViews)
            {
                postOldData = new OneEventCollection();
            }

            if (newData != null)
            {
                for (var i = 0; i < newData.Length; i++)
                {
                    // Obtain unique value
                    var key = GetUniqueKey(newData[i]);

                    // If there are no child views, just update the own collection
                    if (!HasViews)
                    {
                        _mostRecentEvents.Put(key, newData[i]);
                        continue;
                    }

                    // Post the last value as old data
                    var lastValue = _mostRecentEvents.Get(key);
                    if (lastValue != null)
                    {
                        postOldData.Add(lastValue);
                    }

                    // Override with recent event
                    _mostRecentEvents.Put(key, newData[i]);
                }
            }

            if (oldData != null)
            {
                for (var i = 0; i < oldData.Length; i++)
                {
                    // Obtain unique value
                    var key = GetUniqueKey(oldData[i]);

                    // If the old event is the current unique event, remove and post as old data
                    var lastValue = _mostRecentEvents.Get(key);
                    if (lastValue == null || !lastValue.Equals(oldData[i]))
                    {
                        continue;
                    }

                    postOldData.Add(lastValue);
                    _mostRecentEvents.Remove(key);
                }
            }

            // If there are child views, fireStatementStopped update method
            if (HasViews)
            {
                if (postOldData.IsEmpty())
                {
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().QViewIndicate(this, UniqueByPropertyViewFactory.NAME, newData, null);
                    }
                    UpdateChildren(newData, null);
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().AViewIndicate();
                    }
                }
                else
                {
                    var postOldDataArray = postOldData.ToArray();
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().QViewIndicate(this, UniqueByPropertyViewFactory.NAME, newData, postOldDataArray);
                    }
                    UpdateChildren(newData, postOldDataArray);
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().AViewIndicate();
                    }
                }
            }
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AViewProcessIRStream();
            }
        }
Esempio n. 21
0
        // Called based on schedule evaluation registered when a variable changes (new data is null).
        // Called when new data arrives.
        private void Expire(EventBean[] newData, EventBean[] oldData)
        {
            OneEventCollection expired = null;

            if (oldData != null)
            {
                expired = new OneEventCollection();
                expired.Add(oldData);
            }
            int expiredCount = 0;

            if (!_window.IsEmpty())
            {
                ExpressionWindowTimestampEventPair newest = _window.Last;

                while (true)
                {
                    ExpressionWindowTimestampEventPair first = _window.First;

                    bool pass = CheckEvent(first, newest, expiredCount);
                    if (!pass)
                    {
                        if (expired == null)
                        {
                            expired = new OneEventCollection();
                        }
                        EventBean removed = _window.RemoveFirst().TheEvent;
                        expired.Add(removed);
                        if (AggregationService != null)
                        {
                            _removedEvents[0] = removed;
                            AggregationService.ApplyLeave(_removedEvents, null, AgentInstanceContext);
                        }
                        expiredCount++;
                        InternalHandleExpired(first);
                    }
                    else
                    {
                        break;
                    }

                    if (_window.IsEmpty())
                    {
                        if (AggregationService != null)
                        {
                            AggregationService.ClearResults(AgentInstanceContext);
                        }
                        break;
                    }
                }
            }

            // Check for any events that get pushed out of the window
            EventBean[] expiredArr = null;
            if (expired != null)
            {
                expiredArr = expired.ToArray();
            }

            // update event buffer for access by expressions, if any
            if (ViewUpdatedCollection != null)
            {
                ViewUpdatedCollection.Update(newData, expiredArr);
            }

            // If there are child views, call update method
            if (HasViews)
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QViewIndicate(this, _dataWindowViewFactory.ViewName, newData, expiredArr);
                }
                UpdateChildren(newData, expiredArr);
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().AViewIndicate();
                }
            }
        }
Esempio n. 22
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            // handle remove stream
            OneEventCollection oldDataColl = null;

            EventBean[] newDataPosted = null;
            if (oldData != null)
            {
                _isDiscardObserverEvents = true; // disable reaction logic in observer

                try
                {
                    foreach (var view in _views)
                    {
                        view.Update(null, oldData);
                    }
                }
                finally
                {
                    _isDiscardObserverEvents = false;
                }

                // remove from union
                foreach (var oldEvent in oldData)
                {
                    _unionWindow.RemoveAll(oldEvent);
                }

                oldDataColl = new OneEventCollection();
                oldDataColl.Add(oldData);
            }

            // add new event to union
            if (newData != null)
            {
                var removedByView = new bool[newData.Length, _views.Length];
                foreach (var newEvent in newData)
                {
                    _unionWindow.Add(newEvent, _views.Length);
                }

                // new events must go to all views
                // old events, such as when removing from a named window, get removed from all views
                _isHasRemovestreamData  = false; // changed by observer logic to indicate new data
                _isRetainObserverEvents = true;  // enable retain logic in observer
                try
                {
                    for (var viewIndex = 0; viewIndex < _views.Length; viewIndex++)
                    {
                        var view = _views[viewIndex];
                        view.Update(newData, null);

                        // first-X asymetric view post no insert stream for events that get dropped, remove these
                        if (_newDataChildView != null)
                        {
                            for (var i = 0; i < newData.Length; i++)
                            {
                                var found = false;
                                for (var j = 0; j < _newDataChildView.Length; j++)
                                {
                                    if (_newDataChildView[i] == newData[i])
                                    {
                                        found = true;
                                        break;
                                    }
                                }
                                if (!found)
                                {
                                    removedByView[i, viewIndex] = true;
                                }
                            }
                        }
                        else
                        {
                            for (var i = 0; i < newData.Length; i++)
                            {
                                removedByView[i, viewIndex] = true;
                            }
                        }
                    }
                }
                finally
                {
                    _isRetainObserverEvents = false;
                }

                // determine removed events, those that have a "true" in the remove by view index for all views
                _removalEvents.Clear();
                for (var i = 0; i < newData.Length; i++)
                {
                    var allTrue = true;
                    for (var j = 0; j < _views.Length; j++)
                    {
                        if (!removedByView[i, j])
                        {
                            allTrue = false;
                            break;
                        }
                    }
                    if (allTrue)
                    {
                        _removalEvents.Add(newData[i]);
                        _unionWindow.RemoveAll(newData[i]);
                    }
                }

                // remove if any
                if (_removalEvents.IsNotEmpty())
                {
                    _isDiscardObserverEvents = true;
                    var viewOldData = _removalEvents.ToArray();
                    try
                    {
                        for (var j = 0; j < _views.Length; j++)
                        {
                            _views[j].Update(null, viewOldData);
                        }
                    }
                    finally
                    {
                        _isDiscardObserverEvents = false;
                    }
                }

                // see if any child view has removed any events.
                // if there was an insert stream, handle pushed-out events
                if (_isHasRemovestreamData)
                {
                    IList <EventBean> removedEvents = null;

                    // process each buffer
                    for (var i = 0; i < _oldEventsPerView.Length; i++)
                    {
                        if (_oldEventsPerView[i] == null)
                        {
                            continue;
                        }

                        var viewOldData = _oldEventsPerView[i];
                        _oldEventsPerView[i] = null; // clear entry

                        // remove events for union, if the last event was removed then add it
                        foreach (var old in viewOldData)
                        {
                            var isNoMoreRef = _unionWindow.Remove(old);
                            if (isNoMoreRef)
                            {
                                if (removedEvents == null)
                                {
                                    _removalEvents.Clear();
                                    removedEvents = _removalEvents;
                                }
                                removedEvents.Add(old);
                            }
                        }
                    }

                    if (removedEvents != null)
                    {
                        if (oldDataColl == null)
                        {
                            oldDataColl = new OneEventCollection();
                        }
                        foreach (var oldItem in removedEvents)
                        {
                            oldDataColl.Add(oldItem);
                        }
                    }
                }

                _newEvents.Clear();
                for (var i = 0; i < newData.Length; i++)
                {
                    if (!_removalEvents.Contains(newData[i]))
                    {
                        _newEvents.Add(newData[i]);
                    }
                }

                if (_newEvents.IsNotEmpty())
                {
                    newDataPosted = _newEvents.ToArray();
                }
            }

            // indicate new and, possibly, old data
            if (HasViews && ((newDataPosted != null) || (oldDataColl != null)))
            {
                UpdateChildren(newDataPosted, oldDataColl != null ? oldDataColl.ToArray() : null);
            }
        }
Esempio n. 23
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            using (Instrument.With(
                       i => i.QViewProcessIRStream(this, _unionViewFactory.ViewName, newData, oldData),
                       i => i.AViewProcessIRStream()))
            {
                OneEventCollection oldDataColl = null;
                if (oldData != null)
                {
                    _isDiscardObserverEvents = true; // disable reaction logic in observer

                    try
                    {
                        foreach (View view in _views)
                        {
                            view.Update(null, oldData);
                        }
                    }
                    finally
                    {
                        _isDiscardObserverEvents = false;
                    }

                    // remove from union
                    foreach (EventBean oldEvent in oldData)
                    {
                        _unionWindow.RemoveAll(oldEvent);
                    }

                    oldDataColl = new OneEventCollection();
                    oldDataColl.Add(oldData);
                }

                // add new event to union
                if (newData != null)
                {
                    foreach (EventBean newEvent in newData)
                    {
                        _unionWindow.Add(newEvent, _views.Length);
                    }

                    // new events must go to all views
                    // old events, such as when removing from a named window, get removed from all views
                    _isHasRemovestreamData  = false; // changed by observer logic to indicate new data
                    _isRetainObserverEvents = true;  // enable retain logic in observer
                    try
                    {
                        foreach (View view in _views)
                        {
                            view.Update(newData, null);
                        }
                    }
                    finally
                    {
                        _isRetainObserverEvents = false;
                    }

                    // see if any child view has removed any events.
                    // if there was an insert stream, handle pushed-out events
                    if (_isHasRemovestreamData)
                    {
                        IList <EventBean> removedEvents = null;

                        // process each buffer
                        for (int i = 0; i < _oldEventsPerView.Length; i++)
                        {
                            if (_oldEventsPerView[i] == null)
                            {
                                continue;
                            }

                            EventBean[] viewOldData = _oldEventsPerView[i];
                            _oldEventsPerView[i] = null; // clear entry

                            // remove events for union, if the last event was removed then add it
                            foreach (EventBean old in viewOldData)
                            {
                                bool isNoMoreRef = _unionWindow.Remove(old);
                                if (isNoMoreRef)
                                {
                                    if (removedEvents == null)
                                    {
                                        _removalEvents.Clear();
                                        removedEvents = _removalEvents;
                                    }
                                    removedEvents.Add(old);
                                }
                            }
                        }

                        if (removedEvents != null)
                        {
                            if (oldDataColl == null)
                            {
                                oldDataColl = new OneEventCollection();
                            }
                            foreach (EventBean oldItem in removedEvents)
                            {
                                oldDataColl.Add(oldItem);
                            }
                        }
                    }
                }

                if (HasViews)
                {
                    // indicate new and, possibly, old data
                    EventBean[] oldEvents = oldDataColl != null?oldDataColl.ToArray() : null;

                    Instrument.With(
                        i => i.QViewIndicate(this, _unionViewFactory.ViewName, newData, oldEvents),
                        i => i.AViewIndicate(),
                        () => UpdateChildren(newData, oldEvents));
                }
            }
        }
Esempio n. 24
0
 public abstract void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext);
Esempio n. 25
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            _agentInstanceContext.AuditProvider.View(newData, oldData, _agentInstanceContext, _viewFactory);
            _agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(_viewFactory, newData, oldData);

            if (newData != null && newData.Length == 1 && (oldData == null || oldData.Length == 0)) {
                // Shortcut
                var key = GetUniqueKey(newData[0]);
                var lastValue = _mostRecentEvents.Push(key, newData[0]);
                if (child != null) {
                    var oldDataToPost = lastValue == null ? null : new[] {lastValue};
                    _agentInstanceContext.InstrumentationProvider.QViewIndicate(_viewFactory, newData, oldDataToPost);
                    child.Update(newData, oldDataToPost);
                    _agentInstanceContext.InstrumentationProvider.AViewIndicate();
                }
            }
            else {
                OneEventCollection postOldData = null;

                if (child != null) {
                    postOldData = new OneEventCollection();
                }

                if (newData != null) {
                    for (var i = 0; i < newData.Length; i++) {
                        // Obtain unique value
                        var key = GetUniqueKey(newData[i]);

                        // If there are no child views, just update the own collection
                        if (child == null) {
                            _mostRecentEvents.Put(key, newData[i]);
                            continue;
                        }

                        // Post the last value as old data
                        var lastValue = _mostRecentEvents.Get(key);
                        if (lastValue != null) {
                            postOldData?.Add(lastValue);
                        }

                        // Override with recent event
                        _mostRecentEvents.Put(key, newData[i]);
                    }
                }

                if (oldData != null) {
                    for (var i = 0; i < oldData.Length; i++) {
                        // Obtain unique value
                        var key = GetUniqueKey(oldData[i]);

                        // If the old event is the current unique event, remove and post as old data
                        var lastValue = _mostRecentEvents.Get(key);
                        if (lastValue == null || !lastValue.Equals(oldData[i])) {
                            continue;
                        }

                        postOldData?.Add(lastValue);
                        _mostRecentEvents.Remove(key);
                    }
                }

                // If there are child views, fireStatementStopped update method
                if (child != null) {
                    if (postOldData.IsEmpty()) {
                        _agentInstanceContext.InstrumentationProvider.QViewIndicate(_viewFactory, newData, null);
                        child.Update(newData, null);
                        _agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                    else {
                        EventBean[] postOldDataArray = postOldData.ToArray();
                        _agentInstanceContext.InstrumentationProvider.QViewIndicate(
                            _viewFactory,
                            newData,
                            postOldDataArray);
                        child.Update(newData, postOldDataArray);
                        _agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                }
            }

            _agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Esempio n. 26
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QViewProcessIRStream(this, _sortWindowViewFactory.ViewName, newData, oldData);
            }

            OneEventCollection removedEvents = null;

            // Remove old data
            if (oldData != null)
            {
                for (var i = 0; i < oldData.Length; i++)
                {
                    var oldDataItem = oldData[i];
                    var sortValues  = GetSortValues(oldDataItem);
                    var result      = CollectionUtil.RemoveEventByKeyLazyListMap(sortValues, oldDataItem, _sortedEvents);
                    if (result)
                    {
                        _eventCount--;
                        if (removedEvents == null)
                        {
                            removedEvents = new OneEventCollection();
                        }
                        removedEvents.Add(oldDataItem);
                        InternalHandleRemoved(sortValues, oldDataItem);
                    }
                }
            }

            // Add new data
            if (newData != null)
            {
                for (var i = 0; i < newData.Length; i++)
                {
                    var newDataItem = newData[i];
                    var sortValues  = GetSortValues(newDataItem);
                    CollectionUtil.AddEventByKeyLazyListMapFront(sortValues, newDataItem, _sortedEvents);
                    _eventCount++;
                    InternalHandleAdd(sortValues, newDataItem);
                }
            }

            // Remove data that sorts to the bottom of the window
            if (_eventCount > _sortWindowSize)
            {
                var removeCount = _eventCount - _sortWindowSize;
                for (var i = 0; i < removeCount; i++)
                {
                    // Remove the last element of the last key - sort order is key and then natural order of arrival
                    var lastKey   = _sortedEvents.Keys.Last();
                    var lastEntry = _sortedEvents.Get(lastKey);
                    if (lastEntry is IList <EventBean> )
                    {
                        var events   = (IList <EventBean>)lastEntry;
                        var theEvent = events.DeleteAt(events.Count - 1);  // remove oldest event, newest events are first in list
                        _eventCount--;
                        if (events.IsEmpty())
                        {
                            _sortedEvents.Remove(lastKey);
                        }
                        if (removedEvents == null)
                        {
                            removedEvents = new OneEventCollection();
                        }
                        removedEvents.Add(theEvent);
                        InternalHandleRemoved(lastKey, theEvent);
                    }
                    else
                    {
                        var theEvent = (EventBean)lastEntry;
                        _eventCount--;
                        _sortedEvents.Remove(lastKey);
                        if (removedEvents == null)
                        {
                            removedEvents = new OneEventCollection();
                        }
                        removedEvents.Add(theEvent);
                        InternalHandleRemoved(lastKey, theEvent);
                    }
                }
            }

            // If there are child views, fireStatementStopped Update method
            if (_optionalSortedRandomAccess != null)
            {
                _optionalSortedRandomAccess.Refresh(_sortedEvents, _eventCount, _sortWindowSize);
            }

            if (HasViews)
            {
                EventBean[] expiredArr = null;
                if (removedEvents != null)
                {
                    expiredArr = removedEvents.ToArray();
                }

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

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AViewProcessIRStream();
            }
        }
Esempio n. 27
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, ViewFactory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(ViewFactory, newData, oldData);

            OneEventCollection oldDataColl = null;
            if (oldData != null) {
                isDiscardObserverEvents = true; // disable reaction logic in observer

                try {
                    foreach (var view in views) {
                        agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, null, oldData);
                        view.Update(null, oldData);
                        agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                }
                finally {
                    isDiscardObserverEvents = false;
                }

                // remove from union
                foreach (var oldEvent in oldData) {
                    unionWindow.RemoveAll(oldEvent);
                }

                oldDataColl = new OneEventCollection();
                oldDataColl.Add(oldData);
            }

            // add new event to union
            if (newData != null) {
                foreach (var newEvent in newData) {
                    unionWindow.Add(newEvent, views.Length);
                }

                // new events must go to all views
                // old events, such as when removing from a named window, get removed from all views
                isHasRemovestreamData = false; // changed by observer logic to indicate new data
                isRetainObserverEvents = true; // enable retain logic in observer
                try {
                    foreach (var view in views) {
                        agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newData, null);
                        view.Update(newData, null);
                        agentInstanceContext.InstrumentationProvider.AViewIndicate();
                    }
                }
                finally {
                    isRetainObserverEvents = false;
                }

                // see if any child view has removed any events.
                // if there was an insert stream, handle pushed-out events
                if (isHasRemovestreamData) {
                    IList<EventBean> removedEvents = null;

                    // process each buffer
                    for (var i = 0; i < oldEventsPerView.Length; i++) {
                        if (oldEventsPerView[i] == null) {
                            continue;
                        }

                        var viewOldData = oldEventsPerView[i];
                        oldEventsPerView[i] = null; // clear entry

                        // remove events for union, if the last event was removed then add it
                        foreach (var old in viewOldData) {
                            var isNoMoreRef = unionWindow.Remove(old);
                            if (isNoMoreRef) {
                                if (removedEvents == null) {
                                    removalEvents.Clear();
                                    removedEvents = removalEvents;
                                }

                                removedEvents.Add(old);
                            }
                        }
                    }

                    if (removedEvents != null) {
                        if (oldDataColl == null) {
                            oldDataColl = new OneEventCollection();
                        }

                        foreach (var oldItem in removedEvents) {
                            oldDataColl.Add(oldItem);
                        }
                    }
                }
            }

            if (child != null) {
                // indicate new and, possibly, old data
                var oldEvents = oldDataColl != null ? oldDataColl.ToArray() : null;
                agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newData, oldEvents);
                child.Update(newData, oldEvents);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Esempio n. 28
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();
            }
        }
Esempio n. 29
0
 public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext)
 {
     oldData.Add(matchingEvent);
 }
Esempio n. 30
0
        public override void Apply(EventBean matchingEvent, EventBean[] eventsPerStream, OneEventCollection newData, OneEventCollection oldData, ExprEvaluatorContext exprEvaluatorContext)
        {
            EventBean theEvent = _insertHelper.Process(eventsPerStream, true, true, exprEvaluatorContext);

            if (_insertIntoTableName != null)
            {
                TableStateInstance tableStateInstance = _tableService.GetState(_insertIntoTableName, exprEvaluatorContext.AgentInstanceId);
                if (_audit)
                {
                    AuditPath.AuditInsertInto(tableStateInstance.AgentInstanceContext.EngineURI, _statementHandle.StatementName, theEvent);
                }
                tableStateInstance.AddEventUnadorned(theEvent);
                return;
            }

            if (_internalEventRouter == null)
            {
                newData.Add(theEvent);
                return;
            }

            if (_audit)
            {
                AuditPath.AuditInsertInto(_internalEventRouteDest.EngineURI, _statementHandle.StatementName, theEvent);
            }
            _internalEventRouter.Route(theEvent, _statementHandle, _internalEventRouteDest, exprEvaluatorContext, false);
        }