コード例 #1
0
        public override void Start(MatchedEventMap beginState)
        {
            var agentInstanceContext = evalOrNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternOrStart(evalOrNode.factoryNode, beginState);
            agentInstanceContext.AuditProvider.PatternInstance(true, evalOrNode.factoryNode, agentInstanceContext);

            // In an "or" expression we need to create states for all child expressions/listeners,
            // since all are going to be started
            var count = 0;
            foreach (var node in evalOrNode.ChildNodes) {
                var childState = node.NewState(this);
                childNodes[count++] = childState;
            }

            // In an "or" expression we start all child listeners
            var childNodeCopy = new EvalStateNode[childNodes.Length];
            Array.Copy(childNodes, 0, childNodeCopy, 0, childNodes.Length);
            foreach (var child in childNodeCopy) {
                child.Start(beginState);
                if (quitted) {
                    break;
                }
            }

            agentInstanceContext.InstrumentationProvider.APatternOrStart();
        }
コード例 #2
0
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            var agentInstanceContext = evalOrNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternOrEvaluateTrue(evalOrNode.factoryNode, matchEvent);

            // If one of the children quits, the whole or expression turns true and all subexpressions must quit
            if (isQuitted) {
                for (var i = 0; i < childNodes.Length; i++) {
                    if (childNodes[i] == fromNode) {
                        childNodes[i] = null;
                    }
                }

                agentInstanceContext.AuditProvider.PatternInstance(false, evalOrNode.factoryNode, agentInstanceContext);
                QuitInternal(); // Quit the remaining listeners
            }

            agentInstanceContext.AuditProvider.PatternTrue(
                evalOrNode.FactoryNode,
                this,
                matchEvent,
                isQuitted,
                agentInstanceContext);
            ParentEvaluator.EvaluateTrue(matchEvent, this, isQuitted, optionalTriggeringEvent);

            agentInstanceContext.InstrumentationProvider.APatternOrEvaluateTrue(isQuitted);
        }
コード例 #3
0
        public void EvaluateFalse(
            EvalStateNode fromNode,
            bool restartable)
        {
            var agentInstanceContext = everyNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryDistinctEvalFalse(everyNode.factoryNode);

            fromNode.Quit();
            spawnedNodes.Remove(fromNode);

            // Spawn all nodes below this EVERY node
            // During the start of a child we need to use the temporary evaluator to catch any event created during a start
            // Such events can be raised when the "not" operator is used.
            var spawnEvaluator = new EvalEveryStateSpawnEvaluator(everyNode.Context.StatementName);
            var spawned = everyNode.ChildNode.NewState(spawnEvaluator);
            spawned.Start(beginState);

            // If the whole spawned expression already turned true, quit it again
            if (spawnEvaluator.IsEvaluatedTrue) {
                spawned.Quit();
            }
            else {
                spawnedNodes.Put(spawned, new LinkedHashMap<object, long>());
                spawned.ParentEvaluator = this;
            }

            agentInstanceContext.InstrumentationProvider.APatternEveryDistinctEvalFalse();
        }
コード例 #4
0
        public void EvaluateFalse(
            EvalStateNode fromNode,
            bool restartable)
        {
            var agentInstanceContext = evalOrNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternOrEvalFalse(evalOrNode.factoryNode);

            for (var i = 0; i < childNodes.Length; i++) {
                if (childNodes[i] == fromNode) {
                    childNodes[i] = null;
                }
            }

            var allEmpty = true;
            for (var i = 0; i < childNodes.Length; i++) {
                if (childNodes[i] != null) {
                    allEmpty = false;
                    break;
                }
            }

            if (allEmpty) {
                agentInstanceContext.AuditProvider.PatternFalse(evalOrNode.FactoryNode, this, agentInstanceContext);
                agentInstanceContext.AuditProvider.PatternInstance(false, evalOrNode.factoryNode, agentInstanceContext);
                ParentEvaluator.EvaluateFalse(this, true);
            }

            agentInstanceContext.InstrumentationProvider.APatternOrEvalFalse();
        }
コード例 #5
0
ファイル: EvalEveryStateNode.cs プロジェクト: lanicon/nesper
        public override void Start(MatchedEventMap beginState)
        {
            AgentInstanceContext agentInstanceContext = evalEveryNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryStart(evalEveryNode.factoryNode, beginState);
            agentInstanceContext.AuditProvider.PatternInstance(true, evalEveryNode.factoryNode, agentInstanceContext);

            this.beginState = beginState.ShallowCopy();
            EvalStateNode childState = evalEveryNode.ChildNode.NewState(this);
            spawnedNodes.Add(childState);

            // During the start of the child we need to use the temporary evaluator to catch any event created during a start.
            // Events created during the start would likely come from the "not" operator.
            // Quit the new child again if
            var spawnEvaluator = new EvalEveryStateSpawnEvaluator(evalEveryNode.Context.StatementName);
            childState.ParentEvaluator = spawnEvaluator;
            childState.Start(beginState);

            // If the spawned expression turned true already, just quit it
            if (spawnEvaluator.IsEvaluatedTrue) {
                childState.Quit();
            }
            else {
                childState.ParentEvaluator = this;
            }

            agentInstanceContext.InstrumentationProvider.APatternEveryStart();
        }
コード例 #6
0
        public void EvaluateFalse(
            EvalStateNode fromNode,
            bool restartable)
        {
            var agentInstanceContext = evalAndNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternAndEvaluateFalse(evalAndNode.factoryNode);

            int? indexFrom = null;
            for (var i = 0; i < activeChildNodes.Length; i++) {
                if (activeChildNodes[i] == fromNode) {
                    activeChildNodes[i] = null;
                    indexFrom = i;
                }
            }

            if (indexFrom != null) {
                eventsPerChild[indexFrom.Value] = null;
            }

            // The and node cannot turn true anymore, might as well quit all child nodes
            QuitInternal();

            agentInstanceContext.AuditProvider.PatternFalse(evalAndNode.FactoryNode, this, agentInstanceContext);
            agentInstanceContext.AuditProvider.PatternInstance(false, evalAndNode.factoryNode, agentInstanceContext);
            ParentEvaluator.EvaluateFalse(this, restartable ? true : false);

            agentInstanceContext.InstrumentationProvider.APatternAndEvaluateFalse();
        }
コード例 #7
0
ファイル: EvalNotStateNode.cs プロジェクト: lanicon/nesper
 public void EvaluateFalse(
     EvalStateNode fromNode,
     bool restartable)
 {
     var agentInstanceContext = evalNotNode.Context.AgentInstanceContext;
     agentInstanceContext.InstrumentationProvider.QPatternNotEvalFalse(evalNotNode.factoryNode);
     agentInstanceContext.InstrumentationProvider.APatternNotEvalFalse();
 }
コード例 #8
0
 public void EvaluateFalse(
     EvalStateNode fromNode,
     bool restartable)
 {
     log.Warn(
         "Event/request processing: Uncontrolled pattern matching of \"every\" operator - infinite loop when using EVERY operator on expression(s) containing a not operator, for statement '" +
         statementName +
         "'");
     IsEvaluatedTrue = true;
 }
コード例 #9
0
 public void EvaluateFalse(
     EvalStateNode fromNode,
     bool restartable)
 {
     activeChildNode = null;
     var agentInstanceContext = evalGuardNode.Context.AgentInstanceContext;
     agentInstanceContext.InstrumentationProvider.QPatternGuardEvalFalse(evalGuardNode.factoryNode);
     agentInstanceContext.AuditProvider.PatternFalse(evalGuardNode.FactoryNode, this, agentInstanceContext);
     agentInstanceContext.AuditProvider.PatternInstance(false, evalGuardNode.factoryNode, agentInstanceContext);
     ParentEvaluator.EvaluateFalse(this, true);
     agentInstanceContext.InstrumentationProvider.APatternGuardEvalFalse();
 }
コード例 #10
0
 public void EvaluateTrue(
     MatchedEventMap matchEvent,
     EvalStateNode fromNode,
     bool isQuitted,
     EventBean optionalTriggeringEvent)
 {
     log.Warn(
         "Event/request processing: Uncontrolled pattern matching of \"every\" operator - infinite loop when using EVERY operator on expression(s) containing a not operator, for statement '" +
         statementName +
         "'");
     IsEvaluatedTrue = true;
 }
コード例 #11
0
ファイル: EvalEveryStateNode.cs プロジェクト: lanicon/nesper
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            AgentInstanceContext agentInstanceContext = evalEveryNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryEvaluateTrue(
                evalEveryNode.factoryNode,
                matchEvent);

            if (isQuitted) {
                spawnedNodes.Remove(fromNode);
            }

            // See explanation in EvalFilterStateNode for the type check
            if (fromNode.IsFilterStateNode || fromNode.IsObserverStateNodeNonRestarting) {
                // We do not need to newState new listeners here, since the filter state node below this node did not quit
            }
            else {
                // Spawn all nodes below this EVERY node
                // During the start of a child we need to use the temporary evaluator to catch any event created during a start
                // Such events can be raised when the "not" operator is used.
                var spawnEvaluator = new EvalEveryStateSpawnEvaluator(evalEveryNode.Context.StatementName);
                EvalStateNode spawned = evalEveryNode.ChildNode.NewState(spawnEvaluator);
                spawned.Start(beginState);

                // If the whole spawned expression already turned true, quit it again
                if (spawnEvaluator.IsEvaluatedTrue) {
                    spawned.Quit();
                }
                else {
                    spawnedNodes.Add(spawned);
                    spawned.ParentEvaluator = this;
                }
            }

            // All nodes indicate to their parents that their child node did not quit, therefore a false for isQuitted
            agentInstanceContext.AuditProvider.PatternTrue(
                evalEveryNode.FactoryNode,
                this,
                matchEvent,
                false,
                agentInstanceContext);
            ParentEvaluator.EvaluateTrue(matchEvent, this, false, optionalTriggeringEvent);

            agentInstanceContext.InstrumentationProvider.APatternEveryEvaluateTrue();
        }
コード例 #12
0
ファイル: EvalNotStateNode.cs プロジェクト: lanicon/nesper
        public override void Start(MatchedEventMap beginState)
        {
            var factoryNode = evalNotNode.FactoryNode;
            var agentInstanceContext = evalNotNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternNotStart(evalNotNode.factoryNode, beginState);
            agentInstanceContext.AuditProvider.PatternInstance(true, factoryNode, agentInstanceContext);

            childNode = evalNotNode.ChildNode.NewState(this);
            childNode.Start(beginState);

            // The not node acts by inverting the truth
            // By default the child nodes are false. This not node acts inverts the truth and pretends the child is true,
            // raising an event up.
            agentInstanceContext.AuditProvider.PatternTrue(factoryNode, this, beginState, false, agentInstanceContext);
            ParentEvaluator.EvaluateTrue(beginState, this, false, null);
            agentInstanceContext.InstrumentationProvider.APatternNotStart();
        }
コード例 #13
0
        public override void Start(MatchedEventMap beginState)
        {
            var agentInstanceContext = evalGuardNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternGuardStart(evalGuardNode.factoryNode, beginState);
            agentInstanceContext.AuditProvider.PatternInstance(true, evalGuardNode.factoryNode, agentInstanceContext);

            this.beginState = beginState;
            guard = evalGuardNode.FactoryNode.GuardFactory.MakeGuard(evalGuardNode.Context, beginState, this, null);
            activeChildNode = evalGuardNode.ChildNode.NewState(this);

            // Start the single child state
            activeChildNode.Start(beginState);

            // Start the guard
            guard.StartGuard();

            agentInstanceContext.InstrumentationProvider.APatternGuardStart();
        }
コード例 #14
0
        public override void Quit()
        {
            if (activeChildNode == null) {
                return;
            }

            var agentInstanceContext = evalGuardNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternGuardQuit(evalGuardNode.factoryNode);
            agentInstanceContext.AuditProvider.PatternInstance(false, evalGuardNode.factoryNode, agentInstanceContext);

            if (activeChildNode != null) {
                activeChildNode.Quit();
                guard.StopGuard();
            }

            activeChildNode = null;

            agentInstanceContext.InstrumentationProvider.APatternGuardQuit();
        }
コード例 #15
0
        public void GuardQuit()
        {
            var agentInstanceContext = evalGuardNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternGuardGuardQuit(evalGuardNode.factoryNode);

            // It is possible that the child node has already been quit such as when the parent wait time was shorter.
            // 1. parent node's guard indicates quit to all children
            // 2. this node's guards also indicates quit, however that already occured
            activeChildNode?.Quit();

            activeChildNode = null;

            // Indicate to parent state that this is permanently false.
            agentInstanceContext.AuditProvider.PatternFalse(evalGuardNode.FactoryNode, this, agentInstanceContext);
            agentInstanceContext.AuditProvider.PatternInstance(false, evalGuardNode.factoryNode, agentInstanceContext);
            ParentEvaluator.EvaluateFalse(this, true);

            agentInstanceContext.InstrumentationProvider.APatternGuardGuardQuit();
        }
コード例 #16
0
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            var agentInstanceContext = evalGuardNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternGuardEvaluateTrue(
                evalGuardNode.factoryNode,
                matchEvent);

            var haveQuitted = activeChildNode == null;

            // If one of the children quits, remove the child
            if (isQuitted) {
                agentInstanceContext.AuditProvider.PatternInstance(
                    false,
                    evalGuardNode.factoryNode,
                    agentInstanceContext);
                activeChildNode = null;

                // Stop guard, since associated subexpression is gone
                guard.StopGuard();
            }

            if (!haveQuitted) {
                var guardPass = guard.Inspect(matchEvent);
                if (guardPass) {
                    agentInstanceContext.AuditProvider.PatternTrue(
                        evalGuardNode.FactoryNode,
                        this,
                        matchEvent,
                        isQuitted,
                        agentInstanceContext);
                    ParentEvaluator.EvaluateTrue(matchEvent, this, isQuitted, optionalTriggeringEvent);
                }
            }

            agentInstanceContext.InstrumentationProvider.APatternGuardEvaluateTrue(isQuitted);
        }
コード例 #17
0
        public void EvaluateFalse(
            EvalStateNode fromNode,
            bool restartable)
        {
            AgentInstanceContext agentInstanceContext = evalFollowedByNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternFollowedByEvalFalse(evalFollowedByNode.factoryNode);

            fromNode.Quit();
            bool hasIndex = nodes.TryGetValue(fromNode, out var index);
            if (hasIndex) {
                nodes.Remove(fromNode);
            }

            if (hasIndex && index > 0) {
                if (evalFollowedByNode.IsTrackWithMax) {
                    countActivePerChild[index - 1]--;
                }

                if (evalFollowedByNode.IsTrackWithPool) {
                    PatternSubexpressionPoolStmtSvc poolSvc =
                        evalFollowedByNode.Context.StatementContext.PatternSubexpressionPoolSvc;
                    poolSvc.RuntimeSvc.DecreaseCount(
                        evalFollowedByNode,
                        evalFollowedByNode.Context.AgentInstanceContext);
                    poolSvc.StmtHandler.DecreaseCount();
                }
            }

            if (nodes.IsEmpty()) {
                agentInstanceContext.AuditProvider.PatternFalse(
                    evalFollowedByNode.FactoryNode,
                    this,
                    agentInstanceContext);
                this.ParentEvaluator.EvaluateFalse(this, true);
                Quit();
            }

            agentInstanceContext.InstrumentationProvider.APatternFollowedByEvalFalse();
        }
コード例 #18
0
ファイル: EvalEveryStateNode.cs プロジェクト: lanicon/nesper
        public void EvaluateFalse(
            EvalStateNode fromNode,
            bool restartable)
        {
            AgentInstanceContext agentInstanceContext = evalEveryNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryEvalFalse(evalEveryNode.factoryNode);

            fromNode.Quit();
            spawnedNodes.Remove(fromNode);

            if (!restartable) {
                agentInstanceContext.AuditProvider.PatternFalse(evalEveryNode.FactoryNode, this, agentInstanceContext);
                agentInstanceContext.AuditProvider.PatternInstance(
                    false,
                    evalEveryNode.factoryNode,
                    agentInstanceContext);
                ParentEvaluator.EvaluateFalse(this, false);
                return;
            }

            // Spawn all nodes below this EVERY node
            // During the start of a child we need to use the temporary evaluator to catch any event created during a start
            // Such events can be raised when the "not" operator is used.
            var spawnEvaluator = new EvalEveryStateSpawnEvaluator(evalEveryNode.Context.StatementName);
            EvalStateNode spawned = evalEveryNode.ChildNode.NewState(spawnEvaluator);
            spawned.Start(beginState);

            // If the whole spawned expression already turned true, quit it again
            if (spawnEvaluator.IsEvaluatedTrue) {
                spawned.Quit();
            }
            else {
                spawnedNodes.Add(spawned);
                spawned.ParentEvaluator = this;
            }

            agentInstanceContext.InstrumentationProvider.APatternEveryEvalFalse();
        }
コード例 #19
0
ファイル: EvalNotStateNode.cs プロジェクト: lanicon/nesper
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            var agentInstanceContext = evalNotNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternNotEvaluateTrue(evalNotNode.factoryNode, matchEvent);

            // Only is the subexpression stopped listening can we tell the parent evaluator that this
            // turned permanently false.
            if (isQuitted) {
                childNode = null;
                agentInstanceContext.AuditProvider.PatternFalse(evalNotNode.FactoryNode, this, agentInstanceContext);
                agentInstanceContext.AuditProvider.PatternInstance(
                    false,
                    evalNotNode.factoryNode,
                    agentInstanceContext);
                ParentEvaluator.EvaluateFalse(this, true);
            }

            agentInstanceContext.InstrumentationProvider.APatternNotEvaluateTrue(isQuitted);
        }
コード例 #20
0
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            var agentInstanceContext = everyDistinctNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryDistinctEvaluateTrue(
                everyDistinctNode.factoryNode,
                matchEvent);

            // determine if this evaluation has been seen before from the same node
            var matchEventKey = PatternExpressionUtil.GetKeys(
                matchEvent,
                everyDistinctNode.FactoryNode.Convertor,
                everyDistinctNode.FactoryNode.DistinctExpression,
                everyDistinctNode.Context.AgentInstanceContext);
            var haveSeenThis = false;
            var keysFromNode = spawnedNodes.Get(fromNode);
            if (keysFromNode != null) {
                if (keysFromNode.Contains(matchEventKey)) {
                    haveSeenThis = true;
                }
                else {
                    keysFromNode.Add(matchEventKey);
                }
            }

            if (isQuitted) {
                spawnedNodes.Remove(fromNode);
            }

            // See explanation in EvalFilterStateNode for the type check
            if (fromNode.IsFilterStateNode) {
                // We do not need to newState new listeners here, since the filter state node below this node did not quit
            }
            else {
                // Spawn all nodes below this EVERY node
                // During the start of a child we need to use the temporary evaluator to catch any event created during a start
                // Such events can be raised when the "not" operator is used.
                var spawnEvaluator = new EvalEveryStateSpawnEvaluator(everyDistinctNode.Context.StatementName);
                var spawned = everyDistinctNode.ChildNode.NewState(spawnEvaluator);
                spawned.Start(beginState);

                // If the whole spawned expression already turned true, quit it again
                if (spawnEvaluator.IsEvaluatedTrue) {
                    spawned.Quit();
                }
                else {
                    ISet<object> keyset = new HashSet<object>();
                    if (keysFromNode != null) {
                        keyset.AddAll(keysFromNode);
                    }

                    spawnedNodes.Put(spawned, keyset);
                    spawned.ParentEvaluator = this;
                }
            }

            if (!haveSeenThis) {
                agentInstanceContext.AuditProvider.PatternTrue(
                    everyDistinctNode.FactoryNode,
                    this,
                    matchEvent,
                    false,
                    agentInstanceContext);
                ParentEvaluator.EvaluateTrue(matchEvent, this, false, optionalTriggeringEvent);
            }

            agentInstanceContext.InstrumentationProvider.APatternEveryDistinctEvaluateTrue(
                keysFromNode,
                null,
                matchEventKey,
                haveSeenThis);
        }
コード例 #21
0
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            var agentInstanceContext = everyNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryDistinctEvaluateTrue(
                everyNode.factoryNode,
                matchEvent);

            // determine if this evaluation has been seen before from the same node
            var matchEventKey = PatternExpressionUtil.GetKeys(
                matchEvent,
                everyNode.FactoryNode.Convertor,
                everyNode.FactoryNode.DistinctExpression,
                everyNode.Context.AgentInstanceContext);
            var haveSeenThis = false;
            IDictionary<object, long> keysFromNode = spawnedNodes.Get(fromNode);
            if (keysFromNode != null) {
                // Clean out old keys

                var keysToRemove = new List<object>();
                var enumerator = keysFromNode.GetEnumerator();
                var currentTime = everyNode.Context.AgentInstanceContext.TimeProvider.Time;
                for (; enumerator.MoveNext();) {
                    var entry = enumerator.Current;
                    if (currentTime >= entry.Value) {
                        keysToRemove.Add(entry.Key);
                    }
                    else {
                        break;
                    }
                }

                // Remove the keys
                keysToRemove.ForEach(key => keysFromNode.Remove(key));

                if (keysFromNode.ContainsKey(matchEventKey)) {
                    haveSeenThis = true;
                }
                else {
                    var expiryTime = everyNode.FactoryNode.AbsExpiry(everyNode.Context);
                    keysFromNode.Put(matchEventKey, expiryTime);
                }
            }

            if (isQuitted) {
                spawnedNodes.Remove(fromNode);
            }

            // See explanation in EvalFilterStateNode for the type check
            if (fromNode.IsFilterStateNode) {
                // We do not need to newState new listeners here, since the filter state node below this node did not quit
            }
            else {
                // Spawn all nodes below this EVERY node
                // During the start of a child we need to use the temporary evaluator to catch any event created during a start
                // Such events can be raised when the "not" operator is used.
                var spawnEvaluator = new EvalEveryStateSpawnEvaluator(everyNode.Context.StatementName);
                var spawned = everyNode.ChildNode.NewState(spawnEvaluator);
                spawned.Start(beginState);

                // If the whole spawned expression already turned true, quit it again
                if (spawnEvaluator.IsEvaluatedTrue) {
                    spawned.Quit();
                }
                else {
                    var keyset = new LinkedHashMap<object, long>();
                    if (keysFromNode != null) {
                        keyset.PutAll(keysFromNode);
                    }

                    spawnedNodes.Put(spawned, keyset);
                    spawned.ParentEvaluator = this;
                }
            }

            if (!haveSeenThis) {
                agentInstanceContext.AuditProvider.PatternTrue(
                    everyNode.FactoryNode,
                    this,
                    matchEvent,
                    false,
                    agentInstanceContext);
                ParentEvaluator.EvaluateTrue(matchEvent, this, false, optionalTriggeringEvent);
            }

            agentInstanceContext.InstrumentationProvider.APatternEveryDistinctEvaluateTrue(
                null,
                keysFromNode,
                matchEventKey,
                haveSeenThis);
        }
コード例 #22
0
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            bool hasIndex = nodes.TryGetValue(fromNode, out var index);

            AgentInstanceContext agentInstanceContext = evalFollowedByNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternFollowedByEvaluateTrue(
                evalFollowedByNode.factoryNode,
                matchEvent,
                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.RuntimeSvc.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) {
                agentInstanceContext.InstrumentationProvider.APatternFollowedByEvaluateTrue(false);
                return;
            }

            // If the match came from the very last filter, need to escalate
            var numChildNodes = evalFollowedByNode.ChildNodes.Length;
            var isFollowedByQuitted = false;
            if (index == numChildNodes - 1) {
                if (nodes.IsEmpty()) {
                    isFollowedByQuitted = true;
                    agentInstanceContext.AuditProvider.PatternInstance(
                        false,
                        evalFollowedByNode.factoryNode,
                        agentInstanceContext);
                }

                agentInstanceContext.AuditProvider.PatternTrue(
                    evalFollowedByNode.FactoryNode,
                    this,
                    matchEvent,
                    isFollowedByQuitted,
                    agentInstanceContext);
                this.ParentEvaluator.EvaluateTrue(matchEvent, this, isFollowedByQuitted, optionalTriggeringEvent);
            }
            else {
                // Else start a new sub-expression for the next-in-line filter
                if (evalFollowedByNode.IsTrackWithMax) {
                    var 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);
                            return;
                        }
                    }
                }

                if (evalFollowedByNode.IsTrackWithPool) {
                    PatternSubexpressionPoolStmtSvc poolSvc =
                        evalFollowedByNode.Context.StatementContext.PatternSubexpressionPoolSvc;
                    bool allow = poolSvc.RuntimeSvc.TryIncreaseCount(
                        evalFollowedByNode,
                        evalFollowedByNode.Context.AgentInstanceContext);
                    if (!allow) {
                        return;
                    }

                    poolSvc.StmtHandler.IncreaseCount();
                }

                if (evalFollowedByNode.IsTrackWithMax) {
                    countActivePerChild[index]++;
                }

                var child = evalFollowedByNode.ChildNodes[index + 1];
                var childState = child.NewState(this);
                nodes.Put(childState, index + 1);
                childState.Start(matchEvent);
            }

            agentInstanceContext.InstrumentationProvider.APatternFollowedByEvaluateTrue(isFollowedByQuitted);
        }
コード例 #23
0
        public void EvaluateTrue(
            MatchedEventMap matchEvent,
            EvalStateNode fromNode,
            bool isQuitted,
            EventBean optionalTriggeringEvent)
        {
            var agentInstanceContext = evalAndNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternAndEvaluateTrue(evalAndNode.factoryNode, matchEvent);

            int? indexFrom = null;
            for (var i = 0; i < activeChildNodes.Length; i++) {
                if (activeChildNodes[i] == fromNode) {
                    indexFrom = i;
                }
            }

            // If one of the children quits, remove the child
            if (isQuitted && indexFrom != null) {
                activeChildNodes[indexFrom.Value] = null;
            }

            if (eventsPerChild == null || indexFrom == null) {
                agentInstanceContext.InstrumentationProvider.APatternAndEvaluateTrue(true);
                return;
            }

            // If all nodes have events received, the AND expression turns true
            var allHaveEventsExcludingFromChild = true;
            for (var i = 0; i < eventsPerChild.Length; i++) {
                if (indexFrom != i && eventsPerChild[i] == null) {
                    allHaveEventsExcludingFromChild = false;
                    break;
                }
            }

            // if we don't have events from all child nodes, add event and done
            if (!allHaveEventsExcludingFromChild) {
                AddMatchEvent(eventsPerChild, indexFrom.Value, matchEvent);
                agentInstanceContext.InstrumentationProvider.APatternAndEvaluateTrue(false);
                return;
            }

            // if all other nodes have quit other then the from-node, don't retain matching event
            var allOtherNodesQuit = true;
            var hasActive = false;
            for (var i = 0; i < eventsPerChild.Length; i++) {
                if (activeChildNodes[i] != null) {
                    hasActive = true;
                    if (i != indexFrom) {
                        allOtherNodesQuit = false;
                    }
                }
            }

            // if not all other nodes have quit, add event to received list
            if (!allOtherNodesQuit) {
                AddMatchEvent(eventsPerChild, indexFrom.Value, matchEvent);
            }

            // For each combination in eventsPerChild for all other state nodes generate an event to the parent
            var result = GenerateMatchEvents(matchEvent, eventsPerChild, indexFrom.Value);

            // Check if this is quitting
            var quitted = true;
            if (hasActive) {
                foreach (var stateNode in activeChildNodes) {
                    if (stateNode != null && !stateNode.IsNotOperator) {
                        quitted = false;
                    }
                }
            }

            // So we are quitting if all non-not child nodes have quit, since the not-node wait for evaluate false
            if (quitted) {
                agentInstanceContext.AuditProvider.PatternInstance(
                    false,
                    evalAndNode.factoryNode,
                    agentInstanceContext);
                QuitInternal();
            }

            // Send results to parent
            foreach (var theEvent in result) {
                agentInstanceContext.AuditProvider.PatternTrue(
                    evalAndNode.FactoryNode,
                    this,
                    theEvent,
                    quitted,
                    agentInstanceContext);
                ParentEvaluator.EvaluateTrue(theEvent, this, quitted, optionalTriggeringEvent);
            }

            agentInstanceContext.InstrumentationProvider.APatternAndEvaluateTrue(quitted);
        }