Exemplo n.º 1
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, timeWindowViewFactory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(timeWindowViewFactory, newData, oldData);
            var timestamp = agentInstanceContext.StatementContext.SchedulingService.Time;

            if (oldData != null) {
                for (var i = 0; i < oldData.Length; i++) {
                    timeWindow.Remove(oldData[i]);
                }
            }

            // we don't care about removed data from a prior view
            if (newData != null && newData.Length > 0) {
                // If we have an empty window about to be filled for the first time, schedule a callback
                // for now plus millisecondsBeforeExpiry
                if (timeWindow.IsEmpty()) {
                    var current = agentInstanceContext.StatementContext.SchedulingService.Time;
                    ScheduleCallback(timePeriodProvide.DeltaAdd(current, null, true, agentInstanceContext));
                }

                // add data points to the timeWindow
                for (var i = 0; i < newData.Length; i++) {
                    timeWindow.Add(timestamp, newData[i]);
                }

                ViewUpdatedCollection?.Update(newData, null);
            }

            // update child views
            agentInstanceContext.InstrumentationProvider.QViewIndicate(timeWindowViewFactory, newData, oldData);
            Child.Update(newData, oldData);
            agentInstanceContext.InstrumentationProvider.AViewIndicate();

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Exemplo n.º 2
0
 protected void ScheduleCallback(long delta)
 {
     ScheduleHandleCallback callback = new ProxyScheduleHandleCallback {
         ProcScheduledTrigger = () => {
             agentInstanceContext.AuditProvider.ScheduleFire(
                 agentInstanceContext,
                 ScheduleObjectType.view,
                 factory.ViewName);
             agentInstanceContext.InstrumentationProvider.QViewScheduledEval(factory);
             SendBatch(true);
             agentInstanceContext.InstrumentationProvider.AViewScheduledEval();
         }
     };
     handle = new EPStatementHandleCallbackSchedule(
         agentInstanceContext.EpStatementAgentInstanceHandle,
         callback);
     var currentTime = agentInstanceContext.StatementContext.SchedulingService.Time;
     var scheduled = timePeriodProvide.DeltaAdd(currentTime, null, true, agentInstanceContext) - delta;
     agentInstanceContext.StatementContext.SchedulingService.Add(scheduled, handle, scheduleSlot);
     callbackScheduledTime = agentInstanceContext.StatementContext.SchedulingService.Time + scheduled;
 }
