public override void Start(MatchedEventMap beginState)
        {
            var agentInstanceContext = everyNode.Context.AgentInstanceContext;
            agentInstanceContext.InstrumentationProvider.QPatternEveryDistinctStart(everyNode.factoryNode, beginState);
            agentInstanceContext.AuditProvider.PatternInstance(true, everyNode.factoryNode, agentInstanceContext);

            this.beginState = beginState.ShallowCopy();
            var childState = everyNode.ChildNode.NewState(this);
            spawnedNodes.Put(childState, new LinkedHashMap<object, long>());

            // 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(everyNode.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.APatternEveryDistinctStart();
        }
        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();
        }
        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.º 4
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);
        }