org.springframework.scheduling.quartz
Class CronTriggerBean

java.lang.Object
  extended by CronTrigger
      extended by org.springframework.scheduling.quartz.CronTriggerBean
All Implemented Interfaces:
BeanNameAware, InitializingBean, JobDetailAwareTrigger

public class CronTriggerBean
extends CronTrigger
implements JobDetailAwareTrigger, BeanNameAware, InitializingBean

Convenience subclass of Quartz's org.quartz.CronTrigger class, making bean-style usage easier.

CronTrigger itself is already a JavaBean but lacks sensible defaults. This class uses the Spring bean name as job name, the Quartz default group ("DEFAULT") as job group, the current time as start time, and indefinite repetition, if not specified.

This class will also register the trigger with the job name and group of a given org.quartz.JobDetail. This allows SchedulerFactoryBean to automatically register a trigger for the corresponding JobDetail, instead of registering the JobDetail separately.

NOTE: This convenience subclass does not work with trigger persistence in Quartz 1.6, due to a change in Quartz's trigger handling. Use Quartz 1.5 if you rely on trigger persistence based on this class, or the standard Quartz org.quartz.CronTrigger class instead.

Since:
18.02.2004
Author:
Juergen Hoeller
See Also:
#setName, #setGroup, #setStartTime, #setJobName, #setJobGroup, setJobDetail(JobDetail), SchedulerAccessor.setTriggers(Trigger[]), SchedulerAccessor.setJobDetails(JobDetail[]), SimpleTriggerBean

Field Summary
private  java.lang.String beanName
           
private static Constants constants
          Constants for the CronTrigger class
private  JobDetail jobDetail
           
private  long startDelay
           
 
Constructor Summary
CronTriggerBean()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
 JobDetail getJobDetail()
          Return the JobDetail that this Trigger is associated with.
 void setBeanName(java.lang.String beanName)
          Set the name of the bean in the bean factory that created this bean.
 void setJobDataAsMap(java.util.Map jobDataAsMap)
          Register objects in the JobDataMap via a given Map.
 void setJobDetail(JobDetail jobDetail)
          Set the JobDetail that this trigger should be associated with.
 void setMisfireInstructionName(java.lang.String constantName)
          Set the misfire instruction via the name of the corresponding constant in the org.quartz.CronTrigger class.
 void setStartDelay(long startDelay)
          Set the start delay in milliseconds.
 void setTriggerListenerNames(java.lang.String[] names)
          Set a list of TriggerListener names for this job, referring to non-global TriggerListeners registered with the Scheduler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constants

private static final Constants constants
Constants for the CronTrigger class


jobDetail

private JobDetail jobDetail

beanName

private java.lang.String beanName

startDelay

private long startDelay
Constructor Detail

CronTriggerBean

public CronTriggerBean()
Method Detail

setJobDataAsMap

public void setJobDataAsMap(java.util.Map jobDataAsMap)
Register objects in the JobDataMap via a given Map.

These objects will be available to this Trigger only, in contrast to objects in the JobDetail's data map.

Parameters:
jobDataAsMap - Map with String keys and any objects as values (for example Spring-managed beans)
See Also:
JobDetailBean.setJobDataAsMap(java.util.Map)

setMisfireInstructionName

public void setMisfireInstructionName(java.lang.String constantName)
Set the misfire instruction via the name of the corresponding constant in the org.quartz.CronTrigger class. Default is MISFIRE_INSTRUCTION_SMART_POLICY.

See Also:
org.quartz.CronTrigger#MISFIRE_INSTRUCTION_FIRE_ONCE_NOW, org.quartz.CronTrigger#MISFIRE_INSTRUCTION_DO_NOTHING, org.quartz.Trigger#MISFIRE_INSTRUCTION_SMART_POLICY

setTriggerListenerNames

public void setTriggerListenerNames(java.lang.String[] names)
Set a list of TriggerListener names for this job, referring to non-global TriggerListeners registered with the Scheduler.

A TriggerListener name always refers to the name returned by the TriggerListener implementation.

See Also:
SchedulerAccessor.setTriggerListeners(TriggerListener[]), org.quartz.TriggerListener#getName

setJobDetail

public void setJobDetail(JobDetail jobDetail)
Set the JobDetail that this trigger should be associated with.

This is typically used with a bean reference if the JobDetail is a Spring-managed bean. Alternatively, the trigger can also be associated with a job by name and group.

See Also:
#setJobName, #setJobGroup

setStartDelay

public void setStartDelay(long startDelay)
Set the start delay in milliseconds.

The start delay is added to the current system time (when the bean starts) to control the start time of the trigger.

If the start delay is non-zero it will always take precedence over start time.

Parameters:
startDelay - the start delay, in milliseconds.

getJobDetail

public JobDetail getJobDetail()
Description copied from interface: JobDetailAwareTrigger
Return the JobDetail that this Trigger is associated with.

Specified by:
getJobDetail in interface JobDetailAwareTrigger
Returns:
the associated JobDetail, or null if none

setBeanName

public void setBeanName(java.lang.String beanName)
Description copied from interface: BeanNameAware
Set the name of the bean in the bean factory that created this bean.

Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet() or a custom init-method.

Specified by:
setBeanName in interface BeanNameAware
Parameters:
beanName - the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils.originalBeanName(String) method to extract the original bean name (without suffix), if desired.

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
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.lang.Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.