예제 #1
0
 /// <summary>Ctor. </summary>
 /// <param name="scheduleSpec">specification containing the crontab schedule</param>
 /// <param name="beginState">start state</param>
 /// <param name="observerEventEvaluator">receiver for events</param>
 public TimerAtObserver(ScheduleSpec scheduleSpec, MatchedEventMap beginState, ObserverEventEvaluator observerEventEvaluator)
 {
     _scheduleSpec           = scheduleSpec;
     _beginState             = beginState;
     _observerEventEvaluator = observerEventEvaluator;
     _scheduleSlot           = observerEventEvaluator.Context.PatternContext.ScheduleBucket.AllocateSlot();
 }
예제 #2
0
        public static ContextControllerConditionNonHA GetEndpoint(
            IntSeqKey conditionPath,
            object[] partitionKeys,
            ContextConditionDescriptor endpoint,
            ContextControllerConditionCallback callback,
            ContextController controller,
            bool isStartEndpoint)
        {
            if (endpoint is ContextConditionDescriptorFilter) {
                ContextConditionDescriptorFilter filter = (ContextConditionDescriptorFilter) endpoint;
                return new ContextControllerConditionFilter(conditionPath, partitionKeys, filter, callback, controller);
            }

            if (endpoint is ContextConditionDescriptorTimePeriod) {
                ContextConditionDescriptorTimePeriod timePeriod = (ContextConditionDescriptorTimePeriod) endpoint;
                long scheduleSlot = controller.Realization.AgentInstanceContextCreate.ScheduleBucket.AllocateSlot();
                return new ContextControllerConditionTimePeriod(
                    scheduleSlot,
                    timePeriod,
                    conditionPath,
                    callback,
                    controller);
            }

            if (endpoint is ContextConditionDescriptorCrontab) {
                ContextConditionDescriptorCrontab crontab = (ContextConditionDescriptorCrontab) endpoint;
                ScheduleSpec schedule = ScheduleExpressionUtil.CrontabScheduleBuild(
                    crontab.Evaluators,
                    controller.Realization.AgentInstanceContextCreate);
                long scheduleSlot = controller.Realization.AgentInstanceContextCreate.ScheduleBucket.AllocateSlot();
                return new ContextControllerConditionCrontabImpl(
                    conditionPath,
                    scheduleSlot,
                    schedule,
                    crontab,
                    callback,
                    controller);
            }

            if (endpoint is ContextConditionDescriptorPattern) {
                ContextConditionDescriptorPattern pattern = (ContextConditionDescriptorPattern) endpoint;
                return new ContextControllerConditionPattern(
                    conditionPath,
                    partitionKeys,
                    pattern,
                    callback,
                    controller);
            }

            if (endpoint is ContextConditionDescriptorNever) {
                return ContextControllerConditionNever.INSTANCE;
            }

            if (endpoint is ContextConditionDescriptorImmediate) {
                return ContextControllerConditionImmediate.INSTANCE;
            }

            throw new IllegalStateException("Unrecognized context range endpoint " + endpoint.GetType());
        }
예제 #3
0
 public OutputConditionPolledCrontabState(
     ScheduleSpec scheduleSpec,
     long? currentReferencePoint,
     long nextScheduledTime)
 {
     ScheduleSpec = scheduleSpec;
     CurrentReferencePoint = currentReferencePoint;
     NextScheduledTime = nextScheduledTime;
 }
예제 #4
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="scheduleSpec">specification containing the crontab schedule</param>
 /// <param name="beginState">start state</param>
 /// <param name="observerEventEvaluator">receiver for events</param>
 public TimerAtObserver(
     ScheduleSpec scheduleSpec,
     MatchedEventMap beginState,
     ObserverEventEvaluator observerEventEvaluator)
 {
     this.scheduleSpec = scheduleSpec;
     this.beginState = beginState;
     this.observerEventEvaluator = observerEventEvaluator;
     this.scheduleSlot = observerEventEvaluator.Context.AgentInstanceContext.ScheduleBucket.AllocateSlot();
 }
예제 #5
0
 public long? GetExpectedEndTime(
     ContextManagerRealization realization,
     ScheduleSpec scheduleSpec)
 {
     var classpathImportService = realization.AgentInstanceContextCreate.ImportServiceRuntime;
     return ScheduleComputeHelper.ComputeNextOccurance(
         scheduleSpec,
         realization.AgentInstanceContextCreate.TimeProvider.Time,
         classpathImportService.TimeZone,
         classpathImportService.TimeAbacus);
 }
예제 #6
0
 public OutputConditionCrontab(OutputCallback outputCallback, AgentInstanceContext context, bool isStartConditionOnCreation, ScheduleSpec scheduleSpec)
     : base(outputCallback)
 {
     _context      = context;
     _scheduleSpec = scheduleSpec;
     _scheduleSlot = context.StatementContext.ScheduleBucket.AllocateSlot();
     if (isStartConditionOnCreation)
     {
         UpdateOutputCondition(0, 0);
     }
 }
예제 #7
0
        public void SetUp()
        {
            _beginState = new MatchedEventMapImpl(new MatchedEventMapMeta(new String[0], false));

            _scheduleService = new SchedulingServiceImpl(new TimeSourceServiceImpl());
            PatternAgentInstanceContext agentContext = SupportPatternContextFactory.MakePatternAgentInstanceContext(_scheduleService);

            ScheduleSpec scheduleSpec = new ScheduleSpec();

            scheduleSpec.AddValue(ScheduleUnit.SECONDS, 1);

            _evaluator = new SupportObserverEvaluator(agentContext);

            _observer = new TimerAtObserver(scheduleSpec, _beginState, _evaluator);
        }
예제 #8
0
 public ContextControllerConditionCrontabImpl(
     IntSeqKey conditionPath,
     long scheduleSlot,
     ScheduleSpec scheduleSpec,
     ContextConditionDescriptorCrontab crontab,
     ContextControllerConditionCallback callback,
     ContextController controller)
 {
     this.conditionPath = conditionPath;
     this.scheduleSlot = scheduleSlot;
     Schedule = scheduleSpec;
     this.crontab = crontab;
     this.callback = callback;
     this.controller = controller;
 }
예제 #9
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);
                }
            }
        }
예제 #10
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);
            }
        }
        public static bool DetermineCurrentlyRunning(
            ContextControllerCondition startCondition,
            ContextControllerInitTerm controller)
        {
            if (startCondition.IsImmediate) {
                return true;
            }

            var factory = controller.InitTermFactory;
            var spec = factory.InitTermSpec;
            if (spec.IsOverlapping) {
                return false;
            }

            // we are not currently running if either of the endpoints is not crontab-triggered
            if (spec.StartCondition is ContextConditionDescriptorCrontab &&
                spec.EndCondition is ContextConditionDescriptorCrontab) {
                ScheduleSpec[] schedulesStart = ((ContextControllerConditionCrontab) startCondition).Schedules;

                var endCron = (ContextConditionDescriptorCrontab) spec.EndCondition;
                var schedulesEnd = new ScheduleSpec[endCron.EvaluatorsPerCrontab.Length];
                for (var i = 0; i < schedulesEnd.Length; i++) {
                    schedulesEnd[i] = ScheduleExpressionUtil.CrontabScheduleBuild(
                        endCron.EvaluatorsPerCrontab[i],
                        controller.Realization.AgentInstanceContextCreate);
                }

                var classpathImportService = controller.Realization.AgentInstanceContextCreate.ImportServiceRuntime;
                var time = controller.Realization.AgentInstanceContextCreate.SchedulingService.Time;
                var nextScheduledStartTime = ComputeScheduleMinimumNextOccurance(schedulesStart, time, classpathImportService);
                var nextScheduledEndTime = ComputeScheduleMinimumNextOccurance(schedulesEnd, time, classpathImportService);
                
                return nextScheduledStartTime >= nextScheduledEndTime;
            }

            if (startCondition.Descriptor is ContextConditionDescriptorTimePeriod) {
                var descriptor = (ContextConditionDescriptorTimePeriod) startCondition.Descriptor;
                var endTime = descriptor.GetExpectedEndTime(controller.Realization);
                if (endTime != null && endTime <= 0) {
                    return true;
                }
            }

            return startCondition is ContextConditionDescriptorImmediate;
        }
예제 #12
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);
                }
            }
        }
예제 #13
0
        public OutputCondition Make(AgentInstanceContext agentInstanceContext, OutputCallback outputCallback)
        {
            ScheduleSpec scheduleSpec = ExprNodeUtility.CrontabScheduleBuild(scheduleSpecEvaluators, agentInstanceContext);

            return(new OutputConditionCrontab(outputCallback, agentInstanceContext, isStartConditionOnCreation, scheduleSpec));
        }
예제 #14
0
        public void TestWaitAndSpecTogether()
        {
            var dateTimeEx = DateTimeEx.GetInstance(
                TimeZoneInfo.Utc,
                new DateTime(2004, 12, 9, 15, 27, 10, DateTimeKind.Utc));

            dateTimeEx.SetMillis(500);
            var startTime = dateTimeEx.UtcMillis;

            service.Time = startTime;

            // Add a specification
            var spec = new ScheduleSpec();

            spec.AddValue(ScheduleUnit.MONTHS, 12);
            spec.AddValue(ScheduleUnit.DAYS_OF_MONTH, 9);
            spec.AddValue(ScheduleUnit.HOURS, 15);
            spec.AddValue(ScheduleUnit.MINUTES, 27);
            spec.AddValue(ScheduleUnit.SECONDS, 20);

            service.Add(
                ScheduleComputeHelper.ComputeDeltaNextOccurance(spec, service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE),
                callbacks[3],
                slots[1][1]);

            spec.AddValue(ScheduleUnit.SECONDS, 15);
            service.Add(
                ScheduleComputeHelper.ComputeDeltaNextOccurance(spec, service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE),
                callbacks[4],
                slots[2][0]);

            // Add some more callbacks
            service.Add(5000, callbacks[0], slots[0][0]);
            service.Add(10000, callbacks[1], slots[0][1]);
            service.Add(15000, callbacks[2], slots[1][0]);

            // Now send a times reflecting various seconds later and check who got a callback
            service.Time = startTime + 1000;
            SupportScheduleCallback.SetCallbackOrderNum(0);
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 });

            service.Time = startTime + 2000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 });

            service.Time = startTime + 4000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 });

            service.Time = startTime + 5000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 1, 0, 0, 0, 2 });

            service.Time = startTime + 9000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 });

            service.Time = startTime + 10000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 3, 0, 4, 0 });

            service.Time = startTime + 11000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 });

            service.Time = startTime + 15000;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 5, 0, 0 });

            service.Time = startTime + int.MaxValue;
            EvaluateSchedule();
            CheckCallbacks(callbacks, new[] { 0, 0, 0, 0, 0 });
        }