📄 stdschedulerfactory.java
字号:
/* * Copyright James House (c) 2001-2004 * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: 1. * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. 2. Redistributions in * binary form must reproduce the above copyright notice, this list of * conditions and the following disclaimer in the documentation and/or other * materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */package org.quartz.impl;import java.beans.BeanInfo;import java.beans.IntrospectionException;import java.beans.Introspector;import java.beans.PropertyDescriptor;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.lang.reflect.Method;import java.net.InetAddress;import java.sql.SQLException;import java.util.Collection;import java.util.Iterator;import java.util.Properties;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.quartz.JobListener;import org.quartz.Scheduler;import org.quartz.SchedulerConfigException;import org.quartz.SchedulerException;import org.quartz.SchedulerFactory;import org.quartz.TriggerListener;import org.quartz.core.JobRunShellFactory;import org.quartz.core.QuartzScheduler;import org.quartz.core.QuartzSchedulerResources;import org.quartz.core.SchedulingContext;import org.quartz.ee.jta.JTAJobRunShellFactory;import org.quartz.ee.jta.UserTransactionHelper;import org.quartz.impl.jdbcjobstore.JobStoreSupport;import org.quartz.simpl.RAMJobStore;import org.quartz.simpl.SimpleThreadPool;import org.quartz.spi.ClassLoadHelper;import org.quartz.spi.JobStore;import org.quartz.spi.SchedulerPlugin;import org.quartz.spi.ThreadPool;import org.quartz.utils.DBConnectionManager;import org.quartz.utils.JNDIConnectionProvider;import org.quartz.utils.PoolingConnectionProvider;import org.quartz.utils.PropertiesParser;/** * <p> * An implementation of <code>{@link org.quartz.SchedulerFactory}</code> that * does all of it's work of creating a <code>QuartzScheduler</code> instance * based on the contenents of a <code>Properties</code> file. * </p> * * <p> * By default a properties file named "quartz.properties" is loaded from the * 'current working directory'. If that fails, then the "quartz.properties" * file located (as a resource) in the org/quartz package is loaded. If you * wish to use a file other than these defaults, you must define the system * property 'org.quartz.properties' to* point to the file you want. * </p> * * <p> * See the sample properties files that are distributed with Quartz for * information about the various settings available within the file. * </p> * * <p> * Alternativly, you can explicitly initialize the factory by calling one of * the <code>initialize(xx)</code> methods before calling <code>getScheduler()</code>. * </p> * * <p> * Instances of the specified <code>{@link org.quartz.spi.JobStore}</code>, * <code>{@link org.quartz.spi.ThreadPool}</code>, classes will be created * by name, and then any additional properties specified for them in the config * file will be set on the instance by calling an equivalent 'set' method. For * example if the properties file contains the property 'org.quartz.jobStore. * myProp = 10' then after the JobStore class has been instantiated, the method * 'setMyProp()' will be called on it. Type conversion to primitive Java types * (int, long, float, double, boolean, and String) are performed before calling * the propertie's setter method. * </p> * * @author James House * @author Anthony Eden * @author Mohammad Rezaei */public class StdSchedulerFactory implements SchedulerFactory { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constants. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ public static final String PROPERTIES_FILE = "org.quartz.properties"; public static final String PROP_SCHED_INSTANCE_NAME = "org.quartz.scheduler.instanceName"; public static final String PROP_SCHED_INSTANCE_ID = "org.quartz.scheduler.instanceId"; public static final String PROP_SCHED_THREAD_NAME = "org.quartz.scheduler.threadName"; public static final String PROP_SCHED_RMI_EXPORT = "org.quartz.scheduler.rmi.export"; public static final String PROP_SCHED_RMI_PROXY = "org.quartz.scheduler.rmi.proxy"; public static final String PROP_SCHED_RMI_HOST = "org.quartz.scheduler.rmi.registryHost"; public static final String PROP_SCHED_RMI_PORT = "org.quartz.scheduler.rmi.registryPort"; public static final String PROP_SCHED_RMI_CREATE_REGISTRY = "org.quartz.scheduler.rmi.createRegistry"; public static final String PROP_SCHED_WRAP_JOB_IN_USER_TX = "org.quartz.scheduler.wrapJobExecutionInUserTransaction"; public static final String PROP_SCHED_USER_TX_URL = "org.quartz.scheduler.userTransactionURL"; public static final String PROP_SCHED_IDLE_WAIT_TIME = "org.quartz.scheduler.idleWaitTime"; public static final String PROP_SCHED_DB_FAILURE_RETRY_INTERVAL = "org.quartz.scheduler.dbFailureRetryInterval"; public static final String PROP_SCHED_CLASS_LOAD_HELPER_CLASS = "org.quartz.scheduler.classLoadHelper.class"; public static final String PROP_SCHED_CONTEXT_PREFIX = "org.quartz.context.key"; public static final String PROP_THREAD_POOL_PREFIX = "org.quartz.threadPool"; public static final String PROP_THREAD_POOL_CLASS = "org.quartz.threadPool.class"; public static final String PROP_JOB_STORE_PREFIX = "org.quartz.jobStore"; public static final String PROP_JOB_STORE_CLASS = "org.quartz.jobStore.class"; public static final String PROP_JOB_STORE_USE_PROP = "org.quartz.jobStore.useProperties"; public static final String PROP_DATASOURCE_PREFIX = "org.quartz.dataSource"; public static final String PROP_DATASOURCE_DRIVER = "driver"; public static final String PROP_DATASOURCE_URL = "URL"; public static final String PROP_DATASOURCE_USER = "user"; public static final String PROP_DATASOURCE_PASSWORD = "password"; public static final String PROP_DATASOURCE_MAX_CONNECTIONS = "maxConnections"; public static final String PROP_DATASOURCE_VALIDATION_QUERY = "validationQuery"; public static final String PROP_DATASOURCE_JNDI_URL = "jndiURL"; public static final String PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP = "jndiAlwaysLookup"; public static final String PROP_DATASOURCE_JNDI_INITIAL = "java.naming.factory.initial"; public static final String PROP_DATASOURCE_JNDI_PROVDER = "java.naming.provider.url"; public static final String PROP_DATASOURCE_JNDI_PRINCIPAL = "java.naming.security.principal"; public static final String PROP_DATASOURCE_JNDI_CREDENTIALS = "java.naming.security.credentials"; public static final String PROP_PLUGIN_PREFIX = "org.quartz.plugin"; public static final String PROP_PLUGIN_CLASS = "class"; public static final String PROP_JOB_LISTENER_PREFIX = "org.quartz.jobListener"; public static final String PROP_TRIGGER_LISTENER_PREFIX = "org.quartz.triggerListener"; public static final String PROP_LISTENER_CLASS = "class"; public static final String DEFAULT_INSTANCE_ID = "NON_CLUSTERED"; public static final String AUTO_GENERATE_INSTANCE_ID = "AUTO"; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Data members. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private SchedulerException initException = null; private String propSrc = null; private PropertiesParser cfg; // private Scheduler scheduler; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constructors. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ public StdSchedulerFactory() { } public StdSchedulerFactory(Properties props) throws SchedulerException { initialize(props); } public StdSchedulerFactory(String fileName) throws SchedulerException { initialize(fileName); } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ public static Log getLog() { return LogFactory.getLog(StdSchedulerFactory.class); } /** * <p> * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with * the contenents of a <code>Properties</code> file. * </p> * * <p> * By default a properties file named "quartz.properties" is loaded from * the 'current working directory'. If that fails, then the * "quartz.properties" file located (as a resource) in the org/quartz * package is loaded. If you wish to use a file other than these defaults, * you must define the system property 'org.quartz.properties' to point to * the file you want. * </p> * * <p> * System properties (envrionment variables, and -D definitions on the * command-line when running the JVM) over-ride any properties in the * loaded file. * </p> */ public void initialize() throws SchedulerException { // short-circuit if already initialized if (cfg != null) return; if (initException != null) throw initException; String requestedFile = System.getProperty(PROPERTIES_FILE); String propFileName = requestedFile != null ? requestedFile : "quartz.properties"; File propFile = new File(propFileName); Properties props = new Properties(); if (propFile.exists()) { try { if (requestedFile != null) propSrc = "specified file: '" + requestedFile + "'"; else propSrc = "default file in current working dir: 'quartz.properties'"; props.load(new BufferedInputStream(new FileInputStream( propFileName))); initialize(overRideWithSysProps(props)); } catch (IOException ioe) { initException = new SchedulerException("Properties file: '" + propFileName + "' could not be read.", ioe); throw initException; } } else if (requestedFile != null) { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(requestedFile); if(in == null) { initException = new SchedulerException("Properties file: '" + requestedFile + "' could not be found."); throw initException; } propSrc = "specified file: '" + requestedFile + "' in the class resource path."; try { props.load(new BufferedInputStream(in)); initialize(overRideWithSysProps(props)); } catch (IOException ioe) { initException = new SchedulerException("Properties file: '" + requestedFile + "' could not be read.", ioe); throw initException; } } else { propSrc = "default resource file in Quartz package: 'quartz.properties'"; InputStream in = getClass().getClassLoader().getResourceAsStream( "quartz.properties"); if (in == null) in = getClass().getClassLoader().getResourceAsStream( "/quartz.properties"); if (in == null) in = getClass().getClassLoader().getResourceAsStream( "org/quartz/quartz.properties"); if (in == null) { initException = new SchedulerException( "Default quartz.properties not found in class path"); throw initException; } try { props.load(in); } catch (IOException ioe) { initException = new SchedulerException( "Resource properties file: 'org/quartz/quartz.properties' " + "could not be read from the classpath.", ioe); throw initException; } initialize(overRideWithSysProps(props)); } } private Properties overRideWithSysProps(Properties props) { Properties sysProps = System.getProperties(); props.putAll(sysProps); return props; } /** * <p> * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with * the contenents of the <code>Properties</code> file with the given * name. * </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -