org.quartz.ee.servlet
Class QuartzInitializerListener

java.lang.Object
  extended by org.quartz.ee.servlet.QuartzInitializerListener
All Implemented Interfaces:
EventListener, javax.servlet.ServletContextListener

public class QuartzInitializerListener
extends Object
implements javax.servlet.ServletContextListener

A ServletContextListner that can be used to initialize Quartz.

You'll want to add something like this to your WEB-INF/web.xml file:

     <context-param>
         <param-name>quartz:config-file</param-name>
         <param-value>/some/path/my_quartz.properties</param-value>
     </context-param>
     <context-param>
         <param-name>quartz:shutdown-on-unload</param-name>
         <param-value>true</param-value>
     </context-param>
     <context-param>
         <param-name>quartz:wait-on-shutdown</param-name>
         <param-value>true</param-value>
     </context-param>
     <context-param>
         <param-name>quartz:start-on-load</param-name>
         <param-value>true</param-value>
     </context-param>
     
     <listener>
         <listener-class>
             org.quartz.ee.servlet.QuartzInitializerListener
         </listener-class>
     </listener>
 

The init parameter 'quartz:config-file' can be used to specify the path (and filename) of your Quartz properties file. If you leave out this parameter, the default ("quartz.properties") will be used.

The init parameter 'quartz:shutdown-on-unload' can be used to specify whether you want scheduler.shutdown() called when the listener is unloaded (usually when the application server is being shutdown). Possible values are "true" or "false". The default is "true".

The init parameter 'quartz:wait-on-shutdown' has effect when 'quartz:shutdown-on-unload' is specified "true", and indicates whether you want scheduler.shutdown(true) called when the listener is unloaded (usually when the application server is being shutdown). Passing "true" to the shutdown() call causes the scheduler to wait for existing jobs to complete. Possible values are "true" or "false". The default is "false".

The init parameter 'quartz:start-on-load' can be used to specify whether you want the scheduler.start() method called when the listener is first loaded. If set to false, your application will need to call the start() method before the scheduler begins to run and process jobs. Possible values are "true" or "false". The default is "true", which means the scheduler is started.

A StdSchedulerFactory instance is stored into the ServletContext. You can gain access to the factory from a ServletContext instance like this:
 StdSchedulerFactory factory = (StdSchedulerFactory) ctx
                .getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);

The init parameter 'quartz:servlet-context-factory-key' can be used to override the name under which the StdSchedulerFactory is stored into the ServletContext, in which case you will want to use this name rather than QuartzInitializerListener.QUARTZ_FACTORY_KEY in the above example.

The init parameter 'quartz:scheduler-context-servlet-context-key' if set, the ServletContext will be stored in the SchedulerContext under the given key name (and will therefore be available to jobs during execution).

The init parameter 'quartz:start-delay-seconds' can be used to specify the amount of time to wait after initializing the scheduler before scheduler.start() is called.

Once you have the factory instance, you can retrieve the Scheduler instance by calling getScheduler() on the factory.

Author:
James House, Chuck Cavaness, John Petrocik

Field Summary
static String QUARTZ_FACTORY_KEY
           
 
Constructor Summary
QuartzInitializerListener()
           
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent sce)
           
 void contextInitialized(javax.servlet.ServletContextEvent sce)
           
protected  StdSchedulerFactory getSchedulerFactory(String configFile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUARTZ_FACTORY_KEY

public static final String QUARTZ_FACTORY_KEY
See Also:
Constant Field Values
Constructor Detail

QuartzInitializerListener

public QuartzInitializerListener()
Method Detail

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent sce)
Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

getSchedulerFactory

protected StdSchedulerFactory getSchedulerFactory(String configFile)
                                           throws SchedulerException
Throws:
SchedulerException

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent sce)
Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener


Copyright 2001-2013, Terracotta, Inc.