Search in sources :

Example 6 with JobDetailImpl

use of org.quartz.impl.JobDetailImpl in project spring-framework by spring-projects.

the class JobDetailFactoryBean method afterPropertiesSet.

@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() {
    if (this.name == null) {
        this.name = this.beanName;
    }
    if (this.group == null) {
        this.group = Scheduler.DEFAULT_GROUP;
    }
    if (this.applicationContextJobDataKey != null) {
        if (this.applicationContext == null) {
            throw new IllegalStateException("JobDetailBean needs to be set up in an ApplicationContext " + "to be able to handle an 'applicationContextJobDataKey'");
        }
        getJobDataMap().put(this.applicationContextJobDataKey, this.applicationContext);
    }
    JobDetailImpl jdi = new JobDetailImpl();
    jdi.setName(this.name);
    jdi.setGroup(this.group);
    jdi.setJobClass((Class) this.jobClass);
    jdi.setJobDataMap(this.jobDataMap);
    jdi.setDurability(this.durability);
    jdi.setRequestsRecovery(this.requestsRecovery);
    jdi.setDescription(this.description);
    this.jobDetail = jdi;
}
Also used : JobDetailImpl(org.quartz.impl.JobDetailImpl)

Example 7 with JobDetailImpl

use of org.quartz.impl.JobDetailImpl in project opennms by OpenNMS.

the class ImportSchedulerIT method createJobAndVerifyImportJobFactoryIsRegistered.

@Test
public void createJobAndVerifyImportJobFactoryIsRegistered() throws SchedulerException, InterruptedException {
    RequisitionDef def = m_dao.getDefs().get(0);
    JobDetail detail = new JobDetailImpl("test", ImportScheduler.JOB_GROUP, ImportJob.class, false, false);
    detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource());
    detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
    class MyBoolWrapper {

        volatile Boolean m_called = false;

        public Boolean getCalled() {
            return m_called;
        }

        public void setCalled(Boolean called) {
            m_called = called;
        }
    }
    final MyBoolWrapper callTracker = new MyBoolWrapper();
    m_importScheduler.getScheduler().getListenerManager().addTriggerListener(new TriggerListener() {

        @Override
        public String getName() {
            return "TestTriggerListener";
        }

        @Override
        public void triggerComplete(Trigger trigger, JobExecutionContext context, Trigger.CompletedExecutionInstruction triggerInstructionCode) {
            LOG.info("triggerComplete called on trigger listener");
            callTracker.setCalled(true);
        }

        @Override
        public void triggerFired(Trigger trigger, JobExecutionContext context) {
            LOG.info("triggerFired called on trigger listener");
            Job jobInstance = context.getJobInstance();
            if (jobInstance instanceof ImportJob) {
                Assert.assertNotNull(((ImportJob) jobInstance).getProvisioner());
                Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.URL));
                Assert.assertEquals("dns://localhost/localhost", context.getJobDetail().getJobDataMap().get(ImportJob.URL));
                Assert.assertTrue(context.getJobDetail().getJobDataMap().containsKey(ImportJob.RESCAN_EXISTING));
                Assert.assertEquals("dbonly", context.getJobDetail().getJobDataMap().get(ImportJob.RESCAN_EXISTING));
            }
            callTracker.setCalled(true);
        }

        @Override
        public void triggerMisfired(Trigger trigger) {
            LOG.info("triggerMisFired called on trigger listener");
            callTracker.setCalled(true);
        }

        @Override
        public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
            LOG.info("vetoJobExecution called on trigger listener");
            callTracker.setCalled(true);
            return false;
        }
    });
    Calendar testCal = Calendar.getInstance();
    testCal.add(Calendar.SECOND, 5);
    SimpleTriggerImpl trigger = new SimpleTriggerImpl("test", ImportScheduler.JOB_GROUP, testCal.getTime());
    m_importScheduler.getScheduler().scheduleJob(detail, trigger);
    m_importScheduler.start();
    int callCheck = 0;
    while (!callTracker.getCalled() && callCheck++ < 2) {
        Thread.sleep(5000);
    }
//TODO: need to fix the interrupted exception that occurs in the provisioner
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) Calendar(java.util.Calendar) TriggerListener(org.quartz.TriggerListener) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) JobDetailImpl(org.quartz.impl.JobDetailImpl) JobExecutionContext(org.quartz.JobExecutionContext) RequisitionDef(org.opennms.netmgt.config.provisiond.RequisitionDef) Job(org.quartz.Job) Test(org.junit.Test)

Example 8 with JobDetailImpl

use of org.quartz.impl.JobDetailImpl in project opennms by OpenNMS.

the class ReportScheduler method buildReportSchedule.

private void buildReportSchedule() {
    synchronized (m_lock) {
        for (Report report : m_configDao.getReports()) {
            JobDetail detail = null;
            CronTriggerImpl trigger = null;
            try {
                detail = new JobDetailImpl(report.getReportName(), JOB_GROUP, ReportJob.class, false, false);
                detail.getJobDataMap().put(ReportJob.KEY, report);
                trigger = new CronTriggerImpl(report.getReportName(), JOB_GROUP, report.getCronSchedule());
                trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
                getScheduler().scheduleJob(detail, trigger);
            } catch (ParseException e) {
                LOG.error("buildReportSchedule: {}", e.getMessage(), e);
            } catch (SchedulerException e) {
                LOG.error("buildReportSchedule: {}", e.getMessage(), e);
            }
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Report(org.opennms.netmgt.config.reportd.Report) JobDetailImpl(org.quartz.impl.JobDetailImpl) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException)

Example 9 with JobDetailImpl

use of org.quartz.impl.JobDetailImpl in project engine by craftercms.

the class ConfigurationScriptJobResolverTest method testResolveJobs.

@Test
public void testResolveJobs() throws Exception {
    List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
    assertNotNull(jobContexts);
    assertEquals(2, jobContexts.size());
    JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
    CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/morejobs/testJob2.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
    jobDetail = (JobDetailImpl) jobContexts.get(1).getDetail();
    trigger = (CronTrigger) jobContexts.get(1).getTrigger();
    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetailImpl(org.quartz.impl.JobDetailImpl) JobContext(org.craftercms.engine.util.quartz.JobContext) Test(org.junit.Test)

Example 10 with JobDetailImpl

use of org.quartz.impl.JobDetailImpl in project spring-framework by spring-projects.

the class MethodInvokingJobDetailFactoryBean method afterPropertiesSet.

@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws ClassNotFoundException, NoSuchMethodException {
    prepare();
    // Use specific name if given, else fall back to bean name.
    String name = (this.name != null ? this.name : this.beanName);
    // Consider the concurrent flag to choose between stateful and stateless job.
    Class<?> jobClass = (this.concurrent ? MethodInvokingJob.class : StatefulMethodInvokingJob.class);
    // Build JobDetail instance.
    JobDetailImpl jdi = new JobDetailImpl();
    jdi.setName(name);
    jdi.setGroup(this.group);
    jdi.setJobClass((Class) jobClass);
    jdi.setDurability(true);
    jdi.getJobDataMap().put("methodInvoker", this);
    this.jobDetail = jdi;
    postProcessJobDetail(this.jobDetail);
}
Also used : JobDetailImpl(org.quartz.impl.JobDetailImpl)

Aggregations

JobDetailImpl (org.quartz.impl.JobDetailImpl)13 Test (org.junit.Test)9 JobDetail (org.quartz.JobDetail)3 ParseException (java.text.ParseException)2 JobContext (org.craftercms.engine.util.quartz.JobContext)2 RequisitionDef (org.opennms.netmgt.config.provisiond.RequisitionDef)2 CronTrigger (org.quartz.CronTrigger)2 SchedulerException (org.quartz.SchedulerException)2 CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)2 Calendar (java.util.Calendar)1 Report (org.opennms.netmgt.config.reportd.Report)1 Job (org.quartz.Job)1 JobExecutionContext (org.quartz.JobExecutionContext)1 Trigger (org.quartz.Trigger)1 TriggerListener (org.quartz.TriggerListener)1 SimpleTriggerImpl (org.quartz.impl.triggers.SimpleTriggerImpl)1