use of org.quartz.SimpleTrigger in project dq-easy-cloud by dq-open-cloud.
the class JDBCJobStoreRunner method run.
public void run(boolean inClearJobs, boolean inScheduleJobs) throws Exception {
// First we must get a reference to a scheduler
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
if (inClearJobs) {
_log.warn("***** Deleting existing jobs/triggers *****");
sched.clear();
}
_log.info("------- Initialization Complete -----------");
if (inScheduleJobs) {
_log.info("------- Scheduling Jobs ------------------");
String schedId = sched.getSchedulerInstanceId();
int count = 2;
JobDetail job = // put triggers in group
newJob(SimpleRecoveryJob.class).withIdentity("job_" + count, schedId).requestRecovery().build();
SimpleTrigger trigger = newTrigger().withIdentity("triger_" + count, schedId).startAt(futureDate(1, IntervalUnit.SECOND)).withSchedule(simpleSchedule().withRepeatCount(20).withIntervalInSeconds(5)).build();
_log.info(job.getKey() + " will run at: " + trigger.getNextFireTime() + " and repeat: " + trigger.getRepeatCount() + " times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
sched.scheduleJob(job, trigger);
count++;
job = // put triggers in group named after
newJob(SimpleRecoveryJob.class).withIdentity("job_" + count, schedId).requestRecovery().build();
trigger = newTrigger().withIdentity("triger_" + count, schedId).startAt(futureDate(2, IntervalUnit.SECOND)).withSchedule(simpleSchedule().withRepeatCount(20).withIntervalInSeconds(5)).build();
_log.info(job.getKey() + " will run at: " + trigger.getNextFireTime() + " and repeat: " + trigger.getRepeatCount() + " times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
sched.scheduleJob(job, trigger);
count++;
job = // put triggers in group named
newJob(SimpleRecoveryStatefulJob.class).withIdentity("job_" + count, schedId).requestRecovery().build();
trigger = newTrigger().withIdentity("triger_" + count, schedId).startAt(futureDate(1, IntervalUnit.SECOND)).withSchedule(simpleSchedule().withRepeatCount(20).withIntervalInSeconds(3)).build();
_log.info(job.getKey() + " will run at: " + trigger.getNextFireTime() + " and repeat: " + trigger.getRepeatCount() + " times, every " + trigger.getRepeatInterval() / 1000 + " seconds");
sched.scheduleJob(job, trigger);
count++;
job = // put triggers in group named after
newJob(SimpleRecoveryJob.class).withIdentity("job_" + count, schedId).requestRecovery().build();
trigger = newTrigger().withIdentity("triger_" + count, schedId).startAt(futureDate(1, IntervalUnit.SECOND)).withSchedule(simpleSchedule().withRepeatCount(20).withIntervalInSeconds(4)).build();
_log.info(job.getKey() + " will run at: " + trigger.getNextFireTime() + " & repeat: " + trigger.getRepeatCount() + "/" + trigger.getRepeatInterval());
sched.scheduleJob(job, trigger);
count++;
job = // put triggers in group named after
newJob(SimpleRecoveryJob.class).withIdentity("job_" + count, schedId).requestRecovery().build();
trigger = newTrigger().withIdentity("triger_" + count, schedId).startAt(futureDate(1, IntervalUnit.SECOND)).withSchedule(simpleSchedule().withRepeatCount(20).withIntervalInMilliseconds(4500L)).build();
_log.info(job.getKey() + " will run at: " + trigger.getNextFireTime() + " & repeat: " + trigger.getRepeatCount() + "/" + trigger.getRepeatInterval());
sched.scheduleJob(job, trigger);
}
// jobs don't start firing until start() has been called...
_log.info("------- Starting Scheduler ---------------");
sched.start();
_log.info("------- Started Scheduler ----------------");
_log.info("------- Waiting for one hour... ----------");
try {
Thread.sleep(3600L * 1000L);
} catch (Exception e) {
//
}
_log.info("------- Shutting Down --------------------");
sched.shutdown();
_log.info("------- Shutdown Complete ----------------");
}
use of org.quartz.SimpleTrigger in project ovirt-engine by oVirt.
the class FixedDelayJobListener method jobWasExecuted.
/**
* reschedule the job with a new trigger. The new trigger will fire within a
* fixed time from the method execution.
*
* @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext,
* JobExecutionException)
*/
@Override
public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
// Get the details of the job:
JobDetail jobdetail = context.getJobDetail();
JobDataMap data = jobdetail.getJobDataMap();
// job and if not just exit:
if (!data.containsKey(SchedulerUtilBaseImpl.FIXED_DELAY_VALUE)) {
return;
}
// This Job might already have an unused trigger in place, use it
List<? extends Trigger> triggersOfJob = null;
try {
triggersOfJob = context.getScheduler().getTriggersOfJob(context.getJobDetail().getKey());
} catch (SchedulerException e) {
// ignore
}
if (triggersOfJob != null && triggersOfJob.stream().filter(t -> t instanceof SimpleTrigger).anyMatch(t -> ((SimpleTrigger) t).getTimesTriggered() == 0)) {
logger.debug("Not scheduling {} again as there is still an unfired trigger.", context.getJobDetail().getKey());
return;
} else {
logger.debug("Rescheduling {} as there is no unfired trigger.", context.getJobDetail().getKey());
}
// generate the new trigger time
String configValueName = data.getString(SchedulerUtilBaseImpl.CONFIGURABLE_DELAY_KEY_NAME);
long delay;
if (StringUtils.isEmpty(configValueName)) {
delay = data.getLongValue(SchedulerUtilBaseImpl.FIXED_DELAY_VALUE);
} else {
ConfigValues configDelay = ConfigValues.valueOf(configValueName);
delay = Config.<Integer>getValue(configDelay).longValue();
}
TimeUnit delayUnit = (TimeUnit) data.getWrappedMap().get(SchedulerUtilBaseImpl.FIXED_DELAY_TIME_UNIT);
Date runTime = SchedulerUtilQuartzImpl.getFutureDate(delay, delayUnit);
// generate the new trigger
Trigger oldTrigger = context.getTrigger();
TriggerKey oldTriggerKey = oldTrigger.getKey();
Trigger newTrigger = newTrigger().withIdentity(oldTriggerKey).startAt(runTime).build();
// schedule the new trigger
sched.rescheduleAJob(oldTriggerKey.getName(), oldTriggerKey.getGroup(), newTrigger);
// SchedulerUtilQuartzImpl.getInstance().rescheduleAJob(oldTriggerName,
// oldTriggerGroup, newTrigger);
}
use of org.quartz.SimpleTrigger in project shiro by apache.
the class QuartzSessionValidationScheduler method enableSessionValidation.
/*--------------------------------------------
| M E T H O D S |
============================================*/
/**
* Starts session validation by creating a Quartz simple trigger, linking it to
* the {@link QuartzSessionValidationJob}, and scheduling it with the Quartz scheduler.
*/
public void enableSessionValidation() {
if (log.isDebugEnabled()) {
log.debug("Scheduling session validation job using Quartz with " + "session validation interval of [" + sessionValidationInterval + "]ms...");
}
try {
SimpleTrigger trigger = new SimpleTrigger(getClass().getName(), Scheduler.DEFAULT_GROUP, SimpleTrigger.REPEAT_INDEFINITELY, sessionValidationInterval);
JobDetail detail = new JobDetail(JOB_NAME, Scheduler.DEFAULT_GROUP, QuartzSessionValidationJob.class);
detail.getJobDataMap().put(QuartzSessionValidationJob.SESSION_MANAGER_KEY, sessionManager);
Scheduler scheduler = getScheduler();
scheduler.scheduleJob(detail, trigger);
if (schedulerImplicitlyCreated) {
scheduler.start();
if (log.isDebugEnabled()) {
log.debug("Successfully started implicitly created Quartz Scheduler instance.");
}
}
this.enabled = true;
if (log.isDebugEnabled()) {
log.debug("Session validation job successfully scheduled with Quartz.");
}
} catch (SchedulerException e) {
if (log.isErrorEnabled()) {
log.error("Error starting the Quartz session validation job. Session validation may not occur.", e);
}
}
}
use of org.quartz.SimpleTrigger in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method createQuartzTriggerSimpleTriggerTest.
@Test
public void createQuartzTriggerSimpleTriggerTest() throws Exception {
final Calendar calendar = Calendar.getInstance();
Date startTime = calendar.getTime();
calendar.add(Calendar.MONTH, 1);
Date endTime = calendar.getTime();
int repeatCount = 5;
long repeatIntervalSeconds = 10;
final SimpleJobTrigger simpleJobTrigger = new SimpleJobTrigger(startTime, endTime, repeatCount, repeatIntervalSeconds);
final Trigger quartzTrigger = QuartzScheduler.createQuartzTrigger(simpleJobTrigger, getJobKey());
assertNotNull(quartzTrigger);
assertTrue(quartzTrigger instanceof SimpleTrigger);
assertEquals(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT, quartzTrigger.getMisfireInstruction());
assertEquals(USER_NAME, quartzTrigger.getGroup());
SimpleTrigger simpleTrigger = (SimpleTrigger) quartzTrigger;
assertEquals(startTime, simpleTrigger.getStartTime());
assertEquals(endTime, simpleTrigger.getEndTime());
assertEquals(repeatCount, simpleTrigger.getRepeatCount());
assertEquals(repeatIntervalSeconds * 1000, simpleTrigger.getRepeatInterval());
}
use of org.quartz.SimpleTrigger in project pentaho-platform by pentaho.
the class QuartzScheduler method triggerNow.
/**
* {@inheritDoc}
*/
public void triggerNow(String jobId) throws SchedulerException {
try {
QuartzJobKey jobKey = QuartzJobKey.parse(jobId);
Scheduler scheduler = getQuartzScheduler();
String groupName = jobKey.getUserName();
for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
if ("MANUAL_TRIGGER".equals(trigger.getGroup())) {
continue;
}
if (trigger instanceof SimpleTrigger) {
((SimpleTrigger) trigger).setPreviousFireTime(new Date());
} else if (trigger instanceof CronTrigger) {
((CronTrigger) trigger).setPreviousFireTime(new Date());
}
// force the trigger to be updated with the previous fire time
scheduler.rescheduleJob(jobId, jobKey.getUserName(), trigger);
}
scheduler.triggerJob(jobId, jobKey.getUserName());
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0007_FAILED_TO_GET_JOB", jobId), // $NON-NLS-1$
e);
}
}
Aggregations