コード例 #1
0
 /**
  * Overrides {@link Thread#run()}.
  */
 public void Run()
 {
     //outer:
     for (int i = 0; i < collectors.Length; i++)
     {
         TaskTable taskTable = collectors[i].GetTasks();
         int       size      = taskTable.Size();
         for (int j = 0; j < size; j++)
         {
             //if (cThread.isInterrupted()) {
             //    goto outer;
             //}
             SchedulingPattern pattern = taskTable.GetSchedulingPattern(j);
             if (pattern.Match(scheduler.getTimeZone(),
                               referenceTimeInMillis))
             {
                 Task task = taskTable.GetTask(j);
                 scheduler.spawnExecutor(task);
             }
         }
     }
     // Notifies completed.
     scheduler.notifyLauncherCompleted(this);
 }
コード例 #2
0
        /**
         * It returns the next matching moment as a millis value.
         *
         * @return The next matching moment as a millis value.
         */
        public DateTime NextMatchingDate()
        {
            // Go a minute ahead.
            time = time.AddMinutes(1);
            // Is it matching?
            if (schedulingPattern.Match(time))
            {
                return(time);
            }
            // Go through the matcher groups.
            int size = schedulingPattern.matcherSize;

            DateTime[] times = new DateTime[size];
            for (int k = 0; k < size; k++)
            {
                // Ok, split the time!
                DateTime c = time;

                // Gets the matchers.
                IValueMatcher minuteMatcher     = schedulingPattern.minuteMatchers[k];
                IValueMatcher hourMatcher       = schedulingPattern.hourMatchers[k];
                IValueMatcher dayOfMonthMatcher = schedulingPattern.dayOfMonthMatchers[k];
                IValueMatcher dayOfWeekMatcher  = schedulingPattern.dayOfWeekMatchers[k];
                IValueMatcher monthMatcher      = schedulingPattern.monthMatchers[k];
                for (; ;)
                {                 // day of week
                    for (; ;)
                    {             // month
                        for (; ;)
                        {         // day of month
                            for (; ;)
                            {     // hour
                                for (; ;)
                                { // minutes
                                    if (minuteMatcher.Match(c.Minute))
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        c = c.AddMinutes(1);
                                    }
                                }
                                if (hourMatcher.Match(c.Hour))
                                {
                                    break;
                                }
                                else
                                {
                                    c = c.AddHours(1);
                                    c = new DateTime(c.Year, c.Month, c.Day, c.Hour, 0, 0);
                                }
                            }
                            if (dayOfMonthMatcher is DayOfMonthValueMatcher)
                            {
                                DayOfMonthValueMatcher aux = (DayOfMonthValueMatcher)dayOfMonthMatcher;
                                if (aux.Match(c.Day, c.Month, DateTime.IsLeapYear(c.Year)))
                                {
                                    break;
                                }
                                else
                                {
                                    c = c.AddDays(1).Date;
                                }
                            }
                            else if (dayOfMonthMatcher.Match(c.Day))
                            {
                                break;
                            }
                            else
                            {
                                c = c.AddDays(1).Date;
                            }
                        }
                        if (monthMatcher.Match(c.Month))
                        {
                            break;
                        }
                        else
                        {
                            c = c.AddMonths(1);
                            c = new DateTime(c.Year, c.Month, 1);
                        }
                    }
                    // Day of week.
                    int dayOfWeek = (int)c.DayOfWeek;
                    if (dayOfWeekMatcher.Match(dayOfWeek))
                    {
                        break;
                    }
                    else
                    {
                        c = c.AddDays(1).Date;
                    }
                }
                // Seems it matches!
                times[k] = c;
            }
            // Which one?
            DateTime min = DateTime.MaxValue;

            for (int k = 0; k < size; k++)
            {
                if (times[k] < min)
                {
                    min = times[k];
                }
            }
            // Updates the object current time value.
            time = min;
            // Here it is.
            return(time);
        }