KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > StdSchedulerFactory


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 /*
19  * Previously Copyright (c) 2001-2004 James House
20  */

21 package org.quartz.impl;
22
23 import java.beans.BeanInfo JavaDoc;
24 import java.beans.IntrospectionException JavaDoc;
25 import java.beans.Introspector JavaDoc;
26 import java.beans.PropertyDescriptor JavaDoc;
27 import java.io.BufferedInputStream JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33 import java.security.AccessControlException JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import java.util.Collection JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Locale JavaDoc;
38 import java.util.Properties JavaDoc;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42 import org.quartz.JobListener;
43 import org.quartz.Scheduler;
44 import org.quartz.SchedulerConfigException;
45 import org.quartz.SchedulerException;
46 import org.quartz.SchedulerFactory;
47 import org.quartz.TriggerListener;
48 import org.quartz.core.JobRunShellFactory;
49 import org.quartz.core.QuartzScheduler;
50 import org.quartz.core.QuartzSchedulerResources;
51 import org.quartz.core.SchedulingContext;
52 import org.quartz.ee.jta.JTAJobRunShellFactory;
53 import org.quartz.ee.jta.UserTransactionHelper;
54 import org.quartz.impl.jdbcjobstore.JobStoreSupport;
55 import org.quartz.impl.jdbcjobstore.Semaphore;
56 import org.quartz.impl.jdbcjobstore.TablePrefixAware;
57 import org.quartz.simpl.RAMJobStore;
58 import org.quartz.simpl.SimpleThreadPool;
59 import org.quartz.spi.ClassLoadHelper;
60 import org.quartz.spi.InstanceIdGenerator;
61 import org.quartz.spi.JobFactory;
62 import org.quartz.spi.JobStore;
63 import org.quartz.spi.SchedulerPlugin;
64 import org.quartz.spi.ThreadPool;
65 import org.quartz.utils.ConnectionProvider;
66 import org.quartz.utils.DBConnectionManager;
67 import org.quartz.utils.JNDIConnectionProvider;
68 import org.quartz.utils.PoolingConnectionProvider;
69 import org.quartz.utils.PropertiesParser;
70
71 /**
72  * <p>
73  * An implementation of <code>{@link org.quartz.SchedulerFactory}</code> that
74  * does all of its work of creating a <code>QuartzScheduler</code> instance
75  * based on the contenents of a <code>Properties</code> file.
76  * </p>
77  *
78  * <p>
79  * By default a properties file named "quartz.properties" is loaded from the
80  * 'current working directory'. If that fails, then the "quartz.properties"
81  * file located (as a resource) in the org/quartz package is loaded. If you
82  * wish to use a file other than these defaults, you must define the system
83  * property 'org.quartz.properties' to point to the file you want.
84  * </p>
85  *
86  * <p>
87  * See the sample properties files that are distributed with Quartz for
88  * information about the various settings available within the file.
89  * </p>
90  *
91  * <p>
92  * Alternatively, you can explicitly initialize the factory by calling one of
93  * the <code>initialize(xx)</code> methods before calling <code>getScheduler()</code>.
94  * </p>
95  *
96  * <p>
97  * Instances of the specified <code>{@link org.quartz.spi.JobStore}</code>,
98  * <code>{@link org.quartz.spi.ThreadPool}</code>, classes will be created
99  * by name, and then any additional properties specified for them in the config
100  * file will be set on the instance by calling an equivalent 'set' method. For
101  * example if the properties file contains the property
102  * 'org.quartz.jobStore.myProp = 10' then after the JobStore class has been
103  * instantiated, the method 'setMyProp()' will be called on it. Type conversion
104  * to primitive Java types (int, long, float, double, boolean, and String) are
105  * performed before calling the property's setter method.
106  * </p>
107  *
108  * @author James House
109  * @author Anthony Eden
110  * @author Mohammad Rezaei
111  */

