Search in sources :

Example 31 with SimpleTrigger

use of org.quartz.SimpleTrigger in project camel by apache.

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeTriggerOptions.

@Test
public void testRestartAppChangeTriggerOptions() throws Exception {
    // Test creates application context twice with different simple trigger options in configuration xml.
    // Both times it retrieves back the option, accessing it via trigger (so, using value stored in DB).
    // After that it asserts that two options are not equal.
    // load spring app
    AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeOptionsTest1.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    SimpleTrigger trigger = (SimpleTrigger) getTrigger(camel, "quartzRoute");
    long repeatInterval = trigger.getRepeatInterval();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // load spring app
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeOptionsTest2.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    SimpleTrigger trigger2 = (SimpleTrigger) getTrigger(camel2, "quartzRoute");
    long repeatInterval2 = trigger2.getRepeatInterval();
    app2.stop();
    // we're done so let's properly close the application contexts, but close
    // the second app before the first one so that the quartz scheduler running
    // inside it can be properly shutdown
    IOHelper.close(app2, app);
    assertNotEquals(repeatInterval, repeatInterval2);
}
Also used : CamelContext(org.apache.camel.CamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 32 with SimpleTrigger

use of org.quartz.SimpleTrigger in project camel by apache.

the class QuartzSimpleRouteTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);
    assertMockEndpointsSatisfied();
    Trigger trigger = mock.getReceivedExchanges().get(0).getIn().getHeader("trigger", Trigger.class);
    Assert.assertThat(trigger instanceof SimpleTrigger, CoreMatchers.is(true));
    JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE).equals("simple"), CoreMatchers.is(true));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER).equals(-1), CoreMatchers.is(true));
    Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL).equals(2000L), CoreMatchers.is(true));
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 33 with SimpleTrigger

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

the class JobService method startSpellingJob.

/**
     * Starts a background job which updates the spelling corrector
     */
private void startSpellingJob() {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        // Setup the indexer which runs forever adding documents to be indexed
        JobDetail job = newJob(PopulateSpellingCorrectorJob.class).withIdentity("spellingjob").build();
        SimpleTrigger trigger = newTrigger().withIdentity("spellingjob").withSchedule(simpleSchedule().withIntervalInSeconds(360).repeatForever()).build();
        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 34 with SimpleTrigger

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

the class JobService method startEnqueueJob.

/**
     * Starts a background job which pulls all repositories from the database and adds them to the
     * queue to be indexed
     */
private void startEnqueueJob() {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        // Setup the indexer which runs forever adding documents to be indexed
        JobDetail job = newJob(EnqueueRepositoryJob.class).withIdentity("enqueuejob").build();
        SimpleTrigger trigger = newTrigger().withIdentity("enqueuejob").withSchedule(simpleSchedule().withIntervalInSeconds(this.UPDATETIME).repeatForever()).build();
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
        Scheduler scheduler2 = Singleton.getScheduler();
        // Setup the indexer which runs forever adding documents to be indexed
        JobDetail job2 = newJob(EnqueueFileRepositoryJob.class).withIdentity("enqueuefilejob").build();
        SimpleTrigger trigger2 = newTrigger().withIdentity("enqueuefilejob").withSchedule(simpleSchedule().withIntervalInSeconds(this.FILEINDEXUPDATETIME).repeatForever()).build();
        scheduler2.scheduleJob(job2, trigger2);
        scheduler2.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 35 with SimpleTrigger

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

the class JobService method startIndexGitRepoJobs.

/**
     * Creates a git repo indexer job which will pull from the list of git repositories and start
     * indexing them
     */
public void startIndexGitRepoJobs(String uniquename) {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        JobDetail job = newJob(IndexGitRepoJob.class).withIdentity("updateindex-git-" + uniquename).build();
        SimpleTrigger trigger = newTrigger().withIdentity("updateindex-git-" + 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)

Aggregations

SimpleTrigger (org.quartz.SimpleTrigger)38 SchedulerException (org.quartz.SchedulerException)18 JobDetail (org.quartz.JobDetail)15 CronTrigger (org.quartz.CronTrigger)12 Scheduler (org.quartz.Scheduler)11 Date (java.util.Date)8 Test (org.junit.Test)8 Trigger (org.quartz.Trigger)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)5 JobDataMap (org.quartz.JobDataMap)5 SimpleDateFormat (java.text.SimpleDateFormat)4 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)4 DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)4 CamelContext (org.apache.camel.CamelContext)4 AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 IOException (java.io.IOException)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 JobExecutionException (org.quartz.JobExecutionException)3 ApplicationContext (org.springframework.context.ApplicationContext)3