Search in sources :

Example 21 with Scheduler

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

the class QuartzSupportTests method schedulerAutoStartsOnContextRefreshedEventByDefault.

@Test
@SuppressWarnings("resource")
public void schedulerAutoStartsOnContextRefreshedEventByDefault() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBeanDefinition("scheduler", new RootBeanDefinition(SchedulerFactoryBean.class));
    Scheduler bean = context.getBean("scheduler", Scheduler.class);
    assertFalse(bean.isStarted());
    context.refresh();
    assertTrue(bean.isStarted());
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Scheduler(org.quartz.Scheduler) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 22 with Scheduler

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

the class QuartzSupportTests method multipleSchedulers.

/**
	 * Tests the creation of multiple schedulers (SPR-772)
	 */
@Test
public void multipleSchedulers() throws Exception {
    ClassPathXmlApplicationContext ctx = context("multipleSchedulers.xml");
    try {
        Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
        Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
        assertNotSame(scheduler1, scheduler2);
        assertEquals("quartz1", scheduler1.getSchedulerName());
        assertEquals("quartz2", scheduler2.getSchedulerName());
    } finally {
        ctx.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Scheduler(org.quartz.Scheduler) Test(org.junit.Test)

Example 23 with Scheduler

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

the class QuartzSupportTests method schedulerAutoStartupFalse.

@Test
@SuppressWarnings("resource")
public void schedulerAutoStartupFalse() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class).addPropertyValue("autoStartup", false).getBeanDefinition();
    context.registerBeanDefinition("scheduler", beanDefinition);
    Scheduler bean = context.getBean("scheduler", Scheduler.class);
    assertFalse(bean.isStarted());
    context.refresh();
    assertFalse(bean.isStarted());
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Scheduler(org.quartz.Scheduler) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 24 with Scheduler

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

the class QuartzComponent method createScheduler.

protected Scheduler createScheduler() throws SchedulerException {
    Scheduler scheduler = getFactory().getScheduler();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Using SchedulerFactory {} to get/create Scheduler {}({})", new Object[] { getFactory(), scheduler, ObjectHelper.getIdentityHashCode(scheduler) });
    }
    // register current camel context to scheduler so we can look it up when jobs is being triggered
    // must use management name as it should be unique in the same JVM
    String uid = QuartzHelper.getQuartzContextName(getCamelContext());
    scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + uid, getCamelContext());
    // store Camel job counter
    AtomicInteger number = (AtomicInteger) scheduler.getContext().get("CamelJobs");
    if (number == null) {
        number = new AtomicInteger(0);
        scheduler.getContext().put("CamelJobs", number);
    }
    return scheduler;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Scheduler(org.quartz.Scheduler)

Example 25 with Scheduler

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

the class QuartzEndpoint method resumeTrigger.

public void resumeTrigger() throws Exception {
    if (!jobPaused.get()) {
        return;
    }
    jobPaused.set(false);
    Scheduler scheduler = getComponent().getScheduler();
    if (scheduler != null) {
        LOG.info("Resuming trigger {}", triggerKey);
        scheduler.resumeTrigger(triggerKey);
    }
}
Also used : Scheduler(org.quartz.Scheduler)

Aggregations

Scheduler (org.quartz.Scheduler)73 SchedulerException (org.quartz.SchedulerException)37 JobDetail (org.quartz.JobDetail)33 Trigger (org.quartz.Trigger)22 Test (org.junit.Test)19 JobKey (org.quartz.JobKey)17 SimpleTrigger (org.quartz.SimpleTrigger)16 CronTrigger (org.quartz.CronTrigger)15 JobDataMap (org.quartz.JobDataMap)10 TriggerKey (org.quartz.TriggerKey)10 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 IOException (java.io.IOException)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)3