Exemplo n.º 1
0
        public void ApplyTable(
            EventBean matchingEvent,
            EventBean[] eventsPerStream,
            TableInstance stateInstance,
            OnExprViewTableChangeHandler changeHandlerAdded,
            OnExprViewTableChangeHandler changeHandlerRemoved,
            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,
                        stateInstance,
                        changeHandlerAdded,
                        changeHandlerRemoved,
                        agentInstanceContext);
                }

                instrumentationCommon.AInfraMergeWhenThenActionItem(applies);
            }

            instrumentationCommon.AInfraMergeWhenThenActions();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Pre-process the event.
 /// </summary>
 /// <param name="theEvent">to preprocess</param>
 /// <param name="runtimeFilterAndDispatchTimeContext">expression evaluation context</param>
 /// <param name="instrumentation">instrumentation</param>
 /// <returns>preprocessed event</returns>
 public EventBean Preprocess(
     EventBean theEvent,
     ExprEvaluatorContext runtimeFilterAndDispatchTimeContext,
     InstrumentationCommon instrumentation)
 {
     return GetPreprocessedEvent(theEvent, runtimeFilterAndDispatchTimeContext, instrumentation);
 }
Exemplo n.º 3
0
        protected void ApplyEnterTableKey(
            EventBean[] eventsPerStream,
            Object tableKey,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            ObjectArrayBackedEventBean bean = tableInstance.GetCreateRowIntoTable(tableKey, exprEvaluatorContext);
            currentAggregationRow = (AggregationRow) bean.Properties[0];

            InstrumentationCommon instrumentationCommon = exprEvaluatorContext.InstrumentationProvider;
            instrumentationCommon.QAggregationGroupedApplyEnterLeave(true, methodPairs.Length, accessAgents.Length, tableKey);

            for (int i = 0; i < methodPairs.Length; i++) {
                TableColumnMethodPairEval methodPair = methodPairs[i];
                instrumentationCommon.QAggNoAccessEnterLeave(true, i, null, null);
                Object columnResult = methodPair.Evaluator.Evaluate(eventsPerStream, true, exprEvaluatorContext);
                currentAggregationRow.EnterAgg(methodPair.Column, columnResult);
                instrumentationCommon.AAggNoAccessEnterLeave(true, i, null);
            }

            for (int i = 0; i < accessAgents.Length; i++) {
                instrumentationCommon.QAggAccessEnterLeave(true, i, null);
                accessAgents[i].ApplyEnter(eventsPerStream, exprEvaluatorContext, currentAggregationRow, accessColumnsZeroOffset[i]);
                instrumentationCommon.AAggAccessEnterLeave(true, i);
            }

            tableInstance.HandleRowUpdated(bean);

            instrumentationCommon.AAggregationGroupedApplyEnterLeave(true);
        }
Exemplo n.º 4
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();
        }
        public void Execute()
        {
            if (!hasNewData) {
                return;
            }

            hasNewData = false;

            EventBean[][] oldDataPerStream = new EventBean[numStreams][];
            EventBean[][] newDataPerStream = new EventBean[numStreams][];

            for (int i = 0; i < numStreams; i++) {
                oldDataPerStream[i] = GetBufferData(oldStreamBuffer.Get(i));
                newDataPerStream[i] = GetBufferData(newStreamBuffer.Get(i));
            }

            InstrumentationCommon instrumentationCommon = agentInstanceContext.InstrumentationProvider;
            if (instrumentationCommon.Activated()) {
                instrumentationCommon.QJoinDispatch(newDataPerStream, oldDataPerStream);
                joinExecutionStrategy.Join(newDataPerStream, oldDataPerStream);
                instrumentationCommon.AJoinDispatch();
                return;
            }

            joinExecutionStrategy.Join(newDataPerStream, oldDataPerStream);
        }
        private void Apply(
            EventBean theEvent,
            EventBean[] eventsPerStream,
            InternalEventRouterEntry entry,
            ExprEvaluatorContext exprEvaluatorContext,
            InstrumentationCommon instrumentation)
        {
            // evaluate
            object[] values;
            if (entry.IsSubselect) {
                StatementResourceHolder holder = entry.StatementContext.StatementCPCacheService.MakeOrGetEntryCanNull(
                    StatementCPCacheService.DEFAULT_AGENT_INSTANCE_ID, entry.StatementContext);
                using (holder.AgentInstanceContext.AgentInstanceLock.AcquireWriteLock())
                {
                    values = ObtainValues(eventsPerStream, entry, exprEvaluatorContext, instrumentation);
                }
            }
            else {
                values = ObtainValues(eventsPerStream, entry, exprEvaluatorContext, instrumentation);
            }

            // apply
            entry.Writer.Write(values, theEvent);
            
            if (entry.SpecialPropWriters.Length > 0) {
                foreach (var special in entry.SpecialPropWriters) {
                    if (special is InternalEventRouterWriterArrayElement array) {
                        var value = array.RhsExpression.Evaluate(eventsPerStream, true, exprEvaluatorContext);
                        if ((value != null) && (array.TypeWidener != null)) {
                            value = array.TypeWidener.Widen(value);
                        }
                        var arrayValue = theEvent.Get(array.PropertyName);
                        if (arrayValue is Array asArrayValue) {
                            var index = array.IndexExpression.Evaluate(eventsPerStream, true, exprEvaluatorContext).AsBoxedInt32();
                            if (index != null) {
                                int len = asArrayValue.Length;
                                if (index < len) {
                                    if (value != null || !asArrayValue.GetType().GetElementType().IsPrimitive) {
                                        asArrayValue.SetValue(value, index.Value);
                                    }
                                } else {
                                    throw new EPException("Array length " + len + " less than index " + index + " for property '" + array.PropertyName + "'");
                                }
                            }
                        }
                    } else if (special is InternalEventRouterWriterCurly) {
                        InternalEventRouterWriterCurly curly = (InternalEventRouterWriterCurly) special;
                        curly.Expression.Evaluate(eventsPerStream, true, exprEvaluatorContext);
                    } else {
                        throw new IllegalStateException("Unrecognized writer " + special);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public override bool Handle(
            EventBean theEvent,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            InstrumentationCommon instrumentationCommon = agentInstanceContext.InstrumentationProvider;
            instrumentationCommon.QSplitStream(false, theEvent, items.Length);

            int index = -1;

            for (int i = 0; i < items.Length; i++) {
                OnSplitItemEval item = items[i];
                eventsPerStream[0] = theEvent;

                // handle no contained-event evaluation
                if (item.PropertyEvaluator == null) {
                    bool pass = CheckWhereClauseCurrentEvent(i, exprEvaluatorContext);
                    if (pass) {
                        index = i;
                        break;
                    }
                }
                else {
                    // need to get contained events first
                    EventBean[] containeds =
                        items[i].PropertyEvaluator.GetProperty(eventsPerStream[0], exprEvaluatorContext);
                    if (containeds == null || containeds.Length == 0) {
                        continue;
                    }

                    foreach (EventBean contained in containeds) {
                        eventsPerStream[0] = contained;
                        bool pass = CheckWhereClauseCurrentEvent(i, exprEvaluatorContext);
                        if (pass) {
                            index = i;
                            break;
                        }
                    }

                    if (index != -1) {
                        break;
                    }
                }
            }

            if (index != -1) {
                MayRouteCurrentEvent(index, exprEvaluatorContext);
            }

            bool handled = index != -1;
            instrumentationCommon.ASplitStream(false, handled);
            return handled;
        }
Exemplo n.º 8
0
 public AgentInstanceContext(
     StatementContext statementContext,
     EPStatementAgentInstanceHandle epStatementAgentInstanceHandle,
     AgentInstanceFilterProxy agentInstanceFilterProxy,
     MappedEventBean contextProperties,
     AuditProvider auditProvider,
     InstrumentationCommon instrumentationProvider)
 {
     StatementContext = statementContext;
     FilterVersionAfterAllocation = statementContext.FilterService.FiltersVersion;
     EpStatementAgentInstanceHandle = epStatementAgentInstanceHandle;
     AgentInstanceFilterProxy = agentInstanceFilterProxy;
     _contextProperties = contextProperties;
     AuditProvider = auditProvider;
     InstrumentationProvider = instrumentationProvider;
 }
        public ICollection<EventBean> Lookup(
            EventBean theEvent,
            Cursor cursor,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            InstrumentationCommon instrumentationCommon = exprEvaluatorContext.InstrumentationProvider;
            instrumentationCommon.QIndexJoinLookup(this, eventIndex);

            ISet<EventBean> result = eventIndex.AllValues();
            if (result.IsEmpty()) {
                instrumentationCommon.AIndexJoinLookup(null, null);
                return null;
            }

            instrumentationCommon.AIndexJoinLookup(result, null);
            return result;
        }
        public ICollection<EventBean> Lookup(
            EventBean theEvent,
            Cursor cursor,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            InstrumentationCommon instrumentationCommon = exprEvaluatorContext.InstrumentationProvider;
            instrumentationCommon.QIndexJoinLookup(this, _index);

            _eventsPerStream[_factory.LookupStream] = theEvent;
            ISet<EventBean> result = InKeywordTableLookupUtil.SingleIndexLookup(
                _factory.Expressions,
                _eventsPerStream,
                exprEvaluatorContext,
                _index);

            instrumentationCommon.AIndexJoinLookup(result, null);
            return result;
        }
Exemplo n.º 11
0
        private object[] ObtainValues(
            EventBean[] eventsPerStream,
            InternalEventRouterEntry entry,
            ExprEvaluatorContext exprEvaluatorContext,
            InstrumentationCommon instrumentation)
        {
            instrumentation.QUpdateIStreamApplyAssignments(entry);
            var values = new object[entry.Assignments.Length];
            for (var i = 0; i < entry.Assignments.Length; i++) {
                instrumentation.QUpdateIStreamApplyAssignmentItem(i);
                var value = entry.Assignments[i].Evaluate(eventsPerStream, true, exprEvaluatorContext);
                if (value != null && entry.Wideners[i] != null) {
                    value = entry.Wideners[i].Widen(value);
                }

                values[i] = value;
                instrumentation.AUpdateIStreamApplyAssignmentItem(value);
            }

            instrumentation.AUpdateIStreamApplyAssignments(values);
            return values;
        }
Exemplo n.º 12
0
        private void Apply(
            EventBean theEvent,
            EventBean[] eventsPerStream,
            InternalEventRouterEntry entry,
            ExprEvaluatorContext exprEvaluatorContext,
            InstrumentationCommon instrumentation)
        {
            // evaluate
            object[] values;
            if (entry.IsSubselect) {
                using (entry.AgentInstanceLock.AcquireWriteLock())
                {
                    values = ObtainValues(eventsPerStream, entry, exprEvaluatorContext, instrumentation);
                }
            }
            else {
                values = ObtainValues(eventsPerStream, entry, exprEvaluatorContext, instrumentation);
            }

            // apply
            entry.Writer.Write(values, theEvent);
        }
Exemplo n.º 13
0
        /// <summary>
        ///     Pre-proces the event.
        /// </summary>
        /// <param name="theEvent">to pre-process</param>
        /// <param name="exprEvaluatorContext">expression evaluation context</param>
        /// <param name="instrumentation">instrumentation</param>
        /// <returns>processed event</returns>
        public EventBean Process(
            EventBean theEvent,
            ExprEvaluatorContext exprEvaluatorContext,
            InstrumentationCommon instrumentation)
        {
            if (empty) {
                return theEvent;
            }

            instrumentation.QUpdateIStream(entries);

            var oldEvent = theEvent;
            var haveCloned = false;
            var eventsPerStream = new EventBean[1];
            eventsPerStream[0] = theEvent;
            InternalEventRouterEntry lastEntry = null;

            for (var i = 0; i < entries.Length; i++) {
                var entry = entries[i];
                instrumentation.QUpdateIStreamApply(i, entry);

                var whereClause = entry.OptionalWhereClause;
                if (whereClause != null) {
                    instrumentation.QUpdateIStreamApplyWhere();
                    var result = whereClause.Evaluate(eventsPerStream, true, exprEvaluatorContext);
                    if (result == null || false.Equals(result)) {
                        instrumentation.AUpdateIStreamApplyWhere(false);
                        instrumentation.AUpdateIStreamApply(null, false);
                        continue;
                    }

                    instrumentation.AUpdateIStreamApplyWhere(true);
                }

                if (entry.IsDrop) {
                    instrumentation.AUpdateIStreamApply(null, false);
                    return null;
                }

                // before applying the changes, indicate to last-entries output view
                if (lastEntry != null) {
                    var view = lastEntry.OutputView;
                    if (view.IsIndicate) {
                        var copied = copyMethod.Copy(theEvent);
                        view.Indicate(copied, oldEvent);
                        oldEvent = copied;
                    }
                    else {
                        if (entries[i].OutputView.IsIndicate) {
                            oldEvent = copyMethod.Copy(theEvent);
                        }
                    }
                }

                // copy event for the first update that applies
                if (!haveCloned) {
                    var copiedEvent = copyMethod.Copy(theEvent);
                    if (copiedEvent == null) {
                        Log.Warn("Event of type " + theEvent.EventType.Name + " could not be copied");
                        instrumentation.AUpdateIStreamApply(null, false);
                        return null;
                    }

                    haveCloned = true;
                    eventsPerStream[0] = copiedEvent;
                    theEvent = copiedEvent;
                }

                Apply(theEvent, eventsPerStream, entry, exprEvaluatorContext, instrumentation);
                lastEntry = entry;

                instrumentation.AUpdateIStreamApply(theEvent, true);
            }

            if (lastEntry != null) {
                var view = lastEntry.OutputView;
                if (view.IsIndicate) {
                    view.Indicate(theEvent, oldEvent);
                }
            }

            instrumentation.AUpdateIStream(theEvent, haveCloned);
            return theEvent;
        }