112 public class StdSchedulerFactory implements SchedulerFactory {
113
114     /*
115      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116      *
117      * Constants.
118      *
119      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120      */

121
122     public static final String JavaDoc PROPERTIES_FILE = "org.quartz.properties";
123
124     public static final String JavaDoc PROP_SCHED_INSTANCE_NAME = "org.quartz.scheduler.instanceName";
125
126     public static final String JavaDoc PROP_SCHED_INSTANCE_ID = "org.quartz.scheduler.instanceId";
127
128     public static final String JavaDoc PROP_SCHED_INSTANCE_ID_GENERATOR_PREFIX = "org.quartz.scheduler.instanceIdGenerator";
129     
130     public static final String JavaDoc PROP_SCHED_INSTANCE_ID_GENERATOR_CLASS =
131         PROP_SCHED_INSTANCE_ID_GENERATOR_PREFIX + ".class";
132     
133     public static final String JavaDoc PROP_SCHED_THREAD_NAME = "org.quartz.scheduler.threadName";
134
135     public static final String JavaDoc PROP_SCHED_JMX_EXPORT = "org.quartz.scheduler.jmx.export";
136     
137     public static final String JavaDoc PROP_SCHED_JMX_PROXY = "org.quartz.scheduler.jmx.proxy";
138
139     public static final String JavaDoc PROP_SCHED_JMX_PROXY_CLASS = "org.quartz.scheduler.jmx.proxy.class";
140
141     public static final String JavaDoc PROP_SCHED_JMX_OBJECT_NAME = "org.quartz.scheduler.jmx.objectName";
142
143     public static final String JavaDoc PROP_SCHED_RMI_EXPORT = "org.quartz.scheduler.rmi.export";
144
145     public static final String JavaDoc PROP_SCHED_RMI_PROXY = "org.quartz.scheduler.rmi.proxy";
146
147     public static final String JavaDoc PROP_SCHED_RMI_HOST = "org.quartz.scheduler.rmi.registryHost";
148
149     public static final String JavaDoc PROP_SCHED_RMI_PORT = "org.quartz.scheduler.rmi.registryPort";
150
151     public static final String JavaDoc PROP_SCHED_RMI_SERVER_PORT = "org.quartz.scheduler.rmi.serverPort";
152
153     public static final String JavaDoc PROP_SCHED_RMI_CREATE_REGISTRY = "org.quartz.scheduler.rmi.createRegistry";
154
155     public static final String JavaDoc PROP_SCHED_RMI_BIND_NAME = "org.quartz.scheduler.rmi.bindName";
156
157     public static final String JavaDoc PROP_SCHED_WRAP_JOB_IN_USER_TX = "org.quartz.scheduler.wrapJobExecutionInUserTransaction";
158
159     public static final String JavaDoc PROP_SCHED_USER_TX_URL = "org.quartz.scheduler.userTransactionURL";
160
161     public static final String JavaDoc PROP_SCHED_IDLE_WAIT_TIME = "org.quartz.scheduler.idleWaitTime";
162
163     public static final String JavaDoc PROP_SCHED_DB_FAILURE_RETRY_INTERVAL = "org.quartz.scheduler.dbFailureRetryInterval";
164
165     public static final String JavaDoc PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON = "org.quartz.scheduler.makeSchedulerThreadDaemon";
166
167     public static final String JavaDoc PROP_SCHED_CLASS_LOAD_HELPER_CLASS = "org.quartz.scheduler.classLoadHelper.class";
168
169     public static final String JavaDoc PROP_SCHED_JOB_FACTORY_CLASS = "org.quartz.scheduler.jobFactory.class";
170
171     public static final String JavaDoc PROP_SCHED_JOB_FACTORY_PREFIX = "org.quartz.scheduler.jobFactory";
172
173     public static final String JavaDoc PROP_SCHED_CONTEXT_PREFIX = "org.quartz.context.key";
174
175     public static final String JavaDoc PROP_THREAD_POOL_PREFIX = "org.quartz.threadPool";
176
177     public static final String JavaDoc PROP_THREAD_POOL_CLASS = "org.quartz.threadPool.class";
178
179     public static final String JavaDoc PROP_JOB_STORE_PREFIX = "org.quartz.jobStore";
180
181     public static final String JavaDoc PROP_JOB_STORE_LOCK_HANDLER_PREFIX = PROP_JOB_STORE_PREFIX + ".lockHandler";
182     
183     public static final String JavaDoc PROP_JOB_STORE_LOCK_HANDLER_CLASS = PROP_JOB_STORE_LOCK_HANDLER_PREFIX + ".class";
184
185     public static final String JavaDoc PROP_TABLE_PREFIX = "tablePrefix";
186
187     public static final String JavaDoc PROP_JOB_STORE_CLASS = "org.quartz.jobStore.class";
188
189     public static final String JavaDoc PROP_JOB_STORE_USE_PROP = "org.quartz.jobStore.useProperties";
190
191     public static final String JavaDoc PROP_DATASOURCE_PREFIX = "org.quartz.dataSource";
192
193     public static final String JavaDoc PROP_CONNECTION_PROVIDER_CLASS = "connectionProvider.class";
194
195     public static final String JavaDoc PROP_DATASOURCE_DRIVER = "driver";
196
197     public static final String JavaDoc PROP_DATASOURCE_URL = "URL";
198
199     public static final String JavaDoc PROP_DATASOURCE_USER = "user";
200
201     public static final String JavaDoc PROP_DATASOURCE_PASSWORD = "password";
202
203     public static final String JavaDoc PROP_DATASOURCE_MAX_CONNECTIONS = "maxConnections";
204
205     public static final String JavaDoc PROP_DATASOURCE_VALIDATION_QUERY = "validationQuery";
206
207     public static final String JavaDoc PROP_DATASOURCE_JNDI_URL = "jndiURL";
208
209     public static final String JavaDoc PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP = "jndiAlwaysLookup";
210
211     public static final String JavaDoc PROP_DATASOURCE_JNDI_INITIAL = "java.naming.factory.initial";
212
213     public static final String JavaDoc PROP_DATASOURCE_JNDI_PROVDER = "java.naming.provider.url";
214
215     public static final String JavaDoc PROP_DATASOURCE_JNDI_PRINCIPAL = "java.naming.security.principal";
216
217     public static final String JavaDoc PROP_DATASOURCE_JNDI_CREDENTIALS = "java.naming.security.credentials";
218
219     public static final String JavaDoc PROP_PLUGIN_PREFIX = "org.quartz.plugin";
220
221     public static final String JavaDoc PROP_PLUGIN_CLASS = "class";
222
223     public static final String JavaDoc PROP_JOB_LISTENER_PREFIX = "org.quartz.jobListener";
224
225     public static final String JavaDoc PROP_TRIGGER_LISTENER_PREFIX = "org.quartz.triggerListener";
226
227     public static final String JavaDoc PROP_LISTENER_CLASS = "class";
228
229     public static final String JavaDoc DEFAULT_INSTANCE_ID = "NON_CLUSTERED";
230
231     public static final String JavaDoc AUTO_GENERATE_INSTANCE_ID = "AUTO";
232
233     /*
234      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235      *
236      * Data members.
237      *
238      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239      */

240
241     private SchedulerException initException = null;
242
243     private String JavaDoc propSrc = null;
244
245     private PropertiesParser cfg;
246
247     private final Log log = LogFactory.getLog(getClass());
248
249     // private Scheduler scheduler;
250

251     /*
252      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253      *
254      * Constructors.
255      *
256      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257      */

258
259     /**
260      * Create an uninitialized StdSchedulerFactory.
261      */

262     public StdSchedulerFactory() {
263     }
264
265     /**
266      * Create a StdSchedulerFactory that has been initialized via
267      * <code>{@link #initialize(Properties)}</code>.
268      *
269      * @see #initialize(Properties)
270      */

271     public StdSchedulerFactory(Properties JavaDoc props) throws SchedulerException {
272         initialize(props);
273     }
274
275     /**
276      * Create a StdSchedulerFactory that has been initialized via
277      * <code>{@link #initialize(String)}</code>.
278      *
279      * @see #initialize(String)
280      */

281     public StdSchedulerFactory(String JavaDoc fileName) throws SchedulerException {
282         initialize(fileName);
283     }
284
285     /*
286      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287      *
288      * Interface.
289      *
290      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291      */

292
293     public Log getLog() {
294         return log;
295     }
296
297     /**
298      * <p>
299      * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with
300      * the contents of a <code>Properties</code> file and overriding System
301      * properties.
302      * </p>
303      *
304      * <p>
305      * By default a properties file named "quartz.properties" is loaded from
306      * the 'current working directory'. If that fails, then the
307      * "quartz.properties" file located (as a resource) in the org/quartz
308      * package is loaded. If you wish to use a file other than these defaults,
309      * you must define the system property 'org.quartz.properties' to point to
310      * the file you want.
311      * </p>
312      *
313      * <p>
314      * System properties (environment variables, and -D definitions on the
315      * command-line when running the JVM) override any properties in the
316      * loaded file. For this reason, you may want to use a different initialize()
317      * method if your application security policy prohibits access to
318      * <code>{@link java.lang.System#getProperties()}</code>.
319      * </p>
320      */

321     public void initialize() throws SchedulerException {
322         // short-circuit if already initialized
323
if (cfg != null) {
324             return;
325         }
326         if (initException != null) {
327             throw initException;
328         }
329
330         String JavaDoc requestedFile = System.getProperty(PROPERTIES_FILE);
331         String JavaDoc propFileName = requestedFile != null ? requestedFile
332                 : "quartz.properties";
333         File JavaDoc propFile = new File JavaDoc(propFileName);
334
335         Properties JavaDoc props = new Properties JavaDoc();
336
337         if (propFile.exists()) {
338             try {
339                 if (requestedFile != null) {
340                     propSrc = "specified file: '" + requestedFile + "'";
341                 } else {
342                     propSrc = "default file in current working dir: 'quartz.properties'";
343                 }
344
345                 props.load(new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(
346                         propFileName)));
347
348             } catch (IOException JavaDoc ioe) {
349                 initException = new SchedulerException("Properties file: '"
350                         + propFileName + "' could not be read.", ioe);
351                 throw initException;
352             }
353         } else if (requestedFile != null) {
354             InputStream JavaDoc in =
355                 Thread.currentThread().getContextClassLoader().getResourceAsStream(requestedFile);
356
357             if(in == null) {
358                 initException = new SchedulerException("Properties file: '"
359                     + requestedFile + "' could not be found.");
360                 throw initException;
361             }
362             
363             propSrc = "specified file: '" + requestedFile + "' in the class resource path.";
364             
365             try {
366                 props.load(new BufferedInputStream JavaDoc(in));
367             } catch (IOException JavaDoc ioe) {
368                 initException = new SchedulerException("Properties file: '"
369                         + requestedFile + "' could not be read.", ioe);
370                 throw initException;
371             }
372             
373         } else {
374             propSrc = "default resource file in Quartz package: 'quartz.properties'";
375
376             InputStream JavaDoc in = getClass().getClassLoader().getResourceAsStream(
377                     "quartz.properties");
378
379             if (in == null) {
380                 in = getClass().getClassLoader().getResourceAsStream(
381                         "/quartz.properties");
382             }
383             if (in == null) {
384                 in = getClass().getClassLoader().getResourceAsStream(
385                         "org/quartz/quartz.properties");
386             }
387             if (in == null) {
388                 initException = new SchedulerException(
389                         "Default quartz.properties not found in class path");
390                 throw initException;
391             }
392             try {
393                 props.load(in);
394             } catch (IOException JavaDoc ioe) {
395                 initException = new SchedulerException(
396                         "Resource properties file: 'org/quartz/quartz.properties' "
397                                 + "could not be read from the classpath.", ioe);
398                 throw initException;
399             }
400         }
401         
402         initialize(overrideWithSysProps(props));
403     }
404
405     /**
406      * Add all System properties to the given <code>props</code>. Will override
407      * any properties that already exist in the given <code>props</code>.
408      */

409     private Properties JavaDoc overrideWithSysProps(Properties JavaDoc props) {
410         Properties JavaDoc sysProps = null;
411         try {
412             sysProps = System.getProperties();
413         } catch (AccessControlException JavaDoc e) {
414             getLog().warn(
415                 "Skipping overriding quartz properties with System properties " +
416                 "during initialization because of an AccessControlException. " +
417                 "This is likely due to not having read/write access for " +
418                 "java.util.PropertyPermission as required by java.lang.System.getProperties(). " +
419                 "To resolve this warning, either add this permission to your policy file or " +
420                 "use a non-default version of initialize().",
421                 e);
422         }
423         
424         if (sysProps != null) {
425             props.putAll(sysProps);
426         }
427
428         return props;
429     }
430
431     /**
432      * <p>
433      * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with
434      * the contenents of the <code>Properties</code> file with the given
435      * name.
436      * </p>
437      */

438     public void initialize(String JavaDoc filename) throws SchedulerException {
439         // short-circuit if already initialized
440
if (cfg != null) {
441             return;
442         }
443         
444         if (initException != null) {
445             throw initException;
446         }
447
448         InputStream JavaDoc is = null;
449         Properties JavaDoc props = new Properties JavaDoc();
450
451         is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
452          
453         try {
454             if(is != null) {
455                 is = new BufferedInputStream JavaDoc(is);
456                 propSrc = "the specified file : '" + filename + "' from the class resource path.";
457             } else {
458                 is = new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(filename));
459                 propSrc = "the specified file : '" + filename + "'";
460             }
461             props.load(is);
462         } catch (IOException JavaDoc ioe) {
463             initException = new SchedulerException("Properties file: '"
464                     + filename + "' could not be read.", ioe);
465             throw initException;
466         }
467
468         initialize(props);
469     }
470
471     /**
472      * <p>
473      * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with
474      * the contenents of the <code>Properties</code> file opened with the
475      * given <code>InputStream</code>.
476      * </p>
477      */

