Exemple #1
0
        public override void Update(EventBean[] newData, EventBean[] oldData)
        {
            if (_audit)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    AuditPath.AuditLog(_exprEvaluatorContext.EngineURI, _exprEvaluatorContext.StatementName, AuditEnum.STREAM, _eventType.Name + " insert {" + EventBeanUtility.Summarize(newData) + "} remove {" + EventBeanUtility.Summarize(oldData) + "}");
                }
            }

            // if we have a filter for the named window,
            if (_filterList.Length != 0)
            {
                var eventPerStream = new EventBean[1];
                newData = PassFilter(newData, true, _exprEvaluatorContext, eventPerStream);
                oldData = PassFilter(oldData, false, _exprEvaluatorContext, eventPerStream);
            }

            if (_optPropertyEvaluator != null)
            {
                newData = GetUnpacked(newData);
                oldData = GetUnpacked(oldData);
            }

            if ((newData != null) || (oldData != null))
            {
                UpdateChildren(newData, oldData);
            }
        }
        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);
        }
Exemple #3
0
        public override void Apply(
            EventBean matchingEvent,
            EventBean[] eventsPerStream,
            TableStateInstance tableStateInstance,
            TableOnMergeViewChangeHandler changeHandlerAdded,
            TableOnMergeViewChangeHandler changeHandlerRemoved,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            var theEvent = _insertHelper.Process(eventsPerStream, true, true, exprEvaluatorContext);

            if (_internalEventRouter == null)
            {
                var aggs = _tableStateRowFactory.MakeAggs(exprEvaluatorContext.AgentInstanceId, null, null, tableStateInstance.AggregationServicePassThru);
                ((object[])theEvent.Underlying)[0] = aggs;
                tableStateInstance.AddEvent(theEvent);
                if (changeHandlerAdded != null)
                {
                    changeHandlerAdded.Add(theEvent, eventsPerStream, true, exprEvaluatorContext);
                }
                return;
            }

            if (_audit)
            {
                AuditPath.AuditInsertInto(_internalEventRouteDest.EngineURI, _statementHandle.StatementName, theEvent);
            }
            _internalEventRouter.Route(theEvent, _statementHandle, _internalEventRouteDest, exprEvaluatorContext, false);
        }
        public override object Evaluate(EvaluateParams evaluateParams)
        {
            Object result = base.Evaluate(evaluateParams);

            if (AuditPath.IsInfoEnabled)
            {
                AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.PROPERTY, _propertyName + " value " + result);
            }
            return(result);
        }
Exemple #5
0
 public void HandleAudit(Object targetObject, Object[] parameters)
 {
     if (Audit)
     {
         AuditPath.AuditLog(
             EngineURI, StatementName, AuditEnum.DATAFLOW_OP,
             "dataflow " + DataFlowName + " operator " + OperatorName + "(" + OperatorNumber + ") parameters " +
             parameters.Render());
     }
 }
 private void SetState(EPDataFlowState newState)
 {
     if (_audit)
     {
         AuditPath.AuditLog(
             _engineUri, _statementName, AuditEnum.DATAFLOW_TRANSITION,
             "dataflow " + _dataFlowName + " instance " + _instanceId + " from state " + _state + " to state " +
             newState);
     }
     _state = newState;
 }
Exemple #7
0
        public void EvaluateFalse(EvalStateNode fromNode, bool restartable)
        {
            if (_evalAuditNode.FactoryNode.IsAuditPattern && AuditPath.IsInfoEnabled)
            {
                String message = ToStringEvaluateFalse(this, _evalAuditNode.FactoryNode.PatternExpr, fromNode);
                AuditPath.AuditLog(_evalAuditNode.Context.StatementContext.EngineURI, _evalAuditNode.Context.PatternContext.StatementName, AuditEnum.PATTERN, message);
            }

            _evalAuditNode.FactoryNode.DecreaseRefCount(this, _evalAuditNode.Context.PatternContext);
            ParentEvaluator.EvaluateFalse(this, restartable);
        }
Exemple #8
0
        public void Remove(ScheduleHandle handle, long scheduleSlot)
        {
            if (AuditPath.IsInfoEnabled)
            {
                StringWriter message = new StringWriter();
                message.Write("remove handle ");
                PrintHandle(message, handle);

                AuditPath.AuditLog(_engineUri, _statementName, AuditEnum.SCHEDULE, message.ToString());
            }
            _spi.Remove(handle, scheduleSlot);
        }
