@Test public void hourly() { Date now = new Date(); Hourly hourly = scheduleFactory.hourly(now); TriggerBuilder triggerBuilder = underTest.convert(hourly); Trigger trigger = triggerBuilder.build(); assertThat(trigger, instanceOf(SimpleTriggerImpl.class)); assertThat(trigger.getFireTimeAfter(new Date(now.getTime())), equalTo(new Date(now.getTime() + TimeUnit.HOURS.toMillis(1L)))); }
public TriggerBuilder convert(final Schedule schedule) { checkNotNull(schedule); TriggerBuilder triggerBuilder; if (schedule instanceof Cron) { Cron s = (Cron) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(CronScheduleBuilder.cronSchedule(s.getCronExpression()).inTimeZone(s.getTimeZone())); } else if (schedule instanceof Now) { triggerBuilder = newTrigger() .startNow(); } else if (schedule instanceof Once) { Once s = (Once) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()); } else if (schedule instanceof Hourly) { Hourly s = (Hourly) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(1)); } else if (schedule instanceof Daily) { Daily s = (Daily) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24)); } else if (schedule instanceof Weekly) { Weekly s = (Weekly) schedule; String daysToRun = s.getDaysToRun().stream() .map(Weekday.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "? * " + daysToRun)); } else if (schedule instanceof Monthly) { Monthly s = (Monthly) schedule; Set<CalendarDay> daysToRun = s.getDaysToRun(); boolean lastDayOfMonth = daysToRun.remove(CalendarDay.lastDay()); if (!lastDayOfMonth) { String daysToRunStr = daysToRun.stream() .map(CalendarDay.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), daysToRunStr + " * ?")); } else { triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "L * ?")); } } else if (schedule instanceof Manual) { triggerBuilder = newTrigger() .startAt(new Date(Long.MAX_VALUE)); } else { throw new IllegalArgumentException("Schedule unknown: " + schedule.getType()); } for (Map.Entry<String, String> entry : schedule.asMap().entrySet()) { triggerBuilder.usingJobData(entry.getKey(), entry.getValue()); } return triggerBuilder; }
QuartzTriggerConverter extends ComponentSupport { public TriggerBuilder convert(final Schedule schedule) { checkNotNull(schedule); TriggerBuilder triggerBuilder; if (schedule instanceof Cron) { Cron s = (Cron) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(CronScheduleBuilder.cronSchedule(s.getCronExpression()).inTimeZone(s.getTimeZone())); } else if (schedule instanceof Now) { triggerBuilder = newTrigger() .startNow(); } else if (schedule instanceof Once) { Once s = (Once) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()); } else if (schedule instanceof Hourly) { Hourly s = (Hourly) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(1)); } else if (schedule instanceof Daily) { Daily s = (Daily) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24)); } else if (schedule instanceof Weekly) { Weekly s = (Weekly) schedule; String daysToRun = s.getDaysToRun().stream() .map(Weekday.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "? * " + daysToRun)); } else if (schedule instanceof Monthly) { Monthly s = (Monthly) schedule; Set<CalendarDay> daysToRun = s.getDaysToRun(); boolean lastDayOfMonth = daysToRun.remove(CalendarDay.lastDay()); if (!lastDayOfMonth) { String daysToRunStr = daysToRun.stream() .map(CalendarDay.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), daysToRunStr + " * ?")); } else { triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "L * ?")); } } else if (schedule instanceof Manual) { triggerBuilder = newTrigger() .startAt(new Date(Long.MAX_VALUE)); } else { throw new IllegalArgumentException("Schedule unknown: " + schedule.getType()); } for (Map.Entry<String, String> entry : schedule.asMap().entrySet()) { triggerBuilder.usingJobData(entry.getKey(), entry.getValue()); } return triggerBuilder; } }
QuartzTriggerConverter extends ComponentSupport { public TriggerBuilder convert(final Schedule schedule) { checkNotNull(schedule); TriggerBuilder triggerBuilder; if (schedule instanceof Cron) { Cron s = (Cron) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(CronScheduleBuilder.cronSchedule(s.getCronExpression()).inTimeZone(s.getTimeZone())); } else if (schedule instanceof Now) { triggerBuilder = newTrigger() .startNow(); } else if (schedule instanceof Once) { Once s = (Once) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()); } else if (schedule instanceof Hourly) { Hourly s = (Hourly) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(1)); } else if (schedule instanceof Daily) { Daily s = (Daily) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24)); } else if (schedule instanceof Weekly) { Weekly s = (Weekly) schedule; String daysToRun = s.getDaysToRun().stream() .map(Weekday.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "? * " + daysToRun)); } else if (schedule instanceof Monthly) { Monthly s = (Monthly) schedule; Set<CalendarDay> daysToRun = s.getDaysToRun(); boolean lastDayOfMonth = daysToRun.remove(CalendarDay.lastDay()); if (!lastDayOfMonth) { String daysToRunStr = daysToRun.stream() .map(CalendarDay.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), daysToRunStr + " * ?")); } else { triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "L * ?")); } } else if (schedule instanceof Manual) { triggerBuilder = newTrigger() .startAt(new Date(Long.MAX_VALUE)); } else { throw new IllegalArgumentException("Schedule unknown: " + schedule.getType()); } for (Map.Entry<String, String> entry : schedule.asMap().entrySet()) { triggerBuilder.usingJobData(entry.getKey(), entry.getValue()); } return triggerBuilder; } QuartzTriggerConverter(final ScheduleFactory scheduleFactory); }
QuartzTriggerConverter extends ComponentSupport { public TriggerBuilder convert(final Schedule schedule) { checkNotNull(schedule); TriggerBuilder triggerBuilder; if (schedule instanceof Cron) { Cron s = (Cron) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(CronScheduleBuilder.cronSchedule(s.getCronExpression()).inTimeZone(s.getTimeZone())); } else if (schedule instanceof Now) { triggerBuilder = newTrigger() .startNow(); } else if (schedule instanceof Once) { Once s = (Once) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()); } else if (schedule instanceof Hourly) { Hourly s = (Hourly) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(1)); } else if (schedule instanceof Daily) { Daily s = (Daily) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24)); } else if (schedule instanceof Weekly) { Weekly s = (Weekly) schedule; String daysToRun = s.getDaysToRun().stream() .map(Weekday.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "? * " + daysToRun)); } else if (schedule instanceof Monthly) { Monthly s = (Monthly) schedule; Set<CalendarDay> daysToRun = s.getDaysToRun(); boolean lastDayOfMonth = daysToRun.remove(CalendarDay.lastDay()); if (!lastDayOfMonth) { String daysToRunStr = daysToRun.stream() .map(CalendarDay.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), daysToRunStr + " * ?")); } else { triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "L * ?")); } } else if (schedule instanceof Manual) { triggerBuilder = newTrigger() .startAt(new Date(Long.MAX_VALUE)); } else { throw new IllegalArgumentException("Schedule unknown: " + schedule.getType()); } for (Map.Entry<String, String> entry : schedule.asMap().entrySet()) { triggerBuilder.usingJobData(entry.getKey(), entry.getValue()); } return triggerBuilder; } QuartzTriggerConverter(final ScheduleFactory scheduleFactory); TriggerBuilder convert(final Schedule schedule); Schedule convert(final Trigger trigger); }
QuartzTriggerConverter extends ComponentSupport { public TriggerBuilder convert(final Schedule schedule) { checkNotNull(schedule); TriggerBuilder triggerBuilder; if (schedule instanceof Cron) { Cron s = (Cron) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(CronScheduleBuilder.cronSchedule(s.getCronExpression()).inTimeZone(s.getTimeZone())); } else if (schedule instanceof Now) { triggerBuilder = newTrigger() .startNow(); } else if (schedule instanceof Once) { Once s = (Once) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()); } else if (schedule instanceof Hourly) { Hourly s = (Hourly) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(1)); } else if (schedule instanceof Daily) { Daily s = (Daily) schedule; triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24)); } else if (schedule instanceof Weekly) { Weekly s = (Weekly) schedule; String daysToRun = s.getDaysToRun().stream() .map(Weekday.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "? * " + daysToRun)); } else if (schedule instanceof Monthly) { Monthly s = (Monthly) schedule; Set<CalendarDay> daysToRun = s.getDaysToRun(); boolean lastDayOfMonth = daysToRun.remove(CalendarDay.lastDay()); if (!lastDayOfMonth) { String daysToRunStr = daysToRun.stream() .map(CalendarDay.dayToString) .collect(Collectors.joining(",")); triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), daysToRunStr + " * ?")); } else { triggerBuilder = newTrigger() .startAt(s.getStartAt()) .withSchedule(cron(s.getStartAt(), "L * ?")); } } else if (schedule instanceof Manual) { triggerBuilder = newTrigger() .startAt(new Date(Long.MAX_VALUE)); } else { throw new IllegalArgumentException("Schedule unknown: " + schedule.getType()); } for (Map.Entry<String, String> entry : schedule.asMap().entrySet()) { triggerBuilder.usingJobData(entry.getKey(), entry.getValue()); } return triggerBuilder; } QuartzTriggerConverter(final ScheduleFactory scheduleFactory); TriggerBuilder convert(final Schedule schedule); Schedule convert(final Trigger trigger);  }