📄 stdschedulerfactory.java
字号:
*/ public void initialize(String filename) throws SchedulerException { // short-circuit if already initialized if (cfg != null) return; if (initException != null) throw initException; InputStream is = null; Properties props = new Properties(); is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); try { if(is != null) { is = new BufferedInputStream(is); propSrc = "the specified file : '" + filename + "' from the class resource path."; } else { is = new BufferedInputStream(new FileInputStream(filename)); propSrc = "the specified file : '" + filename + "'"; } props.load(is); } catch (IOException ioe) { initException = new SchedulerException("Properties file: '" + filename + "' could not be read.", ioe); throw initException; } initialize(props); } /** * <p> * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with * the contenents of the <code>Properties</code> file opened with the * given <code>InputStream</code>. * </p> */ public void initialize(InputStream propertiesStream) throws SchedulerException { // short-circuit if already initialized if (cfg != null) return; if (initException != null) throw initException; Properties props = new Properties(); if (propertiesStream != null) { try { props.load(propertiesStream); propSrc = "an externally opened InputStream."; } catch (IOException e) { initException = new SchedulerException( "Error loading property data from InputStream", e); throw initException; } } else { initException = new SchedulerException( "Error loading property data from InputStream - InputStream is null."); throw initException; } initialize(props); } /** * <p> * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with * the contenents of the given <code>Properties</code> object. * </p> */ public void initialize(Properties props) throws SchedulerException { if (propSrc == null) propSrc = "an externally provided properties instance."; this.cfg = new PropertiesParser(props); } /** * */private Scheduler instantiate() throws SchedulerException { if (cfg == null) initialize(); if (initException != null) throw initException; JobStore js = null; ThreadPool tp = null; QuartzScheduler qs = null; SchedulingContext schedCtxt = null; DBConnectionManager dbMgr = null; Properties tProps = null; String userTXLocation = null; boolean wrapJobInTx = false; boolean autoId = false; long idleWaitTime = -1; long dbFailureRetry = -1; String classLoadHelperClass; SchedulerRepository schedRep = SchedulerRepository.getInstance(); // Get Scheduler Properties // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ String schedName = cfg.getStringProperty(PROP_SCHED_INSTANCE_NAME, "QuartzScheduler"); String threadName = cfg.getStringProperty(PROP_SCHED_THREAD_NAME, schedName + "_QuartzSchedulerThread"); String schedInstId = cfg.getStringProperty(PROP_SCHED_INSTANCE_ID, DEFAULT_INSTANCE_ID); if (schedInstId.equals(AUTO_GENERATE_INSTANCE_ID)) autoId = true; userTXLocation = cfg.getStringProperty(PROP_SCHED_USER_TX_URL, userTXLocation); if (userTXLocation != null && userTXLocation.trim().length() == 0) userTXLocation = null; classLoadHelperClass = cfg.getStringProperty( PROP_SCHED_CLASS_LOAD_HELPER_CLASS, "org.quartz.simpl.CascadingClassLoadHelper"); wrapJobInTx = cfg.getBooleanProperty(PROP_SCHED_WRAP_JOB_IN_USER_TX, wrapJobInTx); idleWaitTime = cfg.getLongProperty(PROP_SCHED_IDLE_WAIT_TIME, idleWaitTime); dbFailureRetry = cfg.getLongProperty( PROP_SCHED_DB_FAILURE_RETRY_INTERVAL, dbFailureRetry); boolean rmiExport = cfg .getBooleanProperty(PROP_SCHED_RMI_EXPORT, false); boolean rmiProxy = cfg.getBooleanProperty(PROP_SCHED_RMI_PROXY, false); String rmiHost = cfg .getStringProperty(PROP_SCHED_RMI_HOST, "localhost"); int rmiPort = cfg.getIntProperty(PROP_SCHED_RMI_PORT, 1099); String rmiCreateRegistry = cfg.getStringProperty( PROP_SCHED_RMI_CREATE_REGISTRY, QuartzSchedulerResources.CREATE_REGISTRY_NEVER); Properties schedCtxtProps = cfg.getPropertyGroup(PROP_SCHED_CONTEXT_PREFIX, true); // If Proxying to remote scheduler, short-circuit here... // ~~~~~~~~~~~~~~~~~~ if (rmiProxy) { if (autoId) schedInstId = DEFAULT_INSTANCE_ID; schedCtxt = new SchedulingContext(); schedCtxt.setInstanceId(schedInstId); String uid = QuartzSchedulerResources.getUniqueIdentifier( schedName, schedInstId); RemoteScheduler remoteScheduler = new RemoteScheduler(schedCtxt, uid, rmiHost, rmiPort); schedRep.bind(remoteScheduler); return remoteScheduler; } // Get ThreadPool Properties // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ String tpClass = cfg.getStringProperty(PROP_THREAD_POOL_CLASS, null); if (tpClass == null) { initException = new SchedulerException( "ThreadPool class not specified. ", SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } try { tp = (ThreadPool) loadClass(tpClass).newInstance(); } catch (Exception e) { initException = new SchedulerException("ThreadPool class '" + tpClass + "' could not be instantiated.", e); initException .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } tProps = cfg.getPropertyGroup(PROP_THREAD_POOL_PREFIX, true); try { setBeanProps(tp, tProps); } catch (Exception e) { initException = new SchedulerException("ThreadPool class '" + tpClass + "' props could not be configured.", e); initException .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } // Get JobStore Properties // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ String jsClass = cfg.getStringProperty(PROP_JOB_STORE_CLASS, RAMJobStore.class.getName()); if (jsClass == null) { initException = new SchedulerException( "JobStore class not specified. ", SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } try { js = (JobStore) loadClass(jsClass).newInstance(); } catch (Exception e) { initException = new SchedulerException("JobStore class '" + jsClass + "' could not be instantiated.", e); initException .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } tProps = cfg.getPropertyGroup(PROP_JOB_STORE_PREFIX, true); try { setBeanProps(js, tProps); } catch (Exception e) { initException = new SchedulerException("JobStore class '" + jsClass + "' props could not be configured.", e); initException .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } if (js instanceof org.quartz.impl.jdbcjobstore.JobStoreSupport) { ((org.quartz.impl.jdbcjobstore.JobStoreSupport) js) .setInstanceId(schedInstId); ((org.quartz.impl.jdbcjobstore.JobStoreSupport) js) .setInstanceName(schedName); } // Set up any DataSources // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ String[] dsNames = cfg.getPropertyGroups(PROP_DATASOURCE_PREFIX); for (int i = 0; i < dsNames.length; i++) { PropertiesParser pp = new PropertiesParser(cfg.getPropertyGroup( PROP_DATASOURCE_PREFIX + "." + dsNames[i], true)); String dsDriver = pp .getStringProperty(PROP_DATASOURCE_DRIVER, null); String dsURL = pp.getStringProperty(PROP_DATASOURCE_URL, null); boolean dsAlwaysLookup = pp.getBooleanProperty( PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP, false); String dsUser = pp.getStringProperty(PROP_DATASOURCE_USER, ""); String dsPass = pp.getStringProperty(PROP_DATASOURCE_PASSWORD, ""); int dsCnt = pp.getIntProperty(PROP_DATASOURCE_MAX_CONNECTIONS, 3); String dsJndi = pp .getStringProperty(PROP_DATASOURCE_JNDI_URL, null); String dsJndiInitial = pp.getStringProperty( PROP_DATASOURCE_JNDI_INITIAL, null); String dsJndiProvider = pp.getStringProperty( PROP_DATASOURCE_JNDI_PROVDER, null); String dsJndiPrincipal = pp.getStringProperty( PROP_DATASOURCE_JNDI_PRINCIPAL, null); String dsJndiCredentials = pp.getStringProperty( PROP_DATASOURCE_JNDI_CREDENTIALS, null); String dsValidation = pp.getStringProperty( PROP_DATASOURCE_VALIDATION_QUERY, null); if (dsJndi != null) { Properties props = null; if (null != dsJndiInitial || null != dsJndiProvider || null != dsJndiPrincipal || null != dsJndiCredentials) { props = new Properties(); if (dsJndiInitial != null) props.put(PROP_DATASOURCE_JNDI_INITIAL, dsJndiInitial); if (dsJndiProvider != null) props.put(PROP_DATASOURCE_JNDI_PROVDER, dsJndiProvider); if (dsJndiPrincipal != null) props.put(PROP_DATASOURCE_JNDI_PRINCIPAL, dsJndiPrincipal); if (dsJndiCredentials != null) props.put(PROP_DATASOURCE_JNDI_CREDENTIALS, dsJndiCredentials); } JNDIConnectionProvider cp = new JNDIConnectionProvider(dsJndi, props, dsAlwaysLookup); dbMgr = DBConnectionManager.getInstance(); dbMgr.addConnectionProvider(dsNames[i], cp); } else { if (dsDriver == null) { initException = new SchedulerException( "Driver not specified for DataSource: " + dsNames[i]); throw initException; } if (dsURL == null) { initException = new SchedulerException( "DB URL not specified for DataSource: " + dsNames[i]); throw initException; } try { PoolingConnectionProvider cp = new PoolingConnectionProvider( dsDriver, dsURL, dsUser, dsPass, dsCnt, dsValidation); dbMgr = DBConnectionManager.getInstance(); dbMgr.addConnectionProvider(dsNames[i], cp); } catch (SQLException sqle) { initException = new SchedulerException( "Could not initialize DataSource: " + dsNames[i], sqle); throw initException; } } } // Set up any SchedulerPlugins // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ String[] pluginNames = cfg.getPropertyGroups(PROP_PLUGIN_PREFIX); SchedulerPlugin[] plugins = new SchedulerPlugin[pluginNames.length]; for (int i = 0; i < pluginNames.length; i++) { Properties pp = cfg.getPropertyGroup(PROP_PLUGIN_PREFIX + "." + pluginNames[i], true); String plugInClass = pp.getProperty(PROP_PLUGIN_CLASS, null); if (plugInClass == null) { initException = new SchedulerException( "SchedulerPlugin class not specified for plugin '" + pluginNames[i] + "'", SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } SchedulerPlugin plugin = null; try { plugin = (SchedulerPlugin) loadClass(plugInClass).newInstance(); } catch (Exception e) { initException = new SchedulerException( "SchedulerPlugin class '" + plugInClass + "' could not be instantiated.", e); initException .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } try { setBeanProps(plugin, pp); } catch (Exception e) { initException = new SchedulerException( "JobStore SchedulerPlugin '" + plugInClass + "' props could not be configured.", e); initException .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION); throw initException; } plugins[i] = plugin; } // Set up any JobListeners // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Class[] strArg = new Class[] { String.class }; String[] jobListenerNames = cfg.getPropertyGroups(PROP_JOB_LISTENER_PREFIX); JobListener[] jobListeners = new JobListener[jobListenerNames.length]; for (int i = 0; i < jobListenerNames.length; i++) { Properties lp = cfg.getPropertyGroup(PROP_JOB_LISTENER_PREFIX + "."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -