Search in sources :

Example 66 with SimpleTrigger

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 ----------------");
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) JobDetail(org.quartz.JobDetail) SimpleRecoveryJob(com.easy.cloud.core.worker.examples.example15.SimpleRecoveryJob) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 67 with SimpleTrigger

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);
}
Also used : JobExecutionContext(org.quartz.JobExecutionContext) StringUtils(org.apache.commons.lang.StringUtils) Logger(org.slf4j.Logger) Date(java.util.Date) JobListener(org.quartz.JobListener) LoggerFactory(org.slf4j.LoggerFactory) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) TimeUnit(java.util.concurrent.TimeUnit) JobExecutionException(org.quartz.JobExecutionException) List(java.util.List) SchedulerException(org.quartz.SchedulerException) JobDataMap(org.quartz.JobDataMap) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TriggerKey(org.quartz.TriggerKey) Config(org.ovirt.engine.core.common.config.Config) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Date(java.util.Date) TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) TimeUnit(java.util.concurrent.TimeUnit) SimpleTrigger(org.quartz.SimpleTrigger)

Example 68 with SimpleTrigger

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);
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) SessionValidationScheduler(org.apache.shiro.session.mgt.SessionValidationScheduler) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 69 with SimpleTrigger

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());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(java.util.Calendar) SimpleTrigger(org.quartz.SimpleTrigger) Date(java.util.Date) Test(org.junit.Test)

Example 70 with SimpleTrigger

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);
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Scheduler(org.quartz.Scheduler) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) SimpleTrigger(org.quartz.SimpleTrigger) Date(java.util.Date)

Aggregations

SimpleTrigger (org.quartz.SimpleTrigger)75 CronTrigger (org.quartz.CronTrigger)27 SchedulerException (org.quartz.SchedulerException)27 JobDetail (org.quartz.JobDetail)24 Date (java.util.Date)22 Scheduler (org.quartz.Scheduler)21 Trigger (org.quartz.Trigger)20 Test (org.junit.Test)11 JobDataMap (org.quartz.JobDataMap)11 ArrayList (java.util.ArrayList)9 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 SimpleDateFormat (java.text.SimpleDateFormat)5 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)5 DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)5 TriggerKey (org.quartz.TriggerKey)5 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)4 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)4