Search in sources :

Example 1 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project jmxtrans by jmxtrans.

the class JmxTransModule method scheduler.

@Provides
@Inject
Scheduler scheduler(JmxTransConfiguration configuration, GuiceJobFactory jobFactory) throws SchedulerException, IOException {
    StdSchedulerFactory serverSchedFact = new StdSchedulerFactory();
    try (InputStream stream = openQuartzConfiguration(configuration)) {
        serverSchedFact.initialize(stream);
    }
    Scheduler scheduler = serverSchedFact.getScheduler();
    scheduler.setJobFactory(jobFactory);
    return scheduler;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Scheduler(org.quartz.Scheduler) Inject(com.google.inject.Inject) Provides(com.google.inject.Provides)

Example 2 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project camel by apache.

the class QuartzComponent method createSchedulerFactory.

private SchedulerFactory createSchedulerFactory() throws SchedulerException {
    SchedulerFactory answer;
    Properties prop = loadProperties();
    if (prop != null) {
        // force disabling update checker (will do online check over the internet)
        prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
        prop.put("org.terracotta.quartz.skipUpdateCheck", "true");
        // camel context name will be a suffix to use one scheduler per context
        if (isPrefixInstanceName()) {
            String instName = createInstanceName(prop);
            prop.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instName);
        }
        if (isInterruptJobsOnShutdown()) {
            prop.setProperty(StdSchedulerFactory.PROP_SCHED_INTERRUPT_JOBS_ON_SHUTDOWN, "true");
        }
        // enable jmx unless configured to not do so
        if (enableJmx && !prop.containsKey("org.quartz.scheduler.jmx.export")) {
            prop.put("org.quartz.scheduler.jmx.export", "true");
            LOG.info("Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX.");
        }
        answer = new StdSchedulerFactory(prop);
    } else {
        // read default props to be able to use a single scheduler per camel context
        // if we need more than one scheduler per context use setScheduler(Scheduler)
        // or setFactory(SchedulerFactory) methods
        // must use classloader from StdSchedulerFactory to work even in OSGi
        InputStream is = StdSchedulerFactory.class.getClassLoader().getResourceAsStream("org/quartz/quartz.properties");
        if (is == null) {
            throw new SchedulerException("Quartz properties file not found in classpath: org/quartz/quartz.properties");
        }
        prop = new Properties();
        try {
            prop.load(is);
        } catch (IOException e) {
            throw new SchedulerException("Error loading Quartz properties file from classpath: org/quartz/quartz.properties", e);
        } finally {
            IOHelper.close(is);
        }
        // camel context name will be a suffix to use one scheduler per context
        if (isPrefixInstanceName()) {
            // camel context name will be a suffix to use one scheduler per context
            String instName = createInstanceName(prop);
            prop.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, instName);
        }
        // force disabling update checker (will do online check over the internet)
        prop.put("org.quartz.scheduler.skipUpdateCheck", "true");
        prop.put("org.terracotta.quartz.skipUpdateCheck", "true");
        if (isInterruptJobsOnShutdown()) {
            prop.setProperty(StdSchedulerFactory.PROP_SCHED_INTERRUPT_JOBS_ON_SHUTDOWN, "true");
        }
        // enable jmx unless configured to not do so
        if (enableJmx && !prop.containsKey("org.quartz.scheduler.jmx.export")) {
            prop.put("org.quartz.scheduler.jmx.export", "true");
            LOG.info("Setting org.quartz.scheduler.jmx.export=true to ensure QuartzScheduler(s) will be enlisted in JMX.");
        }
        answer = new StdSchedulerFactory(prop);
    }
    if (LOG.isDebugEnabled()) {
        String name = prop.getProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME);
        LOG.debug("Creating SchedulerFactory: {} with properties: {}", name, prop);
    }
    return answer;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 3 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project siddhi by wso2.

the class CronWindowProcessor method scheduleCronJob.

private void scheduleCronJob(String cronString, String elementId) {
    try {
        SchedulerFactory schedFact = new StdSchedulerFactory();
        scheduler = schedFact.getScheduler();
        jobName = "EventRemoverJob_" + elementId;
        JobKey jobKey = new JobKey(jobName, jobGroup);
        if (scheduler.checkExists(jobKey)) {
            scheduler.deleteJob(jobKey);
        }
        scheduler.start();
        JobDataMap dataMap = new JobDataMap();
        dataMap.put("windowProcessor", this);
        JobDetail job = org.quartz.JobBuilder.newJob(CronWindowProcessor.class).withIdentity(jobName, jobGroup).usingJobData(dataMap).build();
        Trigger trigger = org.quartz.TriggerBuilder.newTrigger().withIdentity("EventRemoverTrigger_" + elementId, jobGroup).withSchedule(CronScheduleBuilder.cronSchedule(cronString)).build();
        scheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        log.error("Error while instantiating quartz scheduler", e);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) JobKey(org.quartz.JobKey) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 4 with StdSchedulerFactory

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

the class SchedulingUtils method createScheduler.

public static Scheduler createScheduler(String schedulerName) throws SchedulerException {
    Properties props = new Properties();
    props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, schedulerName);
    props.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
    props.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
    SchedulerFactory schedulerFactory = new StdSchedulerFactory(props);
    return schedulerFactory.getScheduler();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Properties(java.util.Properties) SimpleThreadPool(org.quartz.simpl.SimpleThreadPool) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Example 5 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project nutzboot by nutzam.

the class QuartzStarter method getIocLoader.

public IocLoader getIocLoader() {
    if (!conf.has("cron.pkgs")) {
        conf.put("cron.pkgs", appContext.getPackage());
    }
    QuartzIocLoader loader = new QuartzIocLoader();
    if (appContext.getClassLoader().getResource("quartz.properties") != null) {
        log.debug("found quartz.properties, use it");
        return loader;
    }
    // 通过nutzboot的配置信息来初始化
    Properties properties = new Properties();
    for (String key : conf.keySet()) {
        if (key.startsWith("quartz.")) {
            properties.put("org." + key, conf.get(key));
        }
    }
    // 设置一下默认值
    /*
org.quartz.scheduler.instanceName = NutzbookScheduler 
org.quartz.threadPool.threadCount = 3 
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.scheduler.skipUpdateCheck=true
		 */
    properties.putIfAbsent("org.quartz.scheduler.instanceName", "NutzbootScheduler");
    properties.putIfAbsent("org.quartz.threadPool.threadCount", "8");
    properties.putIfAbsent("org.quartz.scheduler.skipUpdateCheck", "true");
    startupDelay = conf.getInt("quartz.startupDelay", 0);
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory(properties);
        scheduler = factory.getScheduler();
        scheduler.setJobFactory(new NutQuartzJobFactory(appContext.getIoc()));
        ((Ioc2) appContext.getIoc()).getIocContext().save("app", "scheduler", new ObjectProxy(scheduler));
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
    return loader;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) QuartzIocLoader(org.nutz.integration.quartz.QuartzIocLoader) SchedulerException(org.quartz.SchedulerException) ObjectProxy(org.nutz.ioc.ObjectProxy) Properties(java.util.Properties) NutQuartzJobFactory(org.nutz.integration.quartz.NutQuartzJobFactory)

Aggregations

StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)66 SchedulerFactory (org.quartz.SchedulerFactory)29 SchedulerException (org.quartz.SchedulerException)22 Scheduler (org.quartz.Scheduler)19 JobDetail (org.quartz.JobDetail)17 Logger (org.slf4j.Logger)14 Date (java.util.Date)11 Properties (java.util.Properties)11 Trigger (org.quartz.Trigger)11 JobKey (org.quartz.JobKey)7 JobDataMap (org.quartz.JobDataMap)6 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 DateBuilder.nextGivenSecondDate (org.quartz.DateBuilder.nextGivenSecondDate)4 SimpleTrigger (org.quartz.SimpleTrigger)4 ParseException (java.text.ParseException)3 CronTrigger (org.quartz.CronTrigger)3 SimpleThreadPool (org.quartz.simpl.SimpleThreadPool)3 QuartzManager (com.example.quartz.QuartzManager)2