public SimpleTimer(String name, long interval) { this.trigger = TriggerBuilder.newTrigger() .withIdentity(name) .withSchedule( SimpleScheduleBuilder.simpleSchedule() .withIntervalInMilliseconds(interval) .repeatForever() .withMisfireHandlingInstructionFireNow()) .build(); // .new SimpleTrigger(name, SimpleTrigger.REPEAT_INDEFINITELY, interval); }
public TriggerPropertyBundle loadExtendedTriggerProperties(Connection conn, TriggerKey triggerKey) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(Util.rtp(SELECT_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral)); ps.setString(1, triggerKey.getName()); ps.setString(2, triggerKey.getGroup()); rs = ps.executeQuery(); if (rs.next()) { int repeatCount = rs.getInt(COL_REPEAT_COUNT); long repeatInterval = rs.getLong(COL_REPEAT_INTERVAL); int timesTriggered = rs.getInt(COL_TIMES_TRIGGERED); SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule() .withRepeatCount(repeatCount) .withIntervalInMilliseconds(repeatInterval); String[] statePropertyNames = { "timesTriggered" }; Object[] statePropertyValues = { timesTriggered }; return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues); } throw new IllegalStateException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + Util.rtp(SELECT_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral)); } finally { Util.closeResultSet(rs); Util.closeStatement(ps); } }
public TriggerPropertyBundle loadExtendedTriggerProperties(Connection conn, TriggerKey triggerKey) throws SQLException { PreparedStatement ps = null; ResultSet rs = null; try { ps = conn.prepareStatement(Util.rtp(SELECT_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral)); ps.setString(1, triggerKey.getName()); ps.setString(2, triggerKey.getGroup()); rs = ps.executeQuery(); if (rs.next()) { int repeatCount = rs.getInt(COL_REPEAT_COUNT); long repeatInterval = rs.getLong(COL_REPEAT_INTERVAL); int timesTriggered = rs.getInt(COL_TIMES_TRIGGERED); SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule() .withRepeatCount(repeatCount) .withIntervalInMilliseconds(repeatInterval); String[] statePropertyNames = { "timesTriggered" }; Object[] statePropertyValues = { timesTriggered }; return new TriggerPropertyBundle(sb, statePropertyNames, statePropertyValues); } throw new IllegalStateException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + Util.rtp(SELECT_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral)); } finally { Util.closeResultSet(rs); Util.closeStatement(ps); } }
.withIntervalInMilliseconds(interval[0]); if (interval[2] > 0) { sb = sb.withRepeatCount(interval[2].intValue());
simpleSchedule().repeatForever().withIntervalInMilliseconds(scanInterval)) .forJob(job) .build();
simpleSchedule().repeatForever().withIntervalInMilliseconds(scanInterval)) .forJob(job) .build();
.withIntervalInMilliseconds(repeatInterval) .withRepeatCount(repeatCount);
.withIntervalInMilliseconds(repeatInterval) .withRepeatCount(repeatCount);
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<SimpleTrigger> getScheduleBuilder() { SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule() .withIntervalInMilliseconds(getRepeatInterval()) .withRepeatCount(getRepeatCount()); switch(getMisfireInstruction()) { case MISFIRE_INSTRUCTION_FIRE_NOW : sb.withMisfireHandlingInstructionFireNow(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT : sb.withMisfireHandlingInstructionNextWithExistingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT : sb.withMisfireHandlingInstructionNextWithRemainingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithExistingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithRemainingCount(); break; } return sb; }
/** * Get a {@link ScheduleBuilder} that is configured to produce a * schedule identical to this trigger's schedule. * * @see #getTriggerBuilder() */ @Override public ScheduleBuilder<SimpleTrigger> getScheduleBuilder() { SimpleScheduleBuilder sb = SimpleScheduleBuilder.simpleSchedule() .withIntervalInMilliseconds(getRepeatInterval()) .withRepeatCount(getRepeatCount()); switch(getMisfireInstruction()) { case MISFIRE_INSTRUCTION_FIRE_NOW : sb.withMisfireHandlingInstructionFireNow(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT : sb.withMisfireHandlingInstructionNextWithExistingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT : sb.withMisfireHandlingInstructionNextWithRemainingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithExistingCount(); break; case MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT : sb.withMisfireHandlingInstructionNowWithRemainingCount(); break; } return sb; }
private void addRecurringJob(Class<? extends Job> class1, int intervalMillis) throws SchedulerException { SimpleTrigger trigger = newTrigger().withIdentity("group1", class1.getSimpleName()).withSchedule(simpleSchedule().withIntervalInMilliseconds(intervalMillis).repeatForever()).build(); JobDetail job = newJob(class1).withIdentity("group1", class1.getSimpleName()).build(); sched.scheduleJob(job, trigger); }
private Trigger genTriggerInstance(TriggerKey tk, JobDetail jd, Long interval, Integer repeatCount) { return newTrigger().withIdentity(tk).forJob(jd).startNow() .withSchedule(simpleSchedule().withIntervalInMilliseconds (interval).withRepeatCount(repeatCount)) .build(); }
public static MutableTrigger createSimpleTrigger( TriggerKey triggerKey, int repeatTotalCount, long repeatInterval, Date startTime, Date endTime) { if (startTime == null) startTime = new Date(); // Quartz's SimpleTrigger's repeatCount is one less than repeatTotalCount, so we need to adjust. int repeatCount = repeatTotalCount - 1; if (repeatTotalCount < 0) repeatCount = SimpleTrigger.REPEAT_INDEFINITELY; SimpleTrigger trigger = newTrigger() .withIdentity(triggerKey) .startAt(startTime).endAt(endTime) .withSchedule( simpleSchedule() .withRepeatCount(repeatCount) .withIntervalInMilliseconds(repeatInterval)) .build(); return (MutableTrigger) trigger; }
private ScheduleOptions PERIODIC(final long period, final boolean startImmediate) { if ( period < 1 ) { return new InternalScheduleOptions(new IllegalArgumentException("Period argument must be higher than 0")); } final long ms = period * 1000; final TriggerBuilder<SimpleTrigger> builder = TriggerBuilder.newTrigger() .startAt(new Date(System.currentTimeMillis() + ms)) .withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatForever().withIntervalInMilliseconds(ms)); if ( startImmediate ) { return new InternalScheduleOptions( builder.startNow()); } else { return new InternalScheduleOptions( builder.startAt(new Date(System.currentTimeMillis() + ms)) ); } }
public Trigger getTrigger() throws ParseException { fixParameters(); TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger().forJob(name.trim(), group.trim()).withIdentity(triggerName.trim(), triggerGroup.trim()) .startAt(startTime).endAt(endTime) .usingJobData(JobDataMapUtils.fromDataMapStr(dataMap)); if (repeatCount == -1) { builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatForever() .withIntervalInMilliseconds(intervalInMilliseconds)); } else { builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeatCount) .withIntervalInMilliseconds(intervalInMilliseconds)); } return builder.build(); }
/** * Schedules an event at a specified time with the specified interval. * * @param event event. * @param at time in milliseconds. * @param interval interval in milliseconds. * @return scheduled event entry. */ @Override public EventSchedulerEntry scheduleAt(Event event, long at, long interval) { TriggerBuilder<Trigger> builder = newTrigger(); if (at >= 0) { builder.startAt(new Date(at)); } if (interval > 0) { builder.withSchedule(simpleSchedule().withIntervalInMilliseconds(interval).repeatForever()); } return doSchedule(event, builder.build(), interval == 0); }
@Override public void schedule(final long interval) throws SchedulerException { try { if (scheduler.isShutdown()) throw new IllegalStateException("Scheduler is off"); if (interval < 1) throw new IllegalArgumentException("interval argument should be more then 0"); final TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger(); triggerBuilder.withIdentity("LoaderTrigger", "Scheduler").startNow(); triggerBuilder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(interval).repeatForever()); configureTrigger(triggerBuilder.build()); } catch (final org.quartz.SchedulerException e) { final String message = "schedule(" + interval + ") fail"; LOGGER.error(message, e); throw new SchedulerException(message, e); } }
public Trigger buildTrigger(Scheduled ann) { TriggerBuilder<Trigger> trigger = newTrigger(); if (ann.cron() != null && ann.cron().trim().length() > 0) { trigger.withSchedule(CronScheduleBuilder.cronSchedule(ann.cron()).inTimeZone(config.getTimezone())); } else if (ann.interval() != -1) { trigger.withSchedule(simpleSchedule() .withIntervalInMilliseconds( TimeUnit.MILLISECONDS.convert(ann.interval(), ann.unit())) .repeatForever()) .startAt(new Date(System.currentTimeMillis() + ann.delayInMillis())); } else { throw new IllegalArgumentException("One of 'cron', 'interval' is required for the @Scheduled annotation"); } return trigger.build(); }
/** * Helps to set count and intervals * * @param dto * @param builder */ private static void setCountIntervalValues(TriggerInfo dto, TriggerBuilder<org.quartz.Trigger> builder) { SimpleScheduleBuilder builderSc = SimpleScheduleBuilder.simpleSchedule(); if (dto.getRepeatCount() != 0) builderSc.withRepeatCount(dto.getRepeatCount()); if (dto.getRepeatInterval() > 0) builderSc.withIntervalInMilliseconds(dto.getRepeatInterval()); builder.withSchedule(builderSc); }
public Trigger getTrigger(Trigger trigger) throws ParseException { fixParameters(); TriggerBuilder<Trigger> builder = TriggerBuilder.newTrigger().forJob(trigger.getJobKey().getName(), trigger.getJobKey().getGroup()) .withIdentity(trigger.getKey().getName(), trigger.getKey().getGroup()) .startAt(startTime).endAt(endTime) .usingJobData(JobDataMapUtils.fromDataMapStr(dataMap)); if (repeatCount == -1) { builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().repeatForever() .withIntervalInMilliseconds(intervalInMilliseconds)); } else { builder.withSchedule(SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeatCount) .withIntervalInMilliseconds(intervalInMilliseconds)); } return builder.build(); }