KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > scheduling > ScheduleJob


1 package org.oddjob.scheduling;
2
3 import org.oddjob.framework.SimpleJob;
4 import org.oddjob.quartz.QuartzSchedulerJob;
5 import org.oddjob.util.OddjobConfigException;
6
7 /**
8  * @oddjob.description Add schedules to a given scheduler. The schedules provided
9  * are as specified in {@link QuartzSchedulerJob}. This job provides more
10  * freedom as to when things are scheduled than specifying schedules as part of
11  * the scheduler.
12  *
13  * @oddjob.example
14  *
15  * <pre>
16  * &lt;sequential&gt;
17  * &lt;scheduler name="Scheduler" id="scheduler"/&gt;
18  * &lt;folder name="My Jobs"&gt;
19  * &lt;schedule schedule="${scheduler}"&gt;
20  * &lt;schedules&gt;
21  * &lt;ojschedule id="lunch" name="Lunch Reminder" job="${lunch}"&gt;
22  * &lt;schedule&gt;
23  * &lt;time from="12:00"/&gt;
24  * &lt;/schedule&gt;
25  * &lt;/ojschedule&gt;
26  * &lt;/schedules&gt;
27  * &lt;/schedule&gt;
28  * &lt;echo id="lunch" text="Go to Lunch!"/&gt;
29  * &lt;/folder&gt;
30  * &lt;/sequential&gt;
31  * </pre>
32  *
33  * @author Rob Gordon
34  */

35 public class ScheduleJob extends SimpleJob {
36     static final long serialVersionUID = 20050926;
37
38     /**
39      * @oddjob.property
40      * @oddjob.description A list of schedules to add to the scheduler.
41      * @oddjob.required Yes.
42      */

43     private ScheduleInstruction[] schedules;
44     
45     /**
46      * @oddjob.property
47      * @oddjob.description A {@link QuartzSchedulerJob} to add the schedules
48      * to.
49      * @oddjob.required Yes.
50      */

51     private OddjobScheduler scheduler;
52
53     /**
54      * Set the schedules.
55      *
56      * @param schedules
57      */

58     public void setSchedules(ScheduleInstruction[] schedules) {
59         this.schedules = schedules;
60     }
61     
62     /**
63      * Get the schedules.
64      *
65      * @return The schedules.
66      */

67     public ScheduleInstruction[] getSchedules() {
68         return schedules;
69     }
70     
71     /*
72      * (non-Javadoc)
73      * @see org.oddjob.framework.SimpleJob#execute()
74      */

75     protected int execute() throws Exception JavaDoc {
76         if (scheduler == null) {
77             throw new OddjobConfigException("No scheduler specified.");
78         }
79         if (schedules == null) {
80             logger().debug("Nothing to schedule.");
81             return 0;
82         }
83         for (int i = 0; i < schedules.length; ++i) {
84             scheduler.schedule(schedules[i]);
85         }
86         return 0;
87     }
88     
89     /**
90      * @return Returns the scheduler.
91      */

92     public OddjobScheduler getScheduler() {
93         return scheduler;
94     }
95     /**
96      * @param scheduler The scheduler to set.
97      */

98     public void setScheduler(OddjobScheduler scheduler) {
99         this.scheduler = scheduler;
100     }
101 }
102
103
Popular Tags