public void Activate(EventBean optionalTriggeringEvent, MatchedEventMap priorMatches, long timeOffset, bool isRecoveringResilient)
        {
            if (PatternStopCallback != null)
            {
                PatternStopCallback.Stop();
            }

            PatternStreamSpecCompiled patternStreamSpec = _endpointPatternSpec.PatternCompiled;
            StatementContext          stmtContext       = _agentInstanceContext.StatementContext;

            EvalRootFactoryNode rootFactoryNode = _servicesContext.PatternNodeFactory.MakeRootNode(patternStreamSpec.EvalFactoryNode);
            int            streamNum            = _isStartEndpoint ? _contextStatePathKey.SubPath : -1 * _contextStatePathKey.SubPath;
            bool           allowResilient       = _contextStatePathKey.Level == 1;
            PatternContext patternContext       = stmtContext.PatternContextFactory.CreateContext(stmtContext, streamNum, rootFactoryNode, new MatchedEventMapMeta(patternStreamSpec.AllTags, !patternStreamSpec.ArrayEventTypes.IsEmpty()), allowResilient);

            PatternAgentInstanceContext patternAgentInstanceContext = stmtContext.PatternContextFactory.CreatePatternAgentContext(patternContext, _agentInstanceContext, false);
            EvalRootNode rootNode = EvalNodeUtil.MakeRootNodeFromFactory(rootFactoryNode, patternAgentInstanceContext);

            if (priorMatches == null)
            {
                priorMatches = new MatchedEventMapImpl(patternContext.MatchedEventMapMeta);
            }

            // capture any callbacks that may occur right after start
            ConditionPatternMatchCallback callback = new ConditionPatternMatchCallback(this);

            PatternStopCallback   = rootNode.Start(callback.MatchFound, patternContext, priorMatches, isRecoveringResilient);
            callback.ForwardCalls = true;

            if (_agentInstanceContext.StatementContext.StatementExtensionServicesContext != null &&
                _agentInstanceContext.StatementContext.StatementExtensionServicesContext.StmtResources != null)
            {
                _agentInstanceContext.StatementContext.StatementExtensionServicesContext.StmtResources
                .StartContextPattern(PatternStopCallback, _isStartEndpoint, _contextStatePathKey);
            }

            if (callback.IsInvoked)
            {
                MatchFound(Collections.GetEmptyMap <String, Object>());
            }
        }
        public bool Activate(
            EventBean optionalTriggeringEvent,
            ContextControllerEndConditionMatchEventProvider endConditionMatchEventProvider,
            IDictionary<string, object> optionalTriggeringPattern)
        {
            patternStopCallback?.Stop();

            var agentInstanceContext = controller.Realization.AgentInstanceContextCreate;
            Func<FilterSpecActivatable, FilterValueSetParam[][]> contextAddendumFunction = filter =>
                ContextManagerUtil.ComputeAddendumNonStmt(partitionKeys, filter, controller.Realization);
            var patternAgentInstanceContext = new PatternAgentInstanceContext(
                pattern.PatternContext,
                agentInstanceContext,
                false,
                contextAddendumFunction);
            var rootNode = EvalNodeUtil.MakeRootNodeFromFactory(pattern.Pattern, patternAgentInstanceContext);

            var matchedEventMap = new MatchedEventMapImpl(pattern.PatternContext.MatchedEventMapMeta);
            if (optionalTriggeringEvent != null) {
                endConditionMatchEventProvider?.PopulateEndConditionFromTrigger(
                    matchedEventMap,
                    optionalTriggeringEvent);
            }

            if (optionalTriggeringPattern != null) {
                endConditionMatchEventProvider?.PopulateEndConditionFromTrigger(matchedEventMap, optionalTriggeringPattern);
            }
            
            // capture any callbacks that may occur right after start
            var callback = new ConditionPatternMatchCallback(this);
            patternStopCallback = rootNode.Start(callback, pattern.PatternContext, matchedEventMap, false);
            callback.forwardCalls = true;

            if (callback.IsInvoked) {
                MatchFound(Collections.GetEmptyMap<string, object>(), optionalTriggeringEvent);
            }

            return false;
        }