Example #1
0
        public OutputConditionPolled MakeNew(AgentInstanceContext agentInstanceContext)
        {
            ScheduleSpec scheduleSpec;
            try {
                var scheduleSpecParameterList = Evaluate(expressions, agentInstanceContext);
                scheduleSpec = ScheduleSpecUtil.ComputeValues(scheduleSpecParameterList);
            }
            catch (ScheduleParameterException e) {
                throw new ArgumentException("Invalid schedule specification : " + e.Message, e);
            }

            var state = new OutputConditionPolledCrontabState(scheduleSpec, null, 0);
            return new OutputConditionPolledCrontab(agentInstanceContext, state);
        }
Example #2
0
        public ScheduleSpec ComputeSpec(MatchedEventMap beginState, PatternAgentInstanceContext context)
        {
            if (spec != null)
            {
                return(spec);
            }
            IList <Object> observerParameters = PatternExpressionUtil.Evaluate("Timer-at observer", beginState, parameters, convertor, context.AgentInstanceContext);

            try {
                return(ScheduleSpecUtil.ComputeValues(observerParameters.ToArray()));
            }
            catch (ScheduleParameterException e) {
                throw new EPException("Error computing crontab schedule specification: " + e.Message, e);
            }
        }
Example #3
0
        public void SetObserverParameters(
            IList <ExprNode> parameters,
            MatchedEventConvertor convertor,
            ExprValidationContext validationContext)
        {
            ObserverParameterUtil.ValidateNoNamedParameters("timer:at", parameters);
            if (Log.IsDebugEnabled)
            {
                Log.Debug(".setObserverParameters " + parameters);
            }

            if ((parameters.Count < 5) || (parameters.Count > 7))
            {
                throw new ObserverParameterException("Invalid number of parameters for timer:at");
            }

            _parameters = parameters;
            _convertor  = convertor;

            // if all parameters are constants, lets try to evaluate and build a schedule for early validation
            bool allConstantResult = true;

            foreach (ExprNode param in parameters)
            {
                if (!param.IsConstantResult)
                {
                    allConstantResult = false;
                }
            }

            if (allConstantResult)
            {
                try
                {
                    var observerParameters = PatternExpressionUtil.Evaluate(
                        "Timer-at observer", new MatchedEventMapImpl(convertor.MatchedEventMapMeta), parameters,
                        convertor, null);
                    _spec = ScheduleSpecUtil.ComputeValues(observerParameters.ToArray());
                }
                catch (ScheduleParameterException e)
                {
                    throw new ObserverParameterException(
                              "Error computing crontab schedule specification: " + e.Message, e);
                }
            }
        }
Example #4
0
        /// <summary>Constructor. </summary>
        /// <param name="agentInstanceContext">is the view context for time scheduling</param>
        /// <param name="scheduleSpecExpressionList">list of schedule parameters</param>
        /// <throws><seealso cref="ExprValidationException" /> if the crontab expression failed to validate</throws>
        public OutputConditionPolledCrontab(
            IList <ExprNode> scheduleSpecExpressionList,
            AgentInstanceContext agentInstanceContext)
        {
            if (agentInstanceContext == null)
            {
                const string message = "OutputConditionTime requires a non-null view context";
                throw new ArgumentNullException("agentInstanceContext", message);
            }

            _agentInstanceContext = agentInstanceContext;

            // Validate the expression
            var expressions       = new ExprEvaluator[scheduleSpecExpressionList.Count];
            var count             = 0;
            var validationContext =
                new ExprValidationContext(
                    new StreamTypeServiceImpl(agentInstanceContext.StatementContext.EngineURI, false),
                    agentInstanceContext.StatementContext.MethodResolutionService, null,
                    agentInstanceContext.StatementContext.SchedulingService,
                    agentInstanceContext.StatementContext.VariableService,
                    agentInstanceContext.StatementContext.TableService, agentInstanceContext,
                    agentInstanceContext.StatementContext.EventAdapterService,
                    agentInstanceContext.StatementContext.StatementName,
                    agentInstanceContext.StatementContext.StatementId,
                    agentInstanceContext.StatementContext.Annotations,
                    agentInstanceContext.StatementContext.ContextDescriptor,
                    agentInstanceContext.StatementContext.ScriptingService,
                    false, false, false, false, null, false);

            foreach (var parameters in scheduleSpecExpressionList)
            {
                var node = ExprNodeUtility.GetValidatedSubtree(ExprNodeOrigin.OUTPUTLIMIT, parameters, validationContext);
                expressions[count++] = node.ExprEvaluator;
            }

            try
            {
                var scheduleSpecParameterList = Evaluate(expressions, agentInstanceContext);
                _scheduleSpec = ScheduleSpecUtil.ComputeValues(scheduleSpecParameterList);
            }
            catch (ScheduleParameterException e)
            {
                throw new ArgumentException("Invalid schedule specification : " + e.Message, e);
            }
        }
Example #5
0
        public void SetObserverParameters(
            IList<ExprNode> parameters,
            MatchedEventConvertorForge convertor,
            ExprValidationContext validationContext)
        {
            ObserverParameterUtil.ValidateNoNamedParameters("timer:at", parameters);
            if (Log.IsDebugEnabled) {
                Log.Debug(".setObserverParameters " + parameters);
            }

            if (parameters.Count < 5 || parameters.Count > 9) {
                throw new ObserverParameterException("Invalid number of parameters for timer:at");
            }

            this.parameters = parameters;
            this.convertor = convertor;

            // if all parameters are constants, lets try to evaluate and build a schedule for early validation
            var allConstantResult = true;
            foreach (var param in parameters) {
                if (!(param is ExprWildcard) && !param.Forge.ForgeConstantType.IsCompileTimeConstant) {
                    allConstantResult = false;
                }
            }

            if (allConstantResult) {
                try {
                    var observerParameters = EvaluateCompileTime(parameters);
                    spec = ScheduleSpecUtil.ComputeValues(observerParameters.ToArray());
                }
                catch (ScheduleParameterException e) {
                    throw new ObserverParameterException(
                        "Error computing crontab schedule specification: " + e.Message,
                        e);
                }
            }
        }