Search in sources :

Example 1 with QuartzIocLoader

use of org.nutz.integration.quartz.QuartzIocLoader 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

Properties (java.util.Properties)1 NutQuartzJobFactory (org.nutz.integration.quartz.NutQuartzJobFactory)1 QuartzIocLoader (org.nutz.integration.quartz.QuartzIocLoader)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 SchedulerException (org.quartz.SchedulerException)1 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)1