Search in sources :

Example 6 with SimpleTriggerFactoryBean

use of org.springframework.scheduling.quartz.SimpleTriggerFactoryBean in project netxms by netxms.

the class QuartzReportScheduler method execute.

@Override
public UUID execute(UUID jobId, int userId, UUID reportUuid, Map<String, Object> parameters) {
    if (jobId == null) {
        jobId = UUID.randomUUID();
    }
    log.debug("New job " + jobId + " for report " + reportUuid);
    String groupName = reportUuid.toString();
    JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
    jobDetailFactory.setName(jobId.toString());
    jobDetailFactory.setGroup(groupName);
    jobDetailFactory.setJobClass(GeneratorJob.class);
    jobDetailFactory.afterPropertiesSet();
    JobDetail jobDetail = jobDetailFactory.getObject();
    final JobDataMap dataMap = jobDetail.getJobDataMap();
    dataMap.put("jobId", jobId);
    dataMap.put("reportId", reportUuid);
    dataMap.put("parameters", parameters);
    dataMap.put("userId", userId);
    SimpleTriggerFactoryBean triggerFactoryBean = new SimpleTriggerFactoryBean();
    triggerFactoryBean.setName(jobId.toString() + "_trigger");
    triggerFactoryBean.setGroup(groupName);
    triggerFactoryBean.setJobDetail(jobDetail);
    triggerFactoryBean.setRepeatCount(0);
    triggerFactoryBean.afterPropertiesSet();
    Trigger trigger = triggerFactoryBean.getObject();
    try {
        scheduler.scheduleJob(jobDetail, trigger);
    } catch (SchedulerException e) {
        log.error("Can't schedule job", e);
        jobId = null;
    }
    return jobId;
}
Also used : SimpleTriggerFactoryBean(org.springframework.scheduling.quartz.SimpleTriggerFactoryBean) JobDetailFactoryBean(org.springframework.scheduling.quartz.JobDetailFactoryBean)

Example 7 with SimpleTriggerFactoryBean

use of org.springframework.scheduling.quartz.SimpleTriggerFactoryBean in project tutorials by eugenp.

the class SpringQrtzScheduler method trigger.

@Bean
public SimpleTriggerFactoryBean trigger(JobDetail job) {
    SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
    trigger.setJobDetail(job);
    int frequencyInSec = 10;
    logger.info("Configuring trigger to fire every {} seconds", frequencyInSec);
    trigger.setRepeatInterval(frequencyInSec * 1000);
    trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
    trigger.setName("Qrtz_Trigger");
    return trigger;
}
Also used : SimpleTriggerFactoryBean(org.springframework.scheduling.quartz.SimpleTriggerFactoryBean) JobDetailFactoryBean(org.springframework.scheduling.quartz.JobDetailFactoryBean) SimpleTriggerFactoryBean(org.springframework.scheduling.quartz.SimpleTriggerFactoryBean) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Example 8 with SimpleTriggerFactoryBean

use of org.springframework.scheduling.quartz.SimpleTriggerFactoryBean in project openolat by klemens.

the class SchedulerTest method testSimpleTrigger.

@Test
public void testSimpleTrigger() throws SchedulerException, ParseException {
    JobDetail job = newJob(SchedulerTestJob.class).withIdentity("schedulerTestJobSimpleTrigger", Scheduler.DEFAULT_GROUP).build();
    SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
    trigger.setName("Test scheduler trigger");
    trigger.setStartDelay(0);
    trigger.setRepeatInterval(1000);
    trigger.setRepeatCount(10);
    trigger.setJobDetail(job);
    trigger.afterPropertiesSet();
    // Schedule job now
    scheduler.scheduleJob(job, trigger.getObject());
    // because of cal.add(Calendar.MILLISECOND, 11);
    sleep(20);
    // check number of calls to the job
    org.quartz.Calendar quartzCal = scheduler.getCalendar(trigger.getObject().getCalendarName());
    Calendar cal = Calendar.getInstance();
    Date start = cal.getTime();
    cal.add(Calendar.SECOND, 5);
    cal.add(Calendar.MILLISECOND, 11);
    Date end = cal.getTime();
    Assert.assertEquals(5, TriggerUtils.computeFireTimesBetween((OperableTrigger) trigger.getObject(), quartzCal, start, end).size());
}
Also used : JobDetail(org.quartz.JobDetail) Calendar(java.util.Calendar) SimpleTriggerFactoryBean(org.springframework.scheduling.quartz.SimpleTriggerFactoryBean) Date(java.util.Date) Test(org.junit.Test)

Example 9 with SimpleTriggerFactoryBean

use of org.springframework.scheduling.quartz.SimpleTriggerFactoryBean in project simba-os by cegeka.

the class TriggerConfiguration method createSimpleTrigger.

private SimpleTriggerFactoryBean createSimpleTrigger(JobDetail jobDetail, long repeatIntervalInMillis) {
    SimpleTriggerFactoryBean bean = new SimpleTriggerFactoryBean();
    bean.setJobDetail(jobDetail);
    bean.setGroup(SIMBA_QUARTZ_GROUP);
    bean.setRepeatCount(REPEAT_FOREVER);
    bean.setRepeatInterval(repeatIntervalInMillis);
    return bean;
}
Also used : SimpleTriggerFactoryBean(org.springframework.scheduling.quartz.SimpleTriggerFactoryBean)

Aggregations

SimpleTriggerFactoryBean (org.springframework.scheduling.quartz.SimpleTriggerFactoryBean)9 JobDetailFactoryBean (org.springframework.scheduling.quartz.JobDetailFactoryBean)4 Calendar (java.util.Calendar)3 Date (java.util.Date)3 Test (org.junit.Test)2 JobDetail (org.quartz.JobDetail)2 CronTriggerFactoryBean (org.springframework.scheduling.quartz.CronTriggerFactoryBean)2 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)2 ParseException (java.text.ParseException)1 ExtractPropertyBean (org.akaza.openclinica.bean.extract.ExtractPropertyBean)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 JobDataMap (org.quartz.JobDataMap)1 JobKey (org.quartz.JobKey)1 SchedulerException (org.quartz.SchedulerException)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 MethodInvokingJobDetailFactoryBean (org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1