org.springframework.scheduling.quartz
Class SchedulerFactoryBean

java.lang.Object
  extended byorg.springframework.scheduling.quartz.SchedulerFactoryBean
All Implemented Interfaces:
DisposableBean, FactoryBean, InitializingBean

public class SchedulerFactoryBean
extends java.lang.Object
implements FactoryBean, InitializingBean, DisposableBean

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.

Since:
18.02.2004
Version:
$Id: SchedulerFactoryBean.java,v 1.8 2004/03/18 02:46:09 trisberg Exp $
Author:
Juergen Hoeller
See Also:
Scheduler, StdSchedulerFactory

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
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? That is, will getObject() always return the same object?
 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 setJobDetails(org.quartz.JobDetail[] jobDetails)
          Register a list of JobDetail objects with the Scheduler that this FactoryBean creates, to be referenced by Triggers.
 void setQuartzProperties(java.util.Properties quartzProperties)
          Set Quartz properties, like "org.quartz.threadPool.class".
 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 setTriggers(org.quartz.Trigger[] triggers)
          Register a list of Trigger objects with the Scheduler that this FactoryBean creates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

SchedulerFactoryBean

public SchedulerFactoryBean()
Method Detail

setSchedulerFactoryClass

public void setSchedulerFactoryClass(java.lang.Class schedulerFactoryClass)
Set the Quartz SchedulerFactory implementation to use.

Default is StdSchedulerFactory, reading in the standard quartz.properties from quartz.jar. To use custom Quartz properties, specify "configLocation" or "quartzProperties".

See Also:
StdSchedulerFactory, setConfigLocation(org.springframework.core.io.Resource), setQuartzProperties(java.util.Properties)

setSchedulerName

public void setSchedulerName(java.lang.String schedulerName)
Set the name of the Scheduler to fetch from the SchedulerFactory. If not specified, the default Scheduler will be used.

See Also:
SchedulerFactory.getScheduler(String), SchedulerFactory.getScheduler()

setConfigLocation

public void setConfigLocation(Resource configLocation)
Set the location of the Quartz properties config file, for example as classpath resource "classpath:quartz.properties".

Note: Can be omitted when all necessary properties are specified locally via this bean.


setQuartzProperties

public void setQuartzProperties(java.util.Properties quartzProperties)
Set Quartz properties, like "org.quartz.threadPool.class".

Can be used to override values in a Quartz properties config file, or to specify all necessary properties locally.


setJobDetails

public void setJobDetails(org.quartz.JobDetail[] jobDetails)
Register a list of JobDetail objects with the Scheduler that this FactoryBean creates, to be referenced by Triggers.

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.

See Also:
setTriggers(org.quartz.Trigger[]), JobDetail, JobDetailBean, JobDetailAwareTrigger, Trigger.setJobName(java.lang.String)

setCalendars

public 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.

Parameters:
calendars - Map with calendar names as keys as Calendar objects as values
See Also:
Calendar, Trigger.setCalendarName(java.lang.String)

setTriggers

public void setTriggers(org.quartz.Trigger[] triggers)
Register a list of Trigger objects with the Scheduler that this FactoryBean creates.

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.

See Also:
setJobDetails(org.quartz.JobDetail[]), JobDetail, JobDetailAwareTrigger, CronTriggerBean, SimpleTriggerBean

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.io.IOException,
                               org.quartz.SchedulerException
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

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.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
java.io.IOException
org.quartz.SchedulerException

createScheduler

protected org.quartz.Scheduler createScheduler(org.quartz.SchedulerFactory schedulerFactory,
                                               java.lang.String schedulerName)
                                        throws org.quartz.SchedulerException
Create the Scheduler instance for the given factory and scheduler name. Called by afterPropertiesSet.

Default implementation invokes the corresponding getScheduler methods of SchedulerFactory. Can be overridden for custom Scheduler creation.

Parameters:
schedulerFactory - the factory to create the Scheduler with
schedulerName - the name of the scheduler to create
Returns:
the Scheduler instance
Throws:
org.quartz.SchedulerException - if thrown by Quartz methods
See Also:
afterPropertiesSet(), SchedulerFactory.getScheduler(), SchedulerFactory.getScheduler(String)

getObject

public java.lang.Object getObject()
Description copied from interface: FactoryBean
Return an instance (possibly shared or independent) of the object managed by this factory. As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.

Specified by:
getObject in interface FactoryBean
Returns:
an instance of the bean (should never be null)

getObjectType

public java.lang.Class getObjectType()
Description copied from interface: FactoryBean
Return the type of object that this FactoryBean creates, or null if not known in advance. This allows to check for specific types of beans without instantiating objects, e.g. on autowiring.

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.

Specified by:
getObjectType in interface FactoryBean
Returns:
the type of object that this FactoryBean creates, or null
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object?

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.

Specified by:
isSingleton in interface FactoryBean
Returns:
if this bean is a singleton

destroy

public void destroy()
             throws org.quartz.SchedulerException
This implementation shuts down the Quartz scheduler, stopping all scheduled jobs.

Specified by:
destroy in interface DisposableBean
Throws:
org.quartz.SchedulerException


Copyright (C) 2003-2004 The Spring Framework Project.