Exemple #9
0
        public void EvaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            if (_evalAuditNode.FactoryNode.IsAuditPattern && AuditPath.IsInfoEnabled)
            {
                String message = ToStringEvaluateTrue(this, _evalAuditNode.FactoryNode.PatternExpr, matchEvent, fromNode, isQuitted);
                AuditPath.AuditLog(_evalAuditNode.Context.StatementContext.EngineURI, _evalAuditNode.Context.PatternContext.StatementName, AuditEnum.PATTERN, message);
            }

            ParentEvaluator.EvaluateTrue(matchEvent, this, isQuitted);

            if (isQuitted)
            {
                _evalAuditNode.FactoryNode.DecreaseRefCount(this, _evalAuditNode.Context.PatternContext);
            }
        }
Exemple #10
0
        public void Add(long afterMSec, ScheduleHandle handle, long slot)
        {
            if (AuditPath.IsInfoEnabled)
            {
                StringWriter message = new StringWriter();
                message.Write("after ");
                message.Write(afterMSec);
                message.Write(" handle ");
                PrintHandle(message, handle);

                AuditPath.AuditLog(_engineUri, _statementName, AuditEnum.SCHEDULE, message.ToString());

                ModifyCreateProxy(handle);
            }
            _spi.Add(afterMSec, handle, slot);
        }
Exemple #11
0
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            invocation.ReturnValue = invocation.Method.Invoke(_view, invocation.Arguments);

            if (invocation.Method == Target)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    var newData = (EventBean[])invocation.Arguments[0];
                    var oldData = (EventBean[])invocation.Arguments[1];
                    AuditPath.AuditLog(
                        _engineURI, _statementName, AuditEnum.VIEW,
                        _viewName + " insert {" + EventBeanUtility.Summarize(newData) + "} remove {" + EventBeanUtility.Summarize(oldData) + "}");
                }
            }
        }
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            if (invocation.Method == Target)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    var message = new StringWriter();
                    message.Write("trigger handle ");
                    TypeHelper.WriteInstance(message, _scheduleHandleCallback, true);
                    AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.SCHEDULE, message.ToString());
                }
            }

            invocation.ReturnValue =
                invocation.Method.Invoke(_scheduleHandleCallback, invocation.Arguments);
        }
        public StatementAgentInstanceFactoryResult NewContext(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            if (!_audit || agentInstanceContext.AgentInstanceId == -1)
            {
                return(NewContextInternal(agentInstanceContext, isRecoveringResilient));
            }

            AuditPath.AuditContextPartition(agentInstanceContext.EngineURI, agentInstanceContext.StatementName, true, agentInstanceContext.AgentInstanceId);
            var result       = NewContextInternal(agentInstanceContext, isRecoveringResilient);
            var stopCallback = result.StopCallback;

            result.StopCallback = new ProxyStopCallback(() =>
            {
                AuditPath.AuditContextPartition(agentInstanceContext.EngineURI, agentInstanceContext.StatementName, false, agentInstanceContext.AgentInstanceId);
                stopCallback.Stop();
            });
            return(result);
        }
Exemple #14
0
        private void RunLoop()
        {
            while (true)
            {
                if (_audit)
                {
                    AuditPath.AuditLog(
                        _engineUri, _statementName, AuditEnum.DATAFLOW_SOURCE,
                        "dataflow " + _dataFlowName + " operator " + _operatorName + "(" + _operatorNumber +
                        ") invoking source.Next()");
                }
                _graphSource.Next();

                if (_shutdown)
                {
                    break;
                }
            }
        }
        private void Route(EventBean routed, int index, ExprEvaluatorContext exprEvaluatorContext)
        {
            if (Audit)
            {
                AuditPath.AuditInsertInto(AgentInstanceContext.EngineURI, AgentInstanceContext.StatementName, routed);
            }
            TableStateInstance tableStateInstance = _tableStateInstances[index];

            if (tableStateInstance != null)
            {
                tableStateInstance.AddEventUnadorned(routed);
            }
            else
            {
                bool isNamedWindowInsert = Items[index].IsNamedWindowInsert;
                InternalEventRouter.Route(
                    routed, EPStatementHandle, AgentInstanceContext.StatementContext.InternalEventEngineRouteDest,
                    exprEvaluatorContext, isNamedWindowInsert);
            }
        }
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            if (invocation.Method.Name == "Insert")
            {
                if (AuditPath.IsInfoEnabled)
                {
                    var arg    = invocation.Arguments[0];
                    var events = "(undefined)";
                    if (arg is EventBean[])
                    {
                        events = EventBeanUtility.Summarize((EventBean[])arg);
                    }
                    else if (arg is EventBean)
                    {
                        events = EventBeanUtility.Summarize((EventBean)arg);
                    }
                    AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.STREAM, _eventTypeAndFilter + " inserted " + events);
                }
            }

            invocation.ReturnValue = invocation.Method.Invoke(_eventStream, invocation.Arguments);
        }
        private static void Print(EvalAuditStateNode current, String patternExpression, String engineURI, String statementName, bool added, int?count)
        {
            if (!AuditPath.IsAuditEnabled)
            {
                return;
            }

            var writer = new StringWriter();

            EvalAuditStateNode.WritePatternExpr(current, patternExpression, writer);

            if (added)
            {
                writer.Write(" increased to " + count);
            }
            else
            {
                writer.Write(" decreased to " + count);
            }

            AuditPath.AuditLog(engineURI, statementName, AuditEnum.PATTERNINSTANCES, writer.ToString());
        }
 private void Route(EventBean[] events, ExprEvaluatorContext exprEvaluatorContext)
 {
     foreach (var routed in events)
     {
         if (routed is NaturalEventBean)
         {
             var natural = (NaturalEventBean)routed;
             if (_audit)
             {
                 AuditPath.AuditInsertInto(_agentInstanceContext.EngineURI, _agentInstanceContext.StatementName, natural.OptionalSynthetic);
             }
             if (_tableStateInstance != null)
             {
                 _tableStateInstance.AddEventUnadorned(natural.OptionalSynthetic);
             }
             else
             {
                 _parent.InternalEventRouter.Route(natural.OptionalSynthetic, _parent.EpStatementHandle, _agentInstanceContext.StatementContext.InternalEventEngineRouteDest, exprEvaluatorContext, _parent.IsAddToFront);
             }
         }
         else
         {
             if (_audit)
             {
                 AuditPath.AuditInsertInto(_agentInstanceContext.EngineURI, _agentInstanceContext.StatementName, routed);
             }
             if (_tableStateInstance != null)
             {
                 ExprTableEvalLockUtil.ObtainLockUnless(_tableStateInstance.TableLevelRWLock.WriteLock, exprEvaluatorContext);
                 _tableStateInstance.AddEventUnadorned(routed);
             }
             else
             {
                 _parent.InternalEventRouter.Route(routed, _parent.EpStatementHandle, _agentInstanceContext.StatementContext.InternalEventEngineRouteDest, exprEvaluatorContext, _parent.IsAddToFront);
             }
         }
     }
 }
        public bool Handle(EventBean theEvent, ExprEvaluatorContext exprEvaluatorContext)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QSplitStream(false, theEvent, _whereClauses);
            }

            int index = -1;

            _eventsPerStream[0] = theEvent;

            for (int i = 0; i < _whereClauses.Length; i++)
            {
                if (_whereClauses[i] == null)
                {
                    index = i;
                    break;
                }

                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QSplitStreamWhere(i);
                }
                var pass = (bool?)_whereClauses[i].Evaluate(new EvaluateParams(_eventsPerStream, true, exprEvaluatorContext));
                if ((pass != null) && (pass.Value))
                {
                    index = i;
                    if (InstrumentationHelper.ENABLED)
                    {
                        InstrumentationHelper.Get().ASplitStreamWhere(pass.Value);
                    }
                    break;
                }
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().ASplitStreamWhere(pass.Value);
                }
            }

            if (index != -1)
            {
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().QSplitStreamRoute(index);
                }
                UniformPair <EventBean[]> result = _processors[index].ProcessViewResult(_eventsPerStream, null, false);
                if ((result != null) && (result.First != null) && (result.First.Length > 0))
                {
                    if (_audit)
                    {
                        AuditPath.AuditInsertInto(_agentInstanceContext.EngineURI, _agentInstanceContext.StatementName, result.First[0]);
                    }
                    if (_tableStateInstances[index] != null)
                    {
                        _tableStateInstances[index].AddEventUnadorned(result.First[0]);
                    }
                    else
                    {
                        _internalEventRouter.Route(result.First[0], _epStatementHandle, _agentInstanceContext.StatementContext.InternalEventEngineRouteDest, _agentInstanceContext, _isNamedWindowInsert[index]);
                    }
                }
                if (InstrumentationHelper.ENABLED)
                {
                    InstrumentationHelper.Get().ASplitStreamRoute();
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().ASplitStream(false, index != -1);
            }
            return(index != -1);
        }