478     public void initialize(InputStream JavaDoc propertiesStream)
479         throws SchedulerException {
480         // short-circuit if already initialized
481
if (cfg != null) {
482             return;
483         }
484         
485         if (initException != null) {
486             throw initException;
487         }
488
489         Properties JavaDoc props = new Properties JavaDoc();
490
491         if (propertiesStream != null) {
492             try {
493                 props.load(propertiesStream);
494                 propSrc = "an externally opened InputStream.";
495             } catch (IOException JavaDoc e) {
496                 initException = new SchedulerException(
497                         "Error loading property data from InputStream", e);
498                 throw initException;
499             }
500         } else {
501             initException = new SchedulerException(
502                     "Error loading property data from InputStream - InputStream is null.");
503             throw initException;
504         }
505
506         initialize(props);
507     }
508
509     /**
510      * <p>
511      * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with
512      * the contenents of the given <code>Properties</code> object.
513      * </p>
514      */

515     public void initialize(Properties JavaDoc props) throws SchedulerException {
516         if (propSrc == null) {
517             propSrc = "an externally provided properties instance.";
518         }
519
520         this.cfg = new PropertiesParser(props);
521     }
522
523     private Scheduler instantiate() throws SchedulerException {
524         if (cfg == null) {
525             initialize();
526         }
527
528         if (initException != null) {
529             throw initException;
530         }
531
532         JobStore js = null;
533         ThreadPool tp = null;
534         QuartzScheduler qs = null;
535         SchedulingContext schedCtxt = null;
536         DBConnectionManager dbMgr = null;
537         String JavaDoc instanceIdGeneratorClass = null;
538         Properties JavaDoc tProps = null;
539         String JavaDoc userTXLocation = null;
540         boolean wrapJobInTx = false;
541         boolean autoId = false;
542         long idleWaitTime = -1;
543         long dbFailureRetry = -1;
544         String JavaDoc classLoadHelperClass;
545         String JavaDoc jobFactoryClass;
546
547         SchedulerRepository schedRep = SchedulerRepository.getInstance();
548
549         // Get Scheduler Properties
550
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
551

552         String JavaDoc schedName = cfg.getStringProperty(PROP_SCHED_INSTANCE_NAME,
553                 "QuartzScheduler");
554
555         String JavaDoc threadName = cfg.getStringProperty(PROP_SCHED_THREAD_NAME,
556                 schedName + "_QuartzSchedulerThread");
557         
558         String JavaDoc schedInstId = cfg.getStringProperty(PROP_SCHED_INSTANCE_ID,
559                 DEFAULT_INSTANCE_ID);
560
561         if (schedInstId.equals(AUTO_GENERATE_INSTANCE_ID)) {
562             autoId = true;
563             instanceIdGeneratorClass = cfg.getStringProperty(
564                     PROP_SCHED_INSTANCE_ID_GENERATOR_CLASS,
565                     "org.quartz.simpl.SimpleInstanceIdGenerator");
566         }
567         
568         userTXLocation = cfg.getStringProperty(PROP_SCHED_USER_TX_URL,
569                 userTXLocation);
570         if (userTXLocation != null && userTXLocation.trim().length() == 0) {
571             userTXLocation = null;
572         }
573
574         classLoadHelperClass = cfg.getStringProperty(
575                 PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
576                 "org.quartz.simpl.CascadingClassLoadHelper");
577         wrapJobInTx = cfg.getBooleanProperty(PROP_SCHED_WRAP_JOB_IN_USER_TX,
578                 wrapJobInTx);
579
580         jobFactoryClass = cfg.getStringProperty(
581                 PROP_SCHED_JOB_FACTORY_CLASS, null);
582
583         idleWaitTime = cfg.getLongProperty(PROP_SCHED_IDLE_WAIT_TIME,
584                 idleWaitTime);
585         dbFailureRetry = cfg.getLongProperty(
586                 PROP_SCHED_DB_FAILURE_RETRY_INTERVAL, dbFailureRetry);
587
588         boolean makeSchedulerThreadDaemon =
589             cfg.getBooleanProperty(PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON);
590         
591         boolean jmxExport = cfg.getBooleanProperty(PROP_SCHED_JMX_EXPORT);
592         boolean jmxProxy = cfg.getBooleanProperty(PROP_SCHED_JMX_PROXY);
593         String JavaDoc jmxProxyClass = cfg.getStringProperty(PROP_SCHED_JMX_PROXY_CLASS);
594         String JavaDoc jmxObjectName = cfg.getStringProperty(PROP_SCHED_JMX_OBJECT_NAME);
595         
596         boolean rmiExport = cfg.getBooleanProperty(PROP_SCHED_RMI_EXPORT, false);
597         boolean rmiProxy = cfg.getBooleanProperty(PROP_SCHED_RMI_PROXY, false);
598         String JavaDoc rmiHost = cfg.getStringProperty(PROP_SCHED_RMI_HOST, "localhost");
599         int rmiPort = cfg.getIntProperty(PROP_SCHED_RMI_PORT, 1099);
600         int rmiServerPort = cfg.getIntProperty(PROP_SCHED_RMI_SERVER_PORT, -1);
601         String JavaDoc rmiCreateRegistry = cfg.getStringProperty(
602                 PROP_SCHED_RMI_CREATE_REGISTRY,
603                 QuartzSchedulerResources.CREATE_REGISTRY_NEVER);
604         String JavaDoc rmiBindName = cfg.getStringProperty(PROP_SCHED_RMI_BIND_NAME);
605
606         if (jmxProxy && rmiProxy) {
607             throw new SchedulerConfigException("Cannot proxy both RMI and JMX.");
608         }
609         
610         Properties JavaDoc schedCtxtProps = cfg.getPropertyGroup(PROP_SCHED_CONTEXT_PREFIX, true);
611
612         // If Proxying to remote scheduler, short-circuit here...
613
// ~~~~~~~~~~~~~~~~~~
614
if (rmiProxy) {
615
616             if (autoId) {
617                 schedInstId = DEFAULT_INSTANCE_ID;
618             }
619                 
620             schedCtxt = new SchedulingContext();
621             schedCtxt.setInstanceId(schedInstId);
622
623             String JavaDoc uid = (rmiBindName == null) ? QuartzSchedulerResources.getUniqueIdentifier(
624                     schedName, schedInstId) : rmiBindName;
625
626             RemoteScheduler remoteScheduler = new RemoteScheduler(schedCtxt,
627                     uid, rmiHost, rmiPort);
628
629             schedRep.bind(remoteScheduler);
630
631             return remoteScheduler;
632         }
633
634         
635         // Create class load helper
636
ClassLoadHelper loadHelper = null;
637         try {
638             loadHelper = (ClassLoadHelper) loadClass(classLoadHelperClass)
639                     .newInstance();
640         } catch (Exception JavaDoc e) {
641             throw new SchedulerConfigException(
642                     "Unable to instantiate class load helper class: "
643                             + e.getMessage(), e);
644         }
645         loadHelper.initialize();
646         
647         // If Proxying to remote JMX scheduler, short-circuit here...
648
// ~~~~~~~~~~~~~~~~~~
649
if (jmxProxy) {
650             if (autoId) {
651                 schedInstId = DEFAULT_INSTANCE_ID;
652             }
653
654             if (jmxProxyClass == null) {
655                 throw new SchedulerConfigException("No JMX Proxy Scheduler class provided");
656             }
657
658             RemoteMBeanScheduler jmxScheduler = null;
659             try {
660                 jmxScheduler = (RemoteMBeanScheduler)loadHelper.loadClass(jmxProxyClass)
661                         .newInstance();
662             } catch (Exception JavaDoc e) {
663                 throw new SchedulerConfigException(
664                         "Unable to instantiate RemoteMBeanScheduler class.", e);
665             }
666             
667             schedCtxt = new SchedulingContext();
668             schedCtxt.setInstanceId(schedInstId);
669             
670             if (jmxObjectName == null) {
671                 jmxObjectName = QuartzSchedulerResources.generateJMXObjectName(schedName, schedInstId);
672             }
673             
674             jmxScheduler.setSchedulingContext(schedCtxt);
675             jmxScheduler.setSchedulerObjectName(jmxObjectName);
676                         
677             tProps = cfg.getPropertyGroup(PROP_SCHED_JMX_PROXY, true);
678             try {
679                 setBeanProps(jmxScheduler, tProps);
680             } catch (Exception JavaDoc e) {
681                 initException = new SchedulerException("RemoteMBeanScheduler class '"
682                         + jmxProxyClass + "' props could not be configured.", e);
683                 initException.setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
684                 throw initException;
685             }
686             
687             jmxScheduler.initialize();
688             
689             schedRep.bind(jmxScheduler);
690
691             return jmxScheduler;
692         }
693         
694         JobFactory jobFactory = null;
695         if(jobFactoryClass != null) {
696             try {
697                 jobFactory = (JobFactory) loadHelper.loadClass(jobFactoryClass)
698                         .newInstance();
699             } catch (Exception JavaDoc e) {
700                 throw new SchedulerConfigException(
701                         "Unable to instantiate JobFactory class: "
702                                 + e.getMessage(), e);
703             }
704
705             tProps = cfg.getPropertyGroup(PROP_SCHED_JOB_FACTORY_PREFIX, true);
706             try {
707                 setBeanProps(jobFactory, tProps);
708             } catch (Exception JavaDoc e) {
709                 initException = new SchedulerException("JobFactory class '"
710                         + jobFactoryClass + "' props could not be configured.", e);
711                 initException
712                         .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
713                 throw initException;
714             }
715         }
716         
717         InstanceIdGenerator instanceIdGenerator = null;
718         if(instanceIdGeneratorClass != null) {
719             try {
720                 instanceIdGenerator = (InstanceIdGenerator) loadHelper.loadClass(instanceIdGeneratorClass)
721                     .newInstance();
722             } catch (Exception JavaDoc e) {
723                 throw new SchedulerConfigException(
724                         "Unable to instantiate InstanceIdGenerator class: "
725                         + e.getMessage(), e);
726             }
727             
728             tProps = cfg.getPropertyGroup(PROP_SCHED_INSTANCE_ID_GENERATOR_PREFIX, true);
729             try {
730                 setBeanProps(instanceIdGenerator, tProps);
731             } catch (Exception JavaDoc e) {
732                 initException = new SchedulerException("InstanceIdGenerator class '"
733                         + instanceIdGeneratorClass + "' props could not be configured.", e);
734                 initException
735                         .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
736                 throw initException;
737             }
738         }
739         
740         // Get ThreadPool Properties
741
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
742

743         String JavaDoc tpClass = cfg.getStringProperty(PROP_THREAD_POOL_CLASS, null);
744
745         if (tpClass == null) {
746             initException = new SchedulerException(
747          &nb