本文整理汇总了Java中org.quartz.SimpleScheduleBuilder.simpleSchedule方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleScheduleBuilder.simpleSchedule方法的具体用法?Java SimpleScheduleBuilder.simpleSchedule怎么用?Java SimpleScheduleBuilder.simpleSchedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.quartz.SimpleScheduleBuilder
的用法示例。
在下文中一共展示了SimpleScheduleBuilder.simpleSchedule方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
@Override
public Trigger convert(Immediate trigger) {
SimpleScheduleBuilder simpleSchedule = SimpleScheduleBuilder.simpleSchedule();
if (trigger.getMisfireInstruction() == Immediate.MisfireInstruction.DROP) {
simpleSchedule = simpleSchedule.withMisfireHandlingInstructionIgnoreMisfires();
} else if (trigger.getMisfireInstruction() == Immediate.MisfireInstruction.FIRE_NOW) {
simpleSchedule = simpleSchedule.withMisfireHandlingInstructionFireNow();
}
return newTrigger()
.withIdentity(trigger.getTriggerKey().getName(), trigger.getTriggerKey().getGroup())
.forJob(trigger.getJobKey().getName(), trigger.getJobKey().getGroup())
.withDescription(trigger.getDescription())
.withSchedule(simpleSchedule)
.usingJobData(new JobDataMap(trigger.getTriggerData()))
.startNow()
.build();
}
示例2: createRepeatingTask
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static TaskBase createRepeatingTask(@Nonnull Class<? extends TaskCallback> commandClass,
long interval, long initialDelay) {
checkCommandClass(commandClass, false);
Class<QuartzCommand> quartzCommand = (Class<QuartzCommand>) commandClass;
JobDetail jobDetail = JobBuilder.newJob(quartzCommand).withIdentity(generateUniqueName(quartzCommand),
QuartzTask.ARTIFACTORY_GROUP).build();
SimpleScheduleBuilder schedulerBuilder = SimpleScheduleBuilder.simpleSchedule();
if (interval > 0) {
schedulerBuilder.repeatForever().withIntervalInMilliseconds(interval);
}
Trigger trigger = TriggerBuilder.newTrigger().forJob(jobDetail)
.withIdentity(generateUniqueName(quartzCommand))
.withSchedule(schedulerBuilder).startAt(new Date(System.currentTimeMillis() + initialDelay)).build();
return fillProperties(QuartzTask.createQuartzTask(commandClass, trigger, jobDetail), false);
}
示例3: buildTrigger
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
protected OperableTrigger buildTrigger(String triggerName,
String triggerGroup,
JobDetail job,
Long startAt,
Long endAt,
ScheduleBuilder scheduleBuilder) {
ScheduleBuilder schedule = scheduleBuilder!=null?scheduleBuilder : SimpleScheduleBuilder.simpleSchedule();
return (OperableTrigger) TriggerBuilder
.newTrigger()
.withIdentity(triggerName, triggerGroup)
.forJob(job)
.startAt(startAt != null ? new Date(startAt) : null)
.endAt(endAt != null ? new Date(endAt) : null)
.withSchedule(schedule)
.build();
}
示例4: addSchedule
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
/**
* 增加一个调度任务
*
* @param name
* 任务名称
* @param job
* 执行内容
* @param intervalInHours
* 间隔小时
* @param intervalInMinutes
* 间隔分钟
* @param intervalInSeconds
* 间隔秒
* @param intervalInMillis
* 间隔毫秒
* @param repeatCount
* 重复次数
* @throws SchedulerException
*/
public Trigger addSchedule(String name, Class<? extends Job> task, int intervalInHours, int intervalInMinutes,
int intervalInSeconds, int intervalInMillis, int repeatCount, JobDataMap param) throws SchedulerException {
Scheduler sched = SF.getScheduler();
JobBuilder builder = JobBuilder.newJob(task);
builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
if (param != null) {
builder.usingJobData(param);
}
SimpleScheduleBuilder simpleSchedule = SimpleScheduleBuilder.simpleSchedule();
if (intervalInHours > 0) {
simpleSchedule.withIntervalInHours(intervalInHours);
}
if (intervalInMinutes > 0) {
simpleSchedule.withIntervalInMinutes(intervalInMinutes);
}
if (intervalInSeconds > 0) {
simpleSchedule.withIntervalInSeconds(intervalInSeconds);
}
if (intervalInMillis > 0) {
simpleSchedule.withIntervalInMilliseconds(intervalInMillis);
}
if (repeatCount >= 0) {
simpleSchedule.withRepeatCount(repeatCount);
} else {
simpleSchedule.repeatForever();
}
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
.withSchedule(simpleSchedule).build();
sched.scheduleJob(builder.build(), trigger);
if (!sched.isShutdown())
sched.start();
return trigger;
}
示例5: start
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
public void start() throws SchedulerException {
JobDetail job = JobBuilder.newJob(ScheduleExecutor.class)
.withIdentity(jobname, "group1")
.requestRecovery()
.usingJobData("configPath", configPath)
.usingJobData("logDirectory", logDirectory)
.build();
// schedule
int timeInterval = 1;
SimpleScheduleBuilder simpleScheduleBuilder = null;
simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
simpleScheduleBuilder.withIntervalInHours(timeInterval * 24).repeatForever();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity(triggername, "group1")
.withSchedule(simpleScheduleBuilder)
.startAt(DateBuilder.dateOf(23, 55, 0))
.forJob(job)
.build();
scheduler = new StdSchedulerFactory(configPath+"config/quartz.properties").getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
}
示例6: testStoreAndRetriveTriggers
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
@Test()
public void testStoreAndRetriveTriggers() throws Exception {
SchedulerSignaler schedSignaler = new SampleSignaler();
ClassLoadHelper loadHelper = new CascadingClassLoadHelper();
loadHelper.initialize();
JobStore store = createJobStore("testStoreAndRetriveTriggers");
store.initialize(loadHelper, schedSignaler);
// Store jobs and triggers.
for (int i = 0; i < 10; i++) {
JobDetail job = JobBuilder.newJob(NoOpJob.class).withIdentity("job" + i)
.build();
store.storeJob(job, true);
SimpleScheduleBuilder schedule = SimpleScheduleBuilder.simpleSchedule();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("job" + i)
.withSchedule(schedule).forJob(job).build();
store.storeTrigger((OperableTrigger) trigger, true);
}
// Retrieve job and trigger.
for (int i = 0; i < 10; i++) {
JobKey jobKey = JobKey.jobKey("job" + i);
JobDetail storedJob = store.retrieveJob(jobKey);
Assert.assertEquals(jobKey, storedJob.getKey());
TriggerKey triggerKey = TriggerKey.triggerKey("job" + i);
Trigger storedTrigger = store.retrieveTrigger(triggerKey);
Assert.assertEquals(triggerKey, storedTrigger.getKey());
}
}
示例7: buildTrigger
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
/**
* @return build Trigger with specified name and group, unattached to a job.
*/
protected Trigger buildTrigger(String triggerName, String groupName) {
SimpleScheduleBuilder schedule = SimpleScheduleBuilder.simpleSchedule();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(triggerName, groupName).withSchedule(schedule).build();
return (Trigger) trigger;
}
示例8: createTrigger
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
protected Trigger createTrigger(JobDataMap data, Date start, int interval,
int repeat, Date end) {
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
if (data != null) {
triggerBuilder.usingJobData(data);
}
if (interval > 0) {
SimpleScheduleBuilder schedule = SimpleScheduleBuilder
.simpleSchedule();
schedule.withIntervalInMilliseconds(interval).withRepeatCount(
repeat);
triggerBuilder.withSchedule(schedule);
}
if (start != null) {
triggerBuilder.startAt(start);
} else {
triggerBuilder.startNow();
}
if (end != null) {
triggerBuilder.endAt(end);
}
return triggerBuilder.build();
}
示例9: setTriggerParam
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
/**
* 设置trigger
*
* @param job
* @param triggerKey
* @param trigger
* @param triggerBuilder
*/
public Trigger setTriggerParam(ScheduleJob job, TriggerKey triggerKey, TriggerBuilder triggerBuilder,
Trigger trigger) {
if (job.getTriggerType().equals("CronTrigger")) {
CronScheduleBuilder cronBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式构建一个新的trigger
if (job.getStartTime() != null)
triggerBuilder.startAt(job.getStartTime());
if (job.getEndTime() != null)
triggerBuilder.endAt(job.getEndTime());
//int index=job.getDesc().indexOf(";repeatType:")>-1?job.getDesc().indexOf(";repeatType:"):job.getDesc().length();
trigger = triggerBuilder.withIdentity(triggerKey).withSchedule(cronBuilder).withDescription(
job.getDesc()).build();
} else if (job.getTriggerType().equals("SimpleTrigger")) {
SimpleScheduleBuilder simpleBuilder = SimpleScheduleBuilder.simpleSchedule();
if (job.getStartTime() != null)
triggerBuilder.startAt(job.getStartTime());
if (job.getEndTime() != null)
triggerBuilder.endAt(job.getEndTime());
if (StrUtil.isNotBlank(job.getRepeatType())) {
if (job.getRepeatType().equals("repeatForever")) {
simpleBuilder=simpleBuilderForever(simpleBuilder,job);
}
else if (job.getRepeatType().equals("repeatHourlyForever")) {
if (job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatHourlyForever(job.getRepeatInterval());
else
simpleBuilder = simpleBuilder.repeatHourlyForever();
} else if (job.getRepeatType().equals("repeatMinutelyForever")) {
if (job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatMinutelyForever(job.getRepeatInterval());
else
simpleBuilder = simpleBuilder.repeatMinutelyForever();
} else if (job.getRepeatType().equals("repeatSecondlyForever")) {
if (job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatSecondlyForever(job.getRepeatInterval());
else
simpleBuilder = simpleBuilder.repeatSecondlyForever();
} else if (job.getRepeatType().equals("repeatHourlyForTotalCount")) {
if (job.getRepeatCount() != null && job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatHourlyForTotalCount(job.getRepeatCount(), job
.getRepeatInterval());
else if (job.getRepeatCount() != null)
simpleBuilder = simpleBuilder.repeatHourlyForTotalCount(job.getRepeatCount());
} else if (job.getRepeatType().equals("repeatMinutelyForTotalCount")) {
if (job.getRepeatCount() != null && job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatMinutelyForTotalCount(job.getRepeatCount(), job
.getRepeatInterval());
else if (job.getRepeatCount() != null)
simpleBuilder = simpleBuilder.repeatMinutelyForTotalCount(job.getRepeatCount());
} else if (job.getRepeatType().equals("repeatSecondlyForTotalCount")) {
if (job.getRepeatCount() != null && job.getRepeatInterval() != null)
simpleBuilder = simpleBuilder.repeatSecondlyForTotalCount(job.getRepeatCount(), job
.getRepeatInterval());
else if (job.getRepeatCount() != null)
simpleBuilder = simpleBuilder.repeatSecondlyForTotalCount(job.getRepeatCount());
}
}
if(StrUtil.isEmpty(job.getDesc()))
job.setDesc("");
int index=job.getDesc().indexOf(";repeatType:")>-1?job.getDesc().indexOf(";repeatType:"):job.getDesc().length();
trigger = triggerBuilder.withIdentity(triggerKey).withSchedule(simpleBuilder).withDescription(
job.getDesc().substring(0,index) + ";repeatType:" + job.getRepeatType()).build();
/*trigger = triggerBuilder.withIdentity(triggerKey).withSchedule(simpleBuilder).withDescription(
job.getDesc()).build();*/
}
return trigger;
}
示例10: testMatchers
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
@Test
public void testMatchers() throws Exception {
JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("job1", "aaabbbccc").build();
jobStore.storeJob(job, true);
SimpleScheduleBuilder schedule = SimpleScheduleBuilder.simpleSchedule();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trig1", "aaabbbccc").withSchedule(schedule).forJob(job)
.build();
jobStore.storeTrigger((OperableTrigger) trigger, true);
job = JobBuilder.newJob(MyJob.class).withIdentity("job1", "xxxyyyzzz").build();
jobStore.storeJob(job, true);
schedule = SimpleScheduleBuilder.simpleSchedule();
trigger = TriggerBuilder.newTrigger().withIdentity("trig1", "xxxyyyzzz").withSchedule(schedule).forJob(job).build();
jobStore.storeTrigger((OperableTrigger) trigger, true);
job = JobBuilder.newJob(MyJob.class).withIdentity("job2", "xxxyyyzzz").build();
jobStore.storeJob(job, true);
schedule = SimpleScheduleBuilder.simpleSchedule();
trigger = TriggerBuilder.newTrigger().withIdentity("trig2", "xxxyyyzzz").withSchedule(schedule).forJob(job).build();
jobStore.storeTrigger((OperableTrigger) trigger, true);
Set<JobKey> jkeys = jobStore.getJobKeys(GroupMatcher.anyJobGroup());
assertEquals("Wrong number of jobs found by anything matcher", 3, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupEquals("xxxyyyzzz"));
assertEquals("Wrong number of jobs found by equals matcher", 2, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupEquals("aaabbbccc"));
assertEquals("Wrong number of jobs found by equals matcher", 1, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupStartsWith("aa"));
assertEquals("Wrong number of jobs found by starts with matcher", 1, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupStartsWith("xx"));
assertEquals("Wrong number of jobs found by starts with matcher", 2, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupEndsWith("cc"));
assertEquals("Wrong number of jobs found by ends with matcher", 1, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupEndsWith("zzz"));
assertEquals("Wrong number of jobs found by ends with matcher", 2, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupContains("bc"));
assertEquals("Wrong number of jobs found by contains with matcher", 1, jkeys.size());
jkeys = jobStore.getJobKeys(GroupMatcher.jobGroupContains("yz"));
assertEquals("Wrong number of jobs found by contains with matcher", 2, jkeys.size());
Set<TriggerKey> tkeys = jobStore.getTriggerKeys(GroupMatcher.anyTriggerGroup());
assertEquals("Wrong number of triggers found by anything matcher", 3, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupEquals("xxxyyyzzz"));
assertEquals("Wrong number of triggers found by equals matcher", 2, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupEquals("aaabbbccc"));
assertEquals("Wrong number of triggers found by equals matcher", 1, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupStartsWith("aa"));
assertEquals("Wrong number of triggers found by starts with matcher", 1, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupStartsWith("xx"));
assertEquals("Wrong number of triggers found by starts with matcher", 2, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupEndsWith("cc"));
assertEquals("Wrong number of triggers found by ends with matcher", 1, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupEndsWith("zzz"));
assertEquals("Wrong number of triggers found by ends with matcher", 2, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupContains("bc"));
assertEquals("Wrong number of triggers found by contains with matcher", 1, tkeys.size());
tkeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupContains("yz"));
assertEquals("Wrong number of triggers found by contains with matcher", 2, tkeys.size());
}
示例11: buildTrigger
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
private Trigger buildTrigger(String name, String group, ScheduleRule scheduleRule) {
Trigger trigger;
Parameters triggerParameters = scheduleRule.getTriggerParameters();
Integer triggerStartDelaySeconds = triggerParameters.getInt(TriggerParameters.startDelaySeconds);
int intTriggerStartDelaySeconds = (triggerStartDelaySeconds != null) ? triggerStartDelaySeconds : 0;
Date firstFireTime;
if (startDelaySeconds > 0 || (triggerStartDelaySeconds != null && triggerStartDelaySeconds > 0)) {
firstFireTime = new Date(System.currentTimeMillis() + ((startDelaySeconds + intTriggerStartDelaySeconds) * 1000L));
} else {
firstFireTime = new Date();
}
if (scheduleRule.getTriggerType() == TriggerType.SIMPLE) {
Long intervalInMilliseconds = triggerParameters.getLong(TriggerParameters.intervalInMilliseconds);
Integer intervalInSeconds = triggerParameters.getInt(TriggerParameters.intervalInSeconds);
Integer intervalInMinutes = triggerParameters.getInt(TriggerParameters.intervalInMinutes);
Integer intervalInHours = triggerParameters.getInt(TriggerParameters.intervalInHours);
Integer repeatCount = triggerParameters.getInt(TriggerParameters.repeatCount);
Boolean repeatForever = triggerParameters.getBoolean(TriggerParameters.repeatForever);
SimpleScheduleBuilder builder = SimpleScheduleBuilder.simpleSchedule();
if (intervalInMilliseconds != null) {
builder.withIntervalInMilliseconds(intervalInMilliseconds);
}
if (intervalInMinutes != null) {
builder.withIntervalInMinutes(intervalInMinutes);
}
if (intervalInSeconds != null) {
builder.withIntervalInSeconds(intervalInSeconds);
}
if (intervalInHours != null) {
builder.withIntervalInHours(intervalInHours);
}
if (repeatCount != null) {
builder.withRepeatCount(repeatCount);
}
if (Boolean.TRUE.equals(repeatForever)) {
builder.repeatForever();
}
trigger = TriggerBuilder.newTrigger()
.withIdentity(name, group)
.startAt(firstFireTime)
.withSchedule(builder)
.build();
} else {
String expression = triggerParameters.getString(TriggerParameters.expression);
CronScheduleBuilder cronSchedule = CronScheduleBuilder.cronSchedule(expression);
trigger = TriggerBuilder.newTrigger()
.withIdentity(name, group)
.startAt(firstFireTime)
.withSchedule(cronSchedule)
.build();
}
return trigger;
}
示例12: configureTriggerJob
import org.quartz.SimpleScheduleBuilder; //导入方法依赖的package包/类
private Trigger configureTriggerJob(String jobName, String jobGroup, Job job) {
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
// base trigger configuration
triggerBuilder.withIdentity(jobName, jobGroup);
if (job.getStartTime() != null)
triggerBuilder.startAt(job.getStartTime());
else {
if (job.getActive())
triggerBuilder.startNow();
}
if (job.getEndTime() != null)
triggerBuilder.endAt(job.getEndTime());
triggerBuilder.withPriority(job.getJobTriggerPriority());
// propietary trigger configuration
if (job.getJobTriggerType().getCode().equals(Job.JOB_TRIGGER_TYPE.SIMPLE.name())) {
SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule();
if (job.getJobInterval() != null) {
if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.SECOND.name()))
simpleScheduleBuilder.withIntervalInSeconds(job.getJobInterval());
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.MINUTE.name()))
simpleScheduleBuilder.withIntervalInMinutes(job.getJobInterval());
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.HOUR.name()))
simpleScheduleBuilder.withIntervalInHours(job.getJobInterval());
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.DAY.name()))
simpleScheduleBuilder.withIntervalInHours(job.getJobInterval() * 24);
else if (job.getJobIntervalType().getCode().equals(Job.JOB_INTERVAL_TYPE.WEEK.name()))
simpleScheduleBuilder.withIntervalInHours(job.getJobInterval() * 24 * 7);
}
if (job.getRepeatCount() != null)
simpleScheduleBuilder.withRepeatCount(job.getRepeatCount());
else
simpleScheduleBuilder.repeatForever();
triggerBuilder.withSchedule(simpleScheduleBuilder);
}
else if (job.getJobTriggerType().getCode().equals(Job.JOB_TRIGGER_TYPE.CRON.name())) {
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
triggerBuilder.withSchedule(cronScheduleBuilder);
}
return triggerBuilder.build();
}