public override void Start(MatchedEventMap beginState)
        {
            EvalNode      child      = EvalFollowedByNode.ChildNodes[0];
            EvalStateNode childState = child.NewState(this, null, 0L);

            Nodes.Put(childState, 0);
            childState.Start(beginState);
        }
Example #2
0
 public override void Start(MatchedEventMap beginState)
 {
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.Get().QPatternRootStart(beginState);
     }
     _topStateNode = RootSingleChildNode.NewState(this, null, 0L);
     _topStateNode.Start(beginState);
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.Get().APatternRootStart();
     }
 }
Example #3
0
 public override void Start(MatchedEventMap beginState)
 {
     Instrument.With(
         i => i.QPatternFollowedByStart(EvalFollowedByNode, beginState),
         i => i.APatternFollowedByStart(),
         () =>
     {
         EvalNode child           = EvalFollowedByNode.ChildNodes[0];
         EvalStateNode childState = child.NewState(this, null, 0L);
         Nodes.Put(childState, 0);
         childState.Start(beginState);
     });
 }
Example #4
0
        public void EvaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            int index;
            var hasIndex = Nodes.TryGetValue(fromNode, out index);

            bool[] isFollowedByQuitted = { false };

            using (Instrument.With(
                       i => i.QPatternFollowedByEvaluateTrue(EvalFollowedByNode, matchEvent, index),
                       i => i.APatternFollowedByEvaluateTrue(isFollowedByQuitted[0])))
            {
                if (isQuitted)
                {
                    Nodes.Remove(fromNode);
                }

                // the node may already have quit as a result of an outer state quitting this state,
                // however the callback may still be received; It is fine to ignore this callback.
                if (!hasIndex)
                {
                    return;
                }

                // If the match came from the very last filter, need to escalate
                int numChildNodes = EvalFollowedByNode.ChildNodes.Length;
                if (index == (numChildNodes - 1))
                {
                    if (Nodes.IsEmpty())
                    {
                        isFollowedByQuitted[0] = true;
                    }

                    ParentEvaluator.EvaluateTrue(matchEvent, this, isFollowedByQuitted[0]);
                }
                // Else start a new sub-expression for the next-in-line filter
                else
                {
                    EvalNode      child      = EvalFollowedByNode.ChildNodes[index + 1];
                    EvalStateNode childState = child.NewState(this, null, 0L);
                    Nodes.Put(childState, index + 1);
                    childState.Start(matchEvent);
                }
            }
        }
Example #5
0
        public override void Start(MatchedEventMap beginState)
        {
            Instrument.With(
                i => i.QPatternMatchUntilStart(_evalMatchUntilNode, beginState),
                i => i.APatternMatchUntilStart(),
                () =>
            {
                _beginState = beginState;

                EvalNode childMatcher = _evalMatchUntilNode.ChildNodeSub;
                _stateMatcher         = childMatcher.NewState(this, null, 0L);

                if (_evalMatchUntilNode.ChildNodeUntil != null)
                {
                    EvalNode childUntil = _evalMatchUntilNode.ChildNodeUntil;
                    _stateUntil         = childUntil.NewState(this, null, 0L);
                }

                // start until first, it controls the expression
                // if the same event fires both match and until, the match should not count
                if (_stateUntil != null)
                {
                    _stateUntil.Start(beginState);
                }

                EvalMatchUntilStateBounds bounds =
                    EvalMatchUntilStateBounds.InitBounds(
                        _evalMatchUntilNode.FactoryNode, beginState, _evalMatchUntilNode.Context);
                _lowerbounds = bounds.Lowerbounds;
                _upperbounds = bounds.Upperbounds;

                if (_stateMatcher != null)
                {
                    _stateMatcher.Start(beginState);
                }
            });
        }
Example #6
0
        public void EvaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            Instrument.With(
                i => i.QPatternMatchUntilEvaluateTrue(_evalMatchUntilNode, matchEvent, fromNode == _stateUntil),
                i => i.APatternMatchUntilEvaluateTrue(_stateMatcher == null && _stateUntil == null),
                () =>
            {
                bool isMatcher = false;
                if (fromNode == _stateMatcher)
                {
                    // Add the additional tagged events to the list for later posting
                    isMatcher = true;
                    _numMatches++;
                    int[] tags = _evalMatchUntilNode.FactoryNode.TagsArrayed;
                    for (int i = 0; i < tags.Length; i++)
                    {
                        var theEvent = matchEvent.GetMatchingEventAsObject(tags[i]);
                        if (theEvent != null)
                        {
                            if (_matchedEventArrays[i] == null)
                            {
                                _matchedEventArrays[i] = new List <EventBean>();
                            }
                            if (theEvent is EventBean)
                            {
                                _matchedEventArrays[i].Add((EventBean)theEvent);
                            }
                            else
                            {
                                EventBean[] arrayEvents = (EventBean[])theEvent;
                                _matchedEventArrays[i].AddAll(arrayEvents);
                            }
                        }
                    }
                }

                if (isQuitted)
                {
                    if (isMatcher)
                    {
                        _stateMatcher = null;
                    }
                    else
                    {
                        _stateUntil = null;
                    }
                }

                // handle matcher evaluating true
                if (isMatcher)
                {
                    if ((IsTightlyBound) && (_numMatches == _lowerbounds))
                    {
                        QuitInternal();
                        MatchedEventMap consolidated = Consolidate(
                            matchEvent, _matchedEventArrays, _evalMatchUntilNode.FactoryNode.TagsArrayed);
                        ParentEvaluator.EvaluateTrue(consolidated, this, true);
                    }
                    else
                    {
                        // restart or keep started if not bounded, or not upper bounds, or upper bounds not reached
                        bool restart = (!IsBounded) ||
                                       (_upperbounds == null) ||
                                       (_upperbounds > _numMatches);
                        if (_stateMatcher == null)
                        {
                            if (restart)
                            {
                                EvalNode childMatcher = _evalMatchUntilNode.ChildNodeSub;
                                _stateMatcher         = childMatcher.NewState(this, null, 0L);
                                _stateMatcher.Start(_beginState);
                            }
                        }
                        else
                        {
                            if (!restart)
                            {
                                _stateMatcher.Quit();
                                _stateMatcher = null;
                            }
                        }
                    }
                }
                else
                // handle until-node
                {
                    QuitInternal();

                    // consolidate multiple matched events into a single event
                    MatchedEventMap consolidated = Consolidate(
                        matchEvent, _matchedEventArrays, _evalMatchUntilNode.FactoryNode.TagsArrayed);

                    if ((_lowerbounds != null) && (_numMatches < _lowerbounds))
                    {
                        ParentEvaluator.EvaluateFalse(this, true);
                    }
                    else
                    {
                        ParentEvaluator.EvaluateTrue(consolidated, this, true);
                    }
                }
            });
        }
        public void EvaluateTrue(MatchedEventMap matchEvent, EvalStateNode fromNode, bool isQuitted)
        {
            int index;
            var hasIndex = Nodes.TryGetValue(fromNode, out index);

            if (isQuitted)
            {
                Nodes.Remove(fromNode);
                if (hasIndex && index > 0)
                {
                    if (EvalFollowedByNode.IsTrackWithMax)
                    {
                        CountActivePerChild[index - 1]--;
                    }
                    if (EvalFollowedByNode.IsTrackWithPool)
                    {
                        PatternSubexpressionPoolStmtSvc poolSvc = EvalFollowedByNode.Context.StatementContext.PatternSubexpressionPoolSvc;
                        poolSvc.EngineSvc.DecreaseCount(EvalFollowedByNode, EvalFollowedByNode.Context.AgentInstanceContext);
                        poolSvc.StmtHandler.DecreaseCount();
                    }
                }
            }

            // the node may already have quit as a result of an outer state quitting this state,
            // however the callback may still be received; It is fine to ignore this callback.
            if (!hasIndex)
            {
                return;
            }

            // If the match came from the very last filter, need to escalate
            int numChildNodes = EvalFollowedByNode.ChildNodes.Length;

            if (index == (numChildNodes - 1))
            {
                bool isFollowedByQuitted = Nodes.IsEmpty();
                ParentEvaluator.EvaluateTrue(matchEvent, this, isFollowedByQuitted);
            }
            // Else start a new sub-expression for the next-in-line filter
            else
            {
                if (EvalFollowedByNode.IsTrackWithMax)
                {
                    int max = EvalFollowedByNode.FactoryNode.GetMax(index);
                    if ((max != -1) && (max >= 0))
                    {
                        if (CountActivePerChild[index] >= max)
                        {
                            EvalFollowedByNode.Context.AgentInstanceContext.StatementContext.ExceptionHandlingService.HandleCondition(new ConditionPatternSubexpressionMax(max), EvalFollowedByNode.Context.AgentInstanceContext.StatementContext.EpStatementHandle);
                            return;
                        }
                    }
                }

                if (EvalFollowedByNode.IsTrackWithPool)
                {
                    PatternSubexpressionPoolStmtSvc poolSvc = EvalFollowedByNode.Context.StatementContext.PatternSubexpressionPoolSvc;
                    bool allow = poolSvc.EngineSvc.TryIncreaseCount(EvalFollowedByNode, EvalFollowedByNode.Context.AgentInstanceContext);
                    if (!allow)
                    {
                        return;
                    }
                    poolSvc.StmtHandler.IncreaseCount();
                }

                if (EvalFollowedByNode.IsTrackWithMax)
                {
                    CountActivePerChild[index]++;
                }

                EvalNode      child      = EvalFollowedByNode.ChildNodes[index + 1];
                EvalStateNode childState = child.NewState(this, null, 0L);
                Nodes.Put(childState, index + 1);
                childState.Start(matchEvent);
            }
        }