?? stdschedulerfactory.java
字號:
/* * Copyright 2004-2005 OpenSymphony * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * *//* * Previously Copyright (c) 2001-2004 James House */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.sql.SQLException;import java.util.Collection;import java.util.Iterator;import java.util.Locale;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.InstanceIdGenerator;import org.quartz.spi.JobFactory;import org.quartz.spi.JobStore;import org.quartz.spi.SchedulerPlugin;import org.quartz.spi.ThreadPool;import org.quartz.utils.ConnectionProvider;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_INSTANCE_ID_GENERATOR_CLASS = "org.quartz.scheduler.instanceIdGenerator.class"; 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_SERVER_PORT = "org.quartz.scheduler.rmi.serverPort"; 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_JOB_FACTORY_CLASS = "org.quartz.scheduler.jobFactory.class"; public static final String PROP_SCHED_JOB_FACTORY_PREFIX = "org.quartz.scheduler.jobFactory"; 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_CONNECTION_PROVIDER_CLASS = "connectionProvider.class"; 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)));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -