Ejemplo n.º 1
0
        /// <summary>
        ///     Add a filter callback according to the filter specification to the top node returning
        ///     information to be used to remove the filter callback.
        /// </summary>
        /// <param name="valueSet">is the filter definition</param>
        /// <param name="filterCallback">is the callback to be added</param>
        /// <param name="topNode">node to be added to any subnode beneath it</param>
        /// <param name="lockFactory">lock factory</param>
        public static void Add(
            FilterValueSetParam[][] valueSet,
            FilterHandle filterCallback,
            FilterHandleSetNode topNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            if (ExecutionPathDebugLog.IsDebugEnabled && log.IsDebugEnabled) {
                log.Debug(
                    ".add (" + Thread.CurrentThread.ManagedThreadId + ") Adding filter callback, " +
                    "  topNode=" + topNode +
                    "  filterCallback=" + filterCallback);
            }

            if (valueSet.Length == 0) {
                AddToNode(new ArrayDeque<FilterValueSetParam>(1), filterCallback, topNode, lockFactory);
            }
            else {
                var remainingParameters = new ArrayDeque<FilterValueSetParam>();
                for (var i = 0; i < valueSet.Length; i++) {
                    remainingParameters.Clear();
                    remainingParameters.AddAll(valueSet[i]);
                    AddToNode(remainingParameters, filterCallback, topNode, lockFactory);
                }
            }
        }
        private static void ProcessMatches(
            EvalFilterConsumptionHandler handler,
            EventBean theEvent,
            ICollection<FilterHandleCallback> allStmtMatches)
        {
            // ignore all other callbacks for the same event
            if (handler.LastEvent == theEvent) {
                return;
            }

            handler.LastEvent = theEvent;

            // evaluate consumption for all same-pattern filters
            ArrayDeque<FilterHandleCallback> matches = new ArrayDeque<FilterHandleCallback>();

            int currentConsumption = int.MinValue;
            foreach (FilterHandleCallback callback in allStmtMatches) {
                if (!(callback is EvalFilterStateNodeConsume)) {
                    continue;
                }

                EvalFilterStateNodeConsume node = (EvalFilterStateNodeConsume) callback;
                int? consumption = node.EvalFilterNode.FactoryNode.ConsumptionLevel;
                if (consumption == null) {
                    consumption = 0;
                }

                if (consumption > currentConsumption) {
                    matches.Clear();
                    currentConsumption = consumption.Value;
                }

                if (consumption == currentConsumption) {
                    matches.Add(callback);
                }
            }

            // execute matches
            foreach (FilterHandleCallback match in matches) {
                match.MatchFound(theEvent, null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a filter callback according to the filter specification to the top node returning information to be used to remove the filter callback.
        /// </summary>
        /// <param name="filterValueSet">is the filter definition</param>
        /// <param name="filterCallback">is the callback to be added</param>
        /// <param name="topNode">node to be added to any subnode beneath it</param>
        /// <param name="lockFactory">The lock factory.</param>
        /// <returns>
        /// an encapsulation of information need to allow for safe removal of the filter tree.
        /// </returns>
        public static ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>[] Add(
            FilterValueSet filterValueSet,
            FilterHandle filterCallback,
            FilterHandleSetNode topNode,
            FilterServiceGranularLockFactory lockFactory)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".add (" + Thread.CurrentThread.ManagedThreadId + ") Adding filter callback, " +
                          "  topNode=" + topNode +
                          "  filterCallback=" + filterCallback);
            }

            ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>[] treePathInfo;
            if (filterValueSet.Parameters.Length == 0)
            {
                treePathInfo    = AllocateTreePath(1);
                treePathInfo[0] = new ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>(1);
#if DEBUG && DIAGNOSTICS
                System.Diagnostics.Debug.WriteLine("{0}: Add -> AddToNode[1]: {0}", Thread.CurrentThread.ManagedThreadId, topNode);
#endif
                AddToNode(new ArrayDeque <FilterValueSetParam>(1), filterCallback, topNode, treePathInfo[0], lockFactory);
            }
            else
            {
                treePathInfo = AllocateTreePath(filterValueSet.Parameters.Length);
                var remainingParameters = new ArrayDeque <FilterValueSetParam>(4);
                for (int i = 0; i < filterValueSet.Parameters.Length; i++)
                {
                    treePathInfo[i] = new ArrayDeque <EventTypeIndexBuilderIndexLookupablePair>(filterValueSet.Parameters[i].Length);
                    remainingParameters.Clear();
                    remainingParameters.AddAll(filterValueSet.Parameters[i]);
#if DEBUG && DIAGNOSTICS
                    System.Diagnostics.Debug.WriteLine("{0}: Add -> AddToNode[0]: {1}", Thread.CurrentThread.ManagedThreadId, topNode);
#endif
                    AddToNode(remainingParameters, filterCallback, topNode, treePathInfo[i], lockFactory);
                }
            }

            return(treePathInfo);
        }
