Overview

This Service functions as a wrapper around the Quartz Scheduler

It is written for use in any Avalon compatible container.

Configuration

First, here is the role configuration.

    
        <role
            name="org.apache.fulcrum.quartz.QuartzService"
            shorthand="quartz"
            default-class="org.apache.fulcrum.quartz.DefaultQuartzService"/>
    
    

Now comes the job configuration:

    
    <quartz>
        <globalJobListener className="org.apache.fulcrum.quartz.listener.FooListener" />
        <scheduled jobName="simpleJob" jobGroup="DEFAULT_GROUP" triggerName="cron" triggerGroup="OTHER_GROUP"/>
        <jobDetails>
            <list>
              <org.quartz.JobDetail>
                <name>simpleJob</name>
                <group>DEFAULT_GROUP</group>
                <jobClass>org.apache.fulcrum.quartz.test.SimpleJob</jobClass>
                <volatility>false</volatility>
                <durability>false</durability>
                <shouldRecover>false</shouldRecover>
                <jobListeners/>
              </org.quartz.JobDetail>
              <org.quartz.JobDetail>
                <name>notSoSimpleJob</name>
                <group>DEFAULT_GROUP</group>
                <jobClass>org.apache.fulcrum.quartz.test.NotSoSimpleJob</jobClass>
                <volatility>false</volatility>
                <durability>false</durability>
                <shouldRecover>false</shouldRecover>
                <jobListeners/>
              </org.quartz.JobDetail>
            </list>
        </jobDetails>
        <triggers>
            <list>
              <org.quartz.CronTrigger>
                <startTime>2005-10-20 11:10:45.0 EDT</startTime>
                <misfireInstruction>0</misfireInstruction>
                <volatility>false</volatility>
                <group>OTHER_GROUP</group>
                <jobGroup>DEFAULT_GROUP</jobGroup>
                <jobName>notSoSimpleJob</jobName>
                <name>cron</name>
                <triggerListeners/>
                <cronEx serialization="custom">
                  <org.quartz.CronExpression>
                    <default>
                      <cronExpression>0 0 12 * * ?</cronExpression>
                    </default>
                  </org.quartz.CronExpression>
                </cronEx>
              </org.quartz.CronTrigger>
              <org.quartz.SimpleTrigger>
                <name>simpleTrigger</name>
                <group>DEFAULT_GROUP</group>
                <description>test</description>
              </org.quartz.SimpleTrigger>
            </list>
        </triggers>
    </quartz>
    
    

Note: The section for CronTrigger has to date varied with Quartz releases (the one above is suitable for Quartz 1.5.2). The format depends on how XStream processes the serialized form of CronTrigger .

Refer to the Quartz JavaDoc for details of the serialized form of the other configuration elements.

Usage

Scheduled tasks are quite straightforward to create. The only requirement is that the interface org.quartz.Job be implemented. This requires just that one method be defined, execute(), whose org.quartz.JobExecutionContext argument provides you with details of the execution context when the task is triggered.

    
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class SimpleJob implements Job
{
	public static boolean executed = false;

    public SimpleJob()
    {
        super();
    }

    public void execute(JobExecutionContext context)
        throws JobExecutionException
    {
        executed = true;
    }
}
    
    

An additional example can be found in the unit tests for this component.