下面列出了org.quartz.impl.triggers.SimpleTriggerImpl#setRepeatInterval ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 设置触发器
*/
private void initSimpleTrigger() {
if (this.fixedRate <= 0 || this.delay < 0) {
return;
}
SimpleTriggerImpl simpleTrigger = new SimpleTriggerImpl();
simpleTrigger.setRepeatInterval(this.fixedRate);
this.tip = "fixedRate: " + this.fixedRate + " ms delay: " + this.delay + " ms";
// 无限次
simpleTrigger.setRepeatCount(-1);
simpleTrigger.setStartTime(new Date(System.currentTimeMillis() + this.delay));
this.trigger = simpleTrigger;
this.cron = "";
}
@Override
public void afterPropertiesSet() {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.jobDetail != null) {
this.jobDataMap.put("jobDetail", this.jobDetail);
}
if (this.startDelay > 0 || this.startTime == null) {
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
}
SimpleTriggerImpl sti = new SimpleTriggerImpl();
sti.setName(this.name != null ? this.name : toString());
sti.setGroup(this.group);
if (this.jobDetail != null) {
sti.setJobKey(this.jobDetail.getKey());
}
sti.setJobDataMap(this.jobDataMap);
sti.setStartTime(this.startTime);
sti.setRepeatInterval(this.repeatInterval);
sti.setRepeatCount(this.repeatCount);
sti.setPriority(this.priority);
sti.setMisfireInstruction(this.misfireInstruction);
sti.setDescription(this.description);
this.simpleTrigger = sti;
}
@Override
public void afterPropertiesSet() {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.jobDetail != null) {
this.jobDataMap.put("jobDetail", this.jobDetail);
}
if (this.startDelay > 0 || this.startTime == null) {
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
}
SimpleTriggerImpl sti = new SimpleTriggerImpl();
sti.setName(this.name != null ? this.name : toString());
sti.setGroup(this.group);
if (this.jobDetail != null) {
sti.setJobKey(this.jobDetail.getKey());
}
sti.setJobDataMap(this.jobDataMap);
sti.setStartTime(this.startTime);
sti.setRepeatInterval(this.repeatInterval);
sti.setRepeatCount(this.repeatCount);
sti.setPriority(this.priority);
sti.setMisfireInstruction(this.misfireInstruction);
sti.setDescription(this.description);
this.simpleTrigger = sti;
}
@Override
public void afterPropertiesSet() {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.jobDetail != null) {
this.jobDataMap.put("jobDetail", this.jobDetail);
}
if (this.startDelay > 0 || this.startTime == null) {
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
}
SimpleTriggerImpl sti = new SimpleTriggerImpl();
sti.setName(this.name);
sti.setGroup(this.group);
if (this.jobDetail != null) {
sti.setJobKey(this.jobDetail.getKey());
}
sti.setJobDataMap(this.jobDataMap);
sti.setStartTime(this.startTime);
sti.setRepeatInterval(this.repeatInterval);
sti.setRepeatCount(this.repeatCount);
sti.setPriority(this.priority);
sti.setMisfireInstruction(this.misfireInstruction);
sti.setDescription(this.description);
this.simpleTrigger = sti;
}
/**
* Build the actual Trigger -- NOT intended to be invoked by end users,
* but will rather be invoked by a TriggerBuilder which this
* ScheduleBuilder is given to.
*
* @see TriggerBuilder#withSchedule(ScheduleBuilder)
*/
@Override
public MutableTrigger build() {
SimpleTriggerImpl st = new SimpleTriggerImpl();
st.setRepeatInterval(interval);
st.setRepeatCount(repeatCount);
st.setMisfireInstruction(misfireInstruction);
return st;
}
public static OperableTrigger newTrigger(CompositeData cData) throws ParseException {
SimpleTriggerImpl result = new SimpleTriggerImpl();
result.setRepeatCount(((Integer) cData.get("repeatCount")).intValue());
result.setRepeatInterval(((Long) cData.get("repeatInterval")).longValue());
result.setTimesTriggered(((Integer) cData.get("timesTriggered")).intValue());
TriggerSupport.initializeTrigger(result, cData);
return result;
}
public static OperableTrigger newTrigger(Map<String, Object> attrMap) throws ParseException {
SimpleTriggerImpl result = new SimpleTriggerImpl();
if(attrMap.containsKey("repeatCount")) {
result.setRepeatCount(((Integer) attrMap.get("repeatCount")).intValue());
}
if(attrMap.containsKey("repeatInterval")) {
result.setRepeatInterval(((Long) attrMap.get("repeatInterval")).longValue());
}
if(attrMap.containsKey("timesTriggered")) {
result.setTimesTriggered(((Integer) attrMap.get("timesTriggered")).intValue());
}
TriggerSupport.initializeTrigger(result, attrMap);
return result;
}
@Override
public void afterPropertiesSet() {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.jobDetail != null) {
this.jobDataMap.put("jobDetail", this.jobDetail);
}
if (this.startDelay > 0 || this.startTime == null) {
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
}
SimpleTriggerImpl sti = new SimpleTriggerImpl();
sti.setName(this.name);
sti.setGroup(this.group);
sti.setJobKey(this.jobDetail.getKey());
sti.setJobDataMap(this.jobDataMap);
sti.setStartTime(this.startTime);
sti.setRepeatInterval(this.repeatInterval);
sti.setRepeatCount(this.repeatCount);
sti.setPriority(this.priority);
sti.setMisfireInstruction(this.misfireInstruction);
sti.setDescription(this.description);
this.simpleTrigger = sti;
}
private OperableTrigger toOperableTrigger(TriggerKey triggerKey, Map<String, String> trigger) {
if (TRIGGER_TYPE_SIMPLE.equals(trigger.get(TRIGGER_TYPE))) {
SimpleTriggerImpl simpleTrigger = new SimpleTriggerImpl();
setOperableTriggerFields(triggerKey, trigger, simpleTrigger);
if (trigger.get(REPEAT_COUNT) != null && !trigger.get(REPEAT_COUNT).isEmpty())
simpleTrigger.setRepeatCount(Integer.parseInt(trigger.get(REPEAT_COUNT)));
if (trigger.get(REPEAT_INTERVAL) != null && !trigger.get(REPEAT_INTERVAL).isEmpty())
simpleTrigger.setRepeatInterval(Long.parseLong(trigger.get(REPEAT_INTERVAL)));
if (trigger.get(TIMES_TRIGGERED) != null && !trigger.get(TIMES_TRIGGERED).isEmpty())
simpleTrigger.setTimesTriggered(Integer.parseInt(trigger.get(TIMES_TRIGGERED)));
return simpleTrigger;
} else if (TRIGGER_TYPE_CRON.equals(trigger.get(TRIGGER_TYPE))) {
CronTriggerImpl cronTrigger = new CronTriggerImpl();
setOperableTriggerFields(triggerKey, trigger, cronTrigger);
if (trigger.get(TIME_ZONE_ID) != null && !trigger.get(TIME_ZONE_ID).isEmpty())
cronTrigger.getTimeZone().setID(trigger.get(TIME_ZONE_ID).isEmpty() ? null : trigger.get(TIME_ZONE_ID));
try {
if (trigger.get(CRON_EXPRESSION) != null && !trigger.get(CRON_EXPRESSION).isEmpty())
cronTrigger.setCronExpression(trigger.get(CRON_EXPRESSION).isEmpty() ? null : trigger.get(CRON_EXPRESSION));
} catch (ParseException ex) {
log.warn("could not parse cron_expression: " + trigger.get(CRON_EXPRESSION) + " for trigger: " + createTriggerHashKey(triggerKey.getGroup(), triggerKey.getName()));
}
return cronTrigger;
} else { // other trigger types are not supported
throw new UnsupportedOperationException();
}
}