|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.scheduling.quartz.SchedulerFactoryBean
FactoryBean that sets up a Quartz Scheduler and exposes it for bean references.
Allows registration of JobDetails, Calendars and Triggers, automatically starting the scheduler on initialization and shutting it down on destruction. In typical scenarios, there is no need to access the Scheduler instance itself in application code.
Note that Quartz instantiates a new Job for each execution, in contrast to Timer which uses a TimerTask instance that is shared between repeated executions. Just JobDetail descriptors are shared.
Spring's Quartz support was developed against Quartz 1.3.
Scheduler
,
StdSchedulerFactory
Nested Class Summary | |
static class |
SchedulerFactoryBean.DelayedSchedulerStartException
Exception to be thrown if the Quartz scheduler cannot be started after the specified delay has passed. |
Field Summary | |
static int |
DEFAULT_THREAD_COUNT
|
protected org.apache.commons.logging.Log |
logger
|
static java.lang.String |
PROP_THREAD_COUNT
|
Constructor Summary | |
SchedulerFactoryBean()
|
Method Summary | |
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
protected org.quartz.Scheduler |
createScheduler(org.quartz.SchedulerFactory schedulerFactory,
java.lang.String schedulerName)
Create the Scheduler instance for the given factory and scheduler name. |
void |
destroy()
This implementation shuts down the Quartz scheduler, stopping all scheduled jobs. |
java.lang.Object |
getObject()
Return an instance (possibly shared or independent) of the object managed by this factory. |
java.lang.Class |
getObjectType()
Return the type of object that this FactoryBean creates, or null if not known in advance. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in. |
void |
setApplicationContextSchedulerContextKey(java.lang.String applicationContextSchedulerContextKey)
Set the key of an ApplicationContext reference to expose in the SchedulerContext, for example "applicationContext". |
void |
setAutoStartup(boolean autoStartup)
Set whether to automatically start the scheduler after initialization. |
void |
setCalendars(java.util.Map calendars)
Register a list of Quartz Calendar objects with the Scheduler that this FactoryBean creates, to be referenced by Triggers. |
void |
setConfigLocation(Resource configLocation)
Set the location of the Quartz properties config file, for example as classpath resource "classpath:quartz.properties". |
void |
setDataSource(javax.sql.DataSource dataSource)
Set the DataSource to be used by the Scheduler. |
void |
setJobDetails(org.quartz.JobDetail[] jobDetails)
Register a list of JobDetail objects with the Scheduler that this FactoryBean creates, to be referenced by Triggers. |
void |
setJobSchedulingDataLocation(java.lang.String jobSchedulingDataLocation)
Set the location of a Quartz job definition XML file that follows the "job_scheduling_data_1_0" DTD. |
void |
setJobSchedulingDataLocations(java.lang.String[] jobSchedulingDataLocations)
Set the locations of Quartz job definition XML files that follow the "job_scheduling_data_1_0" DTD. |
void |
setOverwriteExistingJobs(boolean overwriteExistingJobs)
Set whether any jobs defined on this SchedulerFactoryBean should overwrite existing job definitions. |
void |
setQuartzProperties(java.util.Properties quartzProperties)
Set Quartz properties, like "org.quartz.threadPool.class". |
void |
setSchedulerContextAsMap(java.util.Map schedulerContextAsMap)
Register objects in the Scheduler context via a given Map. |
void |
setSchedulerFactoryClass(java.lang.Class schedulerFactoryClass)
Set the Quartz SchedulerFactory implementation to use. |
void |
setSchedulerName(java.lang.String schedulerName)
Set the name of the Scheduler to fetch from the SchedulerFactory. |
void |
setStartupDelay(int startupDelay)
Set the number of seconds to wait after initialization before starting the scheduler asynchronously. |
void |
setTransactionManager(PlatformTransactionManager transactionManager)
Set the transaction manager to be used for registering jobs and triggers that are defined by this SchedulerFactoryBean. |
void |
setTriggers(org.quartz.Trigger[] triggers)
Register a list of Trigger objects with the Scheduler that this FactoryBean creates. |
void |
setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Set whether to wait for running jobs to complete on shutdown. |
protected void |
startScheduler(org.quartz.Scheduler scheduler,
int startupDelay)
Start the Quartz Scheduler, respecting the "startupDelay" setting. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String PROP_THREAD_COUNT
public static final int DEFAULT_THREAD_COUNT
protected final org.apache.commons.logging.Log logger
Constructor Detail |
public SchedulerFactoryBean()
Method Detail |
public void setSchedulerFactoryClass(java.lang.Class schedulerFactoryClass)
Default is StdSchedulerFactory, reading in the standard quartz.properties from quartz.jar. To use custom Quartz properties, specify "configLocation" or "quartzProperties".
StdSchedulerFactory
,
setConfigLocation(org.springframework.core.io.Resource)
,
setQuartzProperties(java.util.Properties)
public void setSchedulerName(java.lang.String schedulerName)
SchedulerFactory.getScheduler(String)
,
SchedulerFactory.getScheduler()
public void setConfigLocation(Resource configLocation)
Note: Can be omitted when all necessary properties are specified locally via this bean, or when relying on Quartz' default configuration.
setQuartzProperties(java.util.Properties)
public void setQuartzProperties(java.util.Properties quartzProperties)
Can be used to override values in a Quartz properties config file, or to specify all necessary properties locally.
setConfigLocation(org.springframework.core.io.Resource)
public void setDataSource(javax.sql.DataSource dataSource)
Note: If this is set, the Quartz settings should not define a job store "dataSource" to avoid meaningless double configuration.
setQuartzProperties(java.util.Properties)
,
setTransactionManager(org.springframework.transaction.PlatformTransactionManager)
,
LocalDataSourceJobStore
public void setTransactionManager(PlatformTransactionManager transactionManager)
setDataSource(javax.sql.DataSource)
public void setSchedulerContextAsMap(java.util.Map schedulerContextAsMap)
Note: When using persistent Jobs whose JobDetail will be kept in the database, do not put Spring-managed beans or an ApplicationContext reference into the JobDataMap but rather into the SchedulerContext.
schedulerContextAsMap
- Map with String keys and any objects as
values (for example Spring-managed beans)JobDetailBean.setJobDataAsMap(java.util.Map)
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ResourceLoaderAware's setResourceLoader.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- ApplicationContext object to be used by this objectBeanInitializationException
public void setApplicationContextSchedulerContextKey(java.lang.String applicationContextSchedulerContextKey)
Note: When using persistent Jobs whose JobDetail will be kept in the database, do not put an ApplicationContext reference into the JobDataMap but rather into the SchedulerContext.
In case of a QuartzJobBean, the reference will be applied to the Job instance as bean property. An "applicationContext" attribute will correspond to a "setApplicationContext" method in that scenario.
Note that BeanFactory callback interfaces like ApplicationContextAware are not automatically applied to Quartz Job instances, because Quartz itself is reponsible for the lifecycle of its Jobs.
JobDetailBean.setApplicationContextJobDataKey(java.lang.String)
,
ApplicationContext
public void setOverwriteExistingJobs(boolean overwriteExistingJobs)
public void setJobSchedulingDataLocation(java.lang.String jobSchedulingDataLocation)
ResourceJobSchedulingDataProcessor
,
JobSchedulingDataProcessor
public void setJobSchedulingDataLocations(java.lang.String[] jobSchedulingDataLocations)
ResourceJobSchedulingDataProcessor
,
JobSchedulingDataProcessor
public void setJobDetails(org.quartz.JobDetail[] jobDetails)
This is not necessary when a Trigger determines the JobDetail itself: In this case, the JobDetail will be implicitly registered in combination with the Trigger.
setTriggers(org.quartz.Trigger[])
,
JobDetail
,
JobDetailBean
,
JobDetailAwareTrigger
,
Trigger.setJobName(java.lang.String)
public void setCalendars(java.util.Map calendars)
calendars
- Map with calendar names as keys as Calendar
objects as valuesCalendar
,
Trigger.setCalendarName(java.lang.String)
public void setTriggers(org.quartz.Trigger[] triggers)
If the Trigger determines the corresponding JobDetail itself, the job will be automatically registered with the Scheduler. Else, the respective JobDetail needs to be registered via the "jobDetails" property of this FactoryBean.
setJobDetails(org.quartz.JobDetail[])
,
JobDetail
,
JobDetailAwareTrigger
,
CronTriggerBean
,
SimpleTriggerBean
public void setAutoStartup(boolean autoStartup)
public void setStartupDelay(int startupDelay)
Setting this to 10 or 20 seconds makes sense if no jobs should be run before the entire application has started up.
public void setWaitForJobsToCompleteOnShutdown(boolean waitForJobsToCompleteOnShutdown)
Scheduler.shutdown(boolean)
public void afterPropertiesSet() throws java.lang.Exception
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
java.lang.Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected org.quartz.Scheduler createScheduler(org.quartz.SchedulerFactory schedulerFactory, java.lang.String schedulerName) throws org.quartz.SchedulerException
Default implementation invokes the corresponding getScheduler methods of SchedulerFactory. Can be overridden for custom Scheduler creation.
schedulerFactory
- the factory to create the Scheduler withschedulerName
- the name of the scheduler to create
org.quartz.SchedulerException
- if thrown by Quartz methodsafterPropertiesSet()
,
SchedulerFactory.getScheduler()
,
SchedulerFactory.getScheduler(String)
protected void startScheduler(org.quartz.Scheduler scheduler, int startupDelay) throws org.quartz.SchedulerException
scheduler
- the Scheduler to startstartupDelay
- the number of seconds to wait before starting
the Scheduler asynchronously
org.quartz.SchedulerException
public java.lang.Object getObject()
FactoryBean
getObject
in interface FactoryBean
public java.lang.Class getObjectType()
FactoryBean
For a singleton, this can simply return getObject().getClass(), or even null, as autowiring will always check the actual objects for singletons. For prototypes, returning a meaningful type here is highly advisable, as autowiring will simply ignore them else.
getObjectType
in interface FactoryBean
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)
public boolean isSingleton()
FactoryBean
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.
isSingleton
in interface FactoryBean
public void destroy() throws org.quartz.SchedulerException
destroy
in interface DisposableBean
org.quartz.SchedulerException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |