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);
        }
Exemplo n.º 2
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);
        }