Exemple #20
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_SELECT, triggerEvents, matchingEvents);
            }

            EventBean[] newData;

            // clear state from prior results
            _resultSetProcessor.Clear();

            // build join result
            // use linked hash set to retain order of join results for last/first/window to work most intuitively
            var newEvents = BuildJoinResult(triggerEvents, matchingEvents);

            // process matches
            var pair = _resultSetProcessor.ProcessJoinResult(newEvents, _oldEvents, false);

            newData = (pair != null ? pair.First : null);

            if (_parent.IsDistinct)
            {
                newData = EventBeanUtility.GetDistinctByProp(newData, _parent.EventBeanReader);
            }

            if (_tableStateInstanceInsertInto != null)
            {
                if (newData != null)
                {
                    foreach (var aNewData in newData)
                    {
                        if (_audit)
                        {
                            AuditPath.AuditInsertInto(ExprEvaluatorContext.EngineURI, ExprEvaluatorContext.StatementName, aNewData);
                        }
                        _tableStateInstanceInsertInto.AddEventUnadorned(aNewData);
                    }
                }
            }
            else if (_parent.InternalEventRouter != null)
            {
                if (newData != null)
                {
                    foreach (var aNewData in newData)
                    {
                        if (_audit)
                        {
                            AuditPath.AuditInsertInto(ExprEvaluatorContext.EngineURI, ExprEvaluatorContext.StatementName, aNewData);
                        }
                        _parent.InternalEventRouter.Route(aNewData, _parent.StatementHandle, _parent.InternalEventRouteDest, ExprEvaluatorContext, _parent.IsAddToFront);
                    }
                }
            }

            // The on-select listeners receive the events selected
            if ((newData != null) && (newData.Length > 0))
            {
                // And post only if we have listeners/subscribers that need the data
                if (_parent.StatementResultService.IsMakeNatural || _parent.StatementResultService.IsMakeSynthetic)
                {
                    UpdateChildren(newData, null);
                }
            }
            _lastResult = newData;

            // clear state from prior results
            _resultSetProcessor.Clear();

            // Events to delete are indicated via old data
            if (_isDelete)
            {
                RootView.Update(null, matchingEvents);
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
Exemple #21
0
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            var result = invocation.Method.Invoke(_evaluator, invocation.Arguments);

            invocation.ReturnValue = result;

            if (invocation.Method == TargetEvaluate)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.EXPRESSION,
                                       "expression " + _expressionToString + " result " + result);
                }
            }
            else if (invocation.Method == TargetEvaluateCollEvents)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    var resultBeans = (ICollection <EventBean>)result;
                    var @out        = "null";
                    if (resultBeans != null)
                    {
                        if (resultBeans.IsEmpty())
                        {
                            @out = "{}";
                        }
                        else
                        {
                            var buf   = new StringWriter();
                            var count = 0;
                            foreach (EventBean theEvent in resultBeans)
                            {
                                buf.Write(" Event ");
                                buf.Write(Convert.ToString(count++));
                                buf.Write(":");
                                EventBeanUtility.AppendEvent(buf, theEvent);
                            }
                            @out = buf.ToString();
                        }
                    }

                    AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.EXPRESSION, "expression " + _expressionToString + " result " + @out);
                }
            }
            else if (invocation.Method == TargetEvaluateCollScalar)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.EXPRESSION, "expression " + _expressionToString + " result " + result);
                }
            }
            else if (invocation.Method == TargetEvaluateBean)
            {
                if (AuditPath.IsAuditEnabled)
                {
                    var @out = "null";
                    if (result != null)
                    {
                        var buf = new StringWriter();
                        EventBeanUtility.AppendEvent(buf, (EventBean)result);
                        @out = buf.ToString();
                    }
                    AuditPath.AuditLog(_engineURI, _statementName, AuditEnum.EXPRESSION, "expression " + _expressionToString + " result " + @out);
                }
            }
        }
Exemple #22
0
        public override void HandleMatching(EventBean[] triggerEvents, EventBean[] matchingEvents)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QInfraOnAction(OnTriggerType.ON_SELECT, triggerEvents, matchingEvents);
            }

            EventBean[] newData;

            // clear state from prior results
            _resultSetProcessor.Clear();

            // build join result
            // use linked hash set to retain order of join results for last/first/window to work most intuitively
            ISet <MultiKey <EventBean> > newEvents = NamedWindowOnSelectView.BuildJoinResult(triggerEvents, matchingEvents);

            // process matches
            UniformPair <EventBean[]> pair = _resultSetProcessor.ProcessJoinResult(newEvents, Collections.GetEmptySet <MultiKey <EventBean> >(), false);

            newData = (pair != null ? pair.First : null);

            if (_parent.IsDistinct)
            {
                newData = EventBeanUtility.GetDistinctByProp(newData, _parent.EventBeanReader);
            }

            if (_parent.InternalEventRouter != null)
            {
                if (newData != null)
                {
                    for (int i = 0; i < newData.Length; i++)
                    {
                        if (_audit)
                        {
                            AuditPath.AuditInsertInto(ExprEvaluatorContext.EngineURI, ExprEvaluatorContext.StatementName, newData[i]);
                        }
                        _parent.InternalEventRouter.Route(newData[i], _parent.StatementHandle, _parent.InternalEventRouteDest, ExprEvaluatorContext, false);
                    }
                }
            }

            // The on-select listeners receive the events selected
            if ((newData != null) && (newData.Length > 0))
            {
                // And post only if we have listeners/subscribers that need the data
                if (_parent.StatementResultService.IsMakeNatural || _parent.StatementResultService.IsMakeSynthetic)
                {
                    UpdateChildren(newData, null);
                }
            }

            // clear state from prior results
            _resultSetProcessor.Clear();

            // Events to delete are indicated via old data
            if (_deleteAndSelect)
            {
                foreach (EventBean @event in matchingEvents)
                {
                    TableStateInstance.DeleteEvent(@event);
                }
            }

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().AInfraOnAction();
            }
        }
        public bool Handle(EventBean theEvent, ExprEvaluatorContext exprEvaluatorContext)
        {
            var isHandled = new Mutable <bool>(false);

            using (Instrument.With(
                       i => i.QSplitStream(true, theEvent, _whereClauses),
                       i => i.ASplitStream(true, isHandled.Value)))
            {
                _eventsPerStream[0] = theEvent;

                for (int ii = 0; ii < _whereClauses.Length; ii++)
                {
                    var pass = new Mutable <bool>(true);
                    if (_whereClauses[ii] != null)
                    {
                        Instrument.With(
                            i => i.QSplitStreamWhere(ii),
                            i => i.ASplitStreamWhere(pass.Value),
                            () =>
                        {
                            var passEvent = (bool?)_whereClauses[ii].Evaluate(new EvaluateParams(_eventsPerStream, true, exprEvaluatorContext));
                            if ((passEvent == null) || (!passEvent.Value))
                            {
                                pass.Value = false;
                            }
                        });
                    }

                    if (pass.Value)
                    {
                        Instrument.With(
                            i => i.QSplitStreamRoute(ii),
                            i => i.ASplitStreamRoute(),
                            () =>
                        {
                            UniformPair <EventBean[]> result = _processors[ii].ProcessViewResult(
                                _eventsPerStream, null, false);
                            if ((result != null) && (result.First != null) && (result.First.Length > 0))
                            {
                                isHandled.Value       = true;
                                EventBean eventRouted = result.First[0];
                                if (_audit)
                                {
                                    AuditPath.AuditInsertInto(
                                        _agentInstanceContext.EngineURI, _agentInstanceContext.StatementName,
                                        eventRouted);
                                }
                                if (_tableStateInstances[ii] != null)
                                {
                                    _tableStateInstances[ii].AddEventUnadorned(eventRouted);
                                }
                                else
                                {
                                    _internalEventRouter.Route(
                                        eventRouted, _epStatementHandle,
                                        _agentInstanceContext.StatementContext.InternalEventEngineRouteDest,
                                        exprEvaluatorContext, _isNamedWindowInsert[ii]);
                                }
                            }
                        });
                    }
                }

                return(isHandled.Value);
            }
        }