Ejemplo n.º 4
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            _oldEvents.Clear();
            EventBean[] newDataPosted = null;

            // handle remove stream
            if (oldData != null)
            {
                _isDiscardObserverEvents = true; // disable reaction logic in observer
                try
                {
                    foreach (View view in _views)
                    {
                        view.Update(null, oldData);
                    }
                }
                finally
                {
                    _isDiscardObserverEvents = false;
                }

                for (int i = 0; i < oldData.Length; i++)
                {
                    _oldEvents.Add(oldData[i]);
                }
            }

            if (newData != null)
            {
                _removalEvents.Clear();

                // 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)
                    {
                        _newDataChildView = null;
                        view.Update(newData, oldData);

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

                if (_removalEvents.IsNotEmpty())
                {
                    _isDiscardObserverEvents = true;
                    EventBean[] viewOldData = _removalEvents.ToArray();
                    try
                    {
                        for (int 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)
                {
                    // 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

                        // add each event to the set of events removed
                        foreach (EventBean oldEvent in viewOldData)
                        {
                            _removalEvents.Add(oldEvent);
                        }

                        _isDiscardObserverEvents = true;
                        try
                        {
                            for (int j = 0; j < _views.Length; j++)
                            {
                                if (i != j)
                                {
                                    _views[j].Update(null, viewOldData);
                                }
                            }
                        }
                        finally
                        {
                            _isDiscardObserverEvents = false;
                        }
                    }

                    _oldEvents.AddAll(_removalEvents);
                }

                _newEvents.Clear();
                for (int 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
            EventBean[] oldDataPosted = null;
            if (_oldEvents.IsNotEmpty())
            {
                oldDataPosted = _oldEvents.ToArray();
            }
            if ((newDataPosted != null) || (oldDataPosted != null))
            {
                UpdateChildren(newDataPosted, oldDataPosted);
            }
            _oldEvents.Clear();
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        private void ProcessDispatches(
            ArrayDeque<NamedWindowConsumerLatch> dispatches,
            IDictionary<EPStatementAgentInstanceHandle, object> dispatchesPerStmt)
        {
            try {
                foreach (var latch in dispatches) {
                    foreach (var entry in latch.DispatchTo) {
                        var handle = entry.Key;
                        var perStmtObj = dispatchesPerStmt.Get(handle);
                        if (perStmtObj == null) {
                            dispatchesPerStmt.Put(handle, latch);
                        }
                        else if (perStmtObj is IList<NamedWindowConsumerLatch> windowConsumerLatches) {
                            windowConsumerLatches.Add(latch);
                        }
                        else {
                            // convert from object to list
                            var unitObj = (NamedWindowConsumerLatch) perStmtObj;
                            IList<NamedWindowConsumerLatch> list = new List<NamedWindowConsumerLatch>();
                            list.Add(unitObj);
                            list.Add(latch);
                            dispatchesPerStmt.Put(handle, list);
                        }
                    }
                }

                // Dispatch - with or without metrics reporting
                if (metricReportingService.IsMetricsReportingEnabled) {
                    foreach (var entry in dispatchesPerStmt) {
                        var handle = entry.Key;
                        var perStmtObj = entry.Value;

                        // dispatch of a single result to the statement
                        if (perStmtObj is NamedWindowConsumerLatch) {
                            var unit = (NamedWindowConsumerLatch) perStmtObj;
                            var newData = unit.DeltaData.NewData;
                            var oldData = unit.DeltaData.OldData;

                            if (handle.StatementHandle.MetricsHandle.IsEnabled) {
                                var performanceMetric = PerformanceMetricsHelper.Call(
                                    () => ProcessHandle(handle, unit.DispatchTo.Get(handle), newData, oldData));

                                metricReportingService.AccountTime(
                                    handle.StatementHandle.MetricsHandle, 
                                    performanceMetric, performanceMetric.NumInput);
                            }
                            else {
                                var entries = unit.DispatchTo;
                                var items = entries.Get(handle);
                                if (items != null) {
                                    ProcessHandle(handle, items, newData, oldData);
                                }
                            }

                            if (isPrioritized && handle.IsPreemptive) {
                                break;
                            }

                            continue;
                        }

                        // dispatch of multiple results to a the same statement, need to aggregate per consumer view
                        var deltaPerConsumer = GetDeltaPerConsumer(perStmtObj, handle);
                        if (handle.StatementHandle.MetricsHandle.IsEnabled) {
                            var performanceMetric = PerformanceMetricsHelper.Call(
                                () => ProcessHandleMultiple(handle, deltaPerConsumer));
                            metricReportingService.AccountTime(
                                handle.StatementHandle.MetricsHandle, 
                                performanceMetric, performanceMetric.NumInput);
                        }
                        else {
                            ProcessHandleMultiple(handle, deltaPerConsumer);
                        }

                        if (isPrioritized && handle.IsPreemptive) {
                            break;
                        }
                    }
                }
                else {
                    foreach (var entry in dispatchesPerStmt) {
                        var handle = entry.Key;
                        var perStmtObj = entry.Value;

                        // dispatch of a single result to the statement
                        if (perStmtObj is NamedWindowConsumerLatch) {
                            var unit = (NamedWindowConsumerLatch) perStmtObj;
                            var newData = unit.DeltaData.NewData;
                            var oldData = unit.DeltaData.OldData;

                            ProcessHandle(handle, unit.DispatchTo.Get(handle), newData, oldData);

                            if (isPrioritized && handle.IsPreemptive) {
                                break;
                            }

                            continue;
                        }

                        // dispatch of multiple results to a the same statement, need to aggregate per consumer view
                        var deltaPerConsumer = GetDeltaPerConsumer(perStmtObj, handle);
                        ProcessHandleMultiple(handle, deltaPerConsumer);

                        if (isPrioritized && handle.IsPreemptive) {
                            break;
                        }
                    }
                }
            }
            finally {
                foreach (var latch in dispatches) {
                    latch.Done();
                }

                dispatchesPerStmt.Clear();
                dispatches.Clear();
            }
        }
Ejemplo n.º 7
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            agentInstanceContext.AuditProvider.View(newData, oldData, agentInstanceContext, ViewFactory);
            agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(ViewFactory, newData, 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) {
                        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) {
                var removedByView = new bool[newData.Length][]
                    .Fill(() => new bool[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];
                        agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newData, null);
                        view.Update(newData, null);
                        agentInstanceContext.InstrumentationProvider.AViewIndicate();

                        // 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.IsEmpty()) {
                    isDiscardObserverEvents = true;
                    var viewOldData = removalEvents.ToArray();
                    try {
                        for (var j = 0; j < views.Length; j++) {
                            agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, null, viewOldData);
                            views[j].Update(null, viewOldData);
                            agentInstanceContext.InstrumentationProvider.AViewIndicate();
                        }
                    }
                    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.IsEmpty()) {
                    newDataPosted = newEvents.ToArray();
                }
            }

            // indicate new and, possibly, old data
            if (Child != null && (newDataPosted != null || oldDataColl != null)) {
                var oldDataToPost = oldDataColl != null ? oldDataColl.ToArray() : null;
                agentInstanceContext.InstrumentationProvider.QViewIndicate(ViewFactory, newDataPosted, oldDataToPost);
                Child.Update(newDataPosted, oldDataToPost);
                agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }