Search in sources :

Example 56 with JobDetail

use of org.quartz.JobDetail in project cdap by caskdata.

the class DatasetBasedTimeScheduleStoreTest method testJobKeyDeletion.

private void testJobKeyDeletion(String version) throws Exception {
    schedulerSetup(true);
    String jobGroup = "jg";
    JobDetail jobDetail = getJobDetail(jobGroup, "job1", version);
    JobDetail versionLessJobDetail = getJobDetail(jobGroup, "job1", null);
    scheduler.addJob(versionLessJobDetail, true);
    scheduler.addJob(jobDetail, true);
    schedulerTearDown();
    schedulerSetup(true);
    Set<JobKey> keys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup));
    if (version.equals(ApplicationId.DEFAULT_VERSION)) {
        Assert.assertEquals(1, keys.size());
        Assert.assertTrue(scheduler.deleteJob(jobDetail.getKey()));
    } else {
        Assert.assertEquals(2, keys.size());
        Assert.assertTrue(scheduler.deleteJob(jobDetail.getKey()));
        Assert.assertTrue(scheduler.deleteJob(versionLessJobDetail.getKey()));
    }
    schedulerTearDown();
    schedulerSetup(true);
    Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup));
    Assert.assertEquals(0, jobKeys.size());
    schedulerTearDown();
}
Also used : JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey)

Example 57 with JobDetail

use of org.quartz.JobDetail in project searchcode-server by boyter.

the class JobService method startIndexerJob.

private void startIndexerJob() throws SchedulerException {
    Scheduler scheduler = Singleton.getScheduler();
    // Setup the indexer which runs forever indexing
    JobDetail job = newJob(IndexDocumentsJob.class).withIdentity("indexerjob").build();
    SimpleTrigger trigger = newTrigger().withIdentity("indexerjob").withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
    scheduler.scheduleJob(job, trigger);
    scheduler.start();
}
Also used : JobDetail(org.quartz.JobDetail) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 58 with JobDetail

use of org.quartz.JobDetail in project searchcode-server by boyter.

the class JobService method startIndexSvnRepoJobs.

/**
     * Creates a svn repo indexer job which will pull from the list of git repositories and start
     * indexing them
     */
public void startIndexSvnRepoJobs(String uniquename) {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        JobDetail job = newJob(IndexSvnRepoJob.class).withIdentity("updateindex-svn-" + uniquename).build();
        SimpleTrigger trigger = newTrigger().withIdentity("updateindex-svn-" + uniquename).withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
        job.getJobDataMap().put("REPOLOCATIONS", this.REPOLOCATION);
        job.getJobDataMap().put("LOWMEMORY", this.LOWMEMORY);
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    } catch (SchedulerException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 59 with JobDetail

use of org.quartz.JobDetail in project opennms by OpenNMS.

the class Statsd method scheduleReport.

private void scheduleReport(ReportDefinition reportDef) throws ClassNotFoundException, NoSuchMethodException, ParseException, SchedulerException, Exception {
    // this is most likely reentrant since the method is private and called from start via plural version.
    synchronized (m_scheduler) {
        MethodInvokingJobDetailFactoryBean jobFactory = new MethodInvokingJobDetailFactoryBean();
        jobFactory.setTargetObject(this);
        jobFactory.setTargetMethod("runReport");
        jobFactory.setArguments(new Object[] { reportDef });
        jobFactory.setConcurrent(false);
        jobFactory.setBeanName(reportDef.getDescription());
        jobFactory.afterPropertiesSet();
        JobDetail jobDetail = (JobDetail) jobFactory.getObject();
        CronTriggerFactoryBean cronReportTrigger = new CronTriggerFactoryBean();
        cronReportTrigger.setBeanName(reportDef.getDescription());
        cronReportTrigger.setJobDetail(jobDetail);
        cronReportTrigger.setCronExpression(reportDef.getCronExpression());
        cronReportTrigger.afterPropertiesSet();
        m_scheduler.scheduleJob(jobDetail, cronReportTrigger.getObject());
        LOG.debug("Schedule report {}", cronReportTrigger);
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTriggerFactoryBean(org.springframework.scheduling.quartz.CronTriggerFactoryBean) MethodInvokingJobDetailFactoryBean(org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean)

Example 60 with JobDetail

use of org.quartz.JobDetail 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().orElse(null));
    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)

Aggregations

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4