Exemplo n.º 3
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, factory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(factory, newData, oldData);

            // we don't care about removed data from a prior view
            if (newData == null || newData.Length == 0) {
                return;
            }

            // If we have an empty window about to be filled for the first time, addSchedule a callback
            var removeSchedule = false;
            var addSchedule = false;
            var timestamp = agentInstanceContext.StatementContext.SchedulingService.Time;

            if (!currentBatch.IsEmpty()) {
                // check if we need to reschedule
                var callbackTime = timestamp + timePeriodProvide.DeltaAdd(timestamp, null, true, agentInstanceContext);
                if (callbackTime != callbackScheduledTime) {
                    removeSchedule = true;
                    addSchedule = true;
                }
            }
            else {
                addSchedule = true;
            }

            if (removeSchedule) {
                agentInstanceContext.AuditProvider.ScheduleRemove(
                    agentInstanceContext,
                    handle,
                    ScheduleObjectType.view,
                    factory.ViewName);
                agentInstanceContext.StatementContext.SchedulingService.Remove(handle, scheduleSlot);
            }

            if (addSchedule) {
                long timeIntervalSize = timePeriodProvide.DeltaAdd(timestamp, null, true, agentInstanceContext);
                agentInstanceContext.AuditProvider.ScheduleAdd(
                    timeIntervalSize,
                    agentInstanceContext,
                    handle,
                    ScheduleObjectType.view,
                    factory.ViewName);
                agentInstanceContext.StatementContext.SchedulingService.Add(timeIntervalSize, handle, scheduleSlot);
                callbackScheduledTime = timeIntervalSize + timestamp;
            }

            // add data points to the window
            foreach (var newEvent in newData) {
                currentBatch.Add(newEvent);
            }

            // forward insert stream to child views
            viewUpdatedCollection?.Update(newData, null);

            // update child views
            if (Child != null) {
                agentInstanceContext.InstrumentationProvider.QViewIndicate(factory, newData, null);
                Child.Update(newData, null);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Exemplo n.º 4
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, factory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(factory, newData, oldData);

            EventBean[] postOldEventsArray = null;

            // Remove old data
            if (oldData != null) {
                for (var i = 0; i < oldData.Length; i++) {
                    var oldDataItem = oldData[i];
                    object sortValues = GetTimestamp(oldDataItem);
                    var result = CollectionUtil.RemoveEventByKeyLazyListMap(sortValues, oldDataItem, sortedEvents);
                    if (result) {
                        eventCount--;
                        if (postOldEventsArray == null) {
                            postOldEventsArray = oldData;
                        }
                        else {
                            postOldEventsArray = CollectionUtil.AddArrayWithSetSemantics(postOldEventsArray, oldData);
                        }
                    }
                }
            }

            if (newData != null && newData.Length > 0) {
                // figure out the current tail time
                var runtimeTime = agentInstanceContext.StatementContext.SchedulingService.Time;
                var windowTailTime = runtimeTime -
                                     timePeriodProvide.DeltaAdd(runtimeTime, null, true, agentInstanceContext) +
                                     1;
                var oldestEvent = long.MaxValue;
                if (!sortedEvents.IsEmpty()) {
                    oldestEvent = sortedEvents.First().Key.AsInt64();
                }

                var addedOlderEvent = false;

                // add events or post events as remove stream if already older then tail time
                List<EventBean> postOldEvents = null;
                for (var i = 0; i < newData.Length; i++) {
                    // get timestamp of event
                    var newEvent = newData[i];
                    var timestamp = GetTimestamp(newEvent);

                    // if the event timestamp indicates its older then the tail of the window, release it
                    if (timestamp < windowTailTime) {
                        if (postOldEvents == null) {
                            postOldEvents = new List<EventBean>(2);
                        }

                        postOldEvents.Add(newEvent);
                    }
                    else {
                        if (timestamp < oldestEvent) {
                            addedOlderEvent = true;
                            oldestEvent = timestamp.Value;
                        }

                        // add to list
                        CollectionUtil.AddEventByKeyLazyListMapBack(timestamp, newEvent, sortedEvents);
                        eventCount++;
                    }
                }

                // If we do have data, check the callback
                if (!sortedEvents.IsEmpty()) {
                    // If we haven't scheduled a callback yet, schedule it now
                    if (!isCallbackScheduled) {
                        var callbackWait = oldestEvent - windowTailTime + 1;
                        agentInstanceContext.AuditProvider.ScheduleAdd(
                            callbackWait,
                            agentInstanceContext,
                            handle,
                            ScheduleObjectType.view,
                            factory.ViewName);
                        agentInstanceContext.StatementContext.SchedulingService.Add(callbackWait, handle, scheduleSlot);
                        isCallbackScheduled = true;
                    }
                    else {
                        // We may need to reschedule, and older event may have been added
                        if (addedOlderEvent) {
                            oldestEvent = sortedEvents.First().Key.AsInt64();
                            var callbackWait = oldestEvent - windowTailTime + 1;
                            agentInstanceContext.AuditProvider.ScheduleRemove(
                                agentInstanceContext,
                                handle,
                                ScheduleObjectType.view,
                                factory.ViewName);
                            agentInstanceContext.StatementContext.SchedulingService.Remove(handle, scheduleSlot);
                            agentInstanceContext.AuditProvider.ScheduleAdd(
                                callbackWait,
                                agentInstanceContext,
                                handle,
                                ScheduleObjectType.view,
                                factory.ViewName);
                            agentInstanceContext.StatementContext.SchedulingService.Add(
                                callbackWait,
                                handle,
                                scheduleSlot);
                            isCallbackScheduled = true;
                        }
                    }
                }

                if (postOldEvents != null) {
                    postOldEventsArray = postOldEvents.ToArray();
                }

                optionalSortedRandomAccess?.Refresh(sortedEvents, eventCount, eventCount);
            }

            // update child views
            if (Child != null) {
                agentInstanceContext.InstrumentationProvider.QViewIndicate(factory, newData, postOldEventsArray);
                Child.Update(newData, postOldEventsArray);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }
Exemplo n.º 5
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            _agentInstanceContext.AuditProvider.View(newData, oldData, _agentInstanceContext, _factory);
            _agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(_factory, newData, oldData);

            if ((newData != null) && (newData.Length > 0)) {
                // If we have an empty window about to be filled for the first time, add a callback
                bool removeSchedule = false;
                bool addSchedule = false;
                long timestamp = _agentInstanceContext.StatementContext.SchedulingService.Time;

                // if the window is already filled, then we may need to reschedule
                if (!_currentBatch.IsEmpty()) {
                    // check if we need to reschedule
                    long callbackTime =
                        timestamp + _timePeriodProvide.DeltaAdd(timestamp, null, true, _agentInstanceContext);
                    if (callbackTime != _callbackScheduledTime) {
                        removeSchedule = true;
                        addSchedule = true;
                    }
                }
                else {
                    addSchedule = true;
                }

                if (removeSchedule) {
                    _agentInstanceContext.AuditProvider.ScheduleRemove(
                        _agentInstanceContext,
                        _handle,
                        ScheduleObjectType.view,
                        _factory.ViewName);
                    _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot);
                    _callbackScheduledTime = -1;
                }

                if (addSchedule) {
                    long timeIntervalSize = _timePeriodProvide.DeltaAdd(timestamp, null, true, _agentInstanceContext);
                    _agentInstanceContext.AuditProvider.ScheduleAdd(
                        timeIntervalSize,
                        _agentInstanceContext,
                        _handle,
                        ScheduleObjectType.view,
                        _factory.ViewName);
                    _agentInstanceContext.StatementContext.SchedulingService.Add(
                        timeIntervalSize,
                        _handle,
                        _scheduleSlot);
                    _callbackScheduledTime = timeIntervalSize + timestamp;
                }

                // add data points to the window
                for (int i = 0; i < newData.Length; i++) {
                    _currentBatch.Put(newData[i], timestamp);
                    _lastEvent = newData[i];
                }
            }

            if ((oldData != null) && (oldData.Length > 0)) {
                bool removedLastEvent = false;
                foreach (EventBean anOldData in oldData) {
                    _currentBatch.Remove(anOldData);
                    if (anOldData == _lastEvent) {
                        removedLastEvent = true;
                    }
                }

                // we may need to reschedule as the newest event may have been deleted
                if (_currentBatch.Count == 0) {
                    _agentInstanceContext.AuditProvider.ScheduleRemove(
                        _agentInstanceContext,
                        _handle,
                        ScheduleObjectType.view,
                        _factory.ViewName);
                    _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot);
                    _callbackScheduledTime = -1;
                    _lastEvent = null;
                }
                else {
                    // reschedule if the last event was removed
                    if (removedLastEvent) {
                        EventBean[] events = _currentBatch.Keys.ToArray();
                        _lastEvent = events[events.Length - 1];
                        long lastTimestamp = _currentBatch.Get(_lastEvent);

                        // reschedule, newest event deleted
                        long timestamp = _agentInstanceContext.StatementContext.SchedulingService.Time;
                        long callbackTime = lastTimestamp +
                                            _timePeriodProvide.DeltaAdd(
                                                lastTimestamp,
                                                null,
                                                true,
                                                _agentInstanceContext);
                        long deltaFromNow = callbackTime - timestamp;
                        if (callbackTime != _callbackScheduledTime) {
                            _agentInstanceContext.AuditProvider.ScheduleRemove(
                                _agentInstanceContext,
                                _handle,
                                ScheduleObjectType.view,
                                _factory.ViewName);
                            _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot);
                            _agentInstanceContext.AuditProvider.ScheduleAdd(
                                deltaFromNow,
                                _agentInstanceContext,
                                _handle,
                                ScheduleObjectType.view,
                                _factory.ViewName);
                            _agentInstanceContext.StatementContext.SchedulingService.Add(
                                deltaFromNow,
                                _handle,
                                _scheduleSlot);
                            _callbackScheduledTime = callbackTime;
                        }
                    }
                }
            }

            // update child views
            var child = Child;
            if (child != null) {
                _agentInstanceContext.InstrumentationProvider.QViewIndicate(_factory, newData, oldData);
                child.Update(newData, oldData);
                _agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            _agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }