Ejemplo n.º 1
0
        public static ContextPartitionIdentifierInitiatedTerminated KeyToIdentifier(
            int subpathIdOrCPId,
            ContextControllerInitTermPartitionKey key,
            ContextControllerInitTerm controller)
        {
            var identifier = new ContextPartitionIdentifierInitiatedTerminated();
            identifier.StartTime = key.StartTime;
            identifier.EndTime = key.ExpectedEndTime;

            var start = controller.InitTermFactory.InitTermSpec.StartCondition;
            if (start is ContextConditionDescriptorFilter) {
                var filter = (ContextConditionDescriptorFilter) start;
                if (filter.OptionalFilterAsName != null) {
                    identifier.Properties = Collections.SingletonDataMap(
                        filter.OptionalFilterAsName,
                        key.TriggeringEvent);
                }
            }

            if (controller.Factory.FactoryEnv.IsLeaf) {
                identifier.ContextPartitionId = subpathIdOrCPId;
            }

            return identifier;
        }
 public static ContextControllerInitTermPartitionKey BuildPartitionKey(
     EventBean optionalTriggeringEvent,
     IDictionary<string, object> optionalTriggeringPattern,
     ContextControllerCondition endCondition,
     ContextControllerInitTerm controller)
 {
     var startTime = controller.realization.AgentInstanceContextCreate.SchedulingService.Time;
     var expectedEndTime = endCondition.ExpectedEndTime;
     return new ContextControllerInitTermPartitionKey(
         optionalTriggeringEvent,
         optionalTriggeringPattern,
         startTime,
         expectedEndTime);
 }
Ejemplo n.º 3
0
        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) {
                var scheduleStart = ((ContextControllerConditionCrontab) startCondition).Schedule;

                var endCron = (ContextConditionDescriptorCrontab) spec.EndCondition;
                var scheduleEnd = ScheduleExpressionUtil.CrontabScheduleBuild(
                    endCron.Evaluators,
                    controller.Realization.AgentInstanceContextCreate);

                var importService = controller.Realization.AgentInstanceContextCreate.ImportServiceRuntime;
                var time = controller.Realization.AgentInstanceContextCreate.SchedulingService.Time;
                var nextScheduledStartTime = ScheduleComputeHelper.ComputeNextOccurance(
                    scheduleStart,
                    time,
                    importService.TimeZone,
                    importService.TimeAbacus);
                var nextScheduledEndTime = ScheduleComputeHelper.ComputeNextOccurance(
                    scheduleEnd,
                    time,
                    importService.TimeZone,
                    importService.TimeAbacus);
                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;
        }
        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;
        }