KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.scheduling;
5
6 import org.oddjob.schedules.Schedule;
7
8 /**
9  * @oddjob.description A schedule instruction that provides a very flexible,
10  * intuative and business orientated approach to scheduling.
11  * <p>
12  * In addition to a regular schedule, an optional retry schedule can be
13  * specified. If the scheduled job doesn't complete or flags an exception the
14  * retry schedule will be used to schedule the next execution.
15  * <p>
16  * When the schedule specifies an interval, the regular schedule will be
17  * scheduled at the beginning of the schedule, the retry will be schedule at
18  * the end of the interval. In the example below the job will be scheduled at
19  * 10am, and if it fails 10:15, 10:30 etc.
20  * </p>
21  * <p>
22  * This schedule takes advantage of schedules being defined as intervals by
23  * using the from/to time in the event that the scheduler wasn't running
24  * at exactly the due time and the scheduler isn't a type that saves state.
25  * The schedule could be specified using on="10:00", but if the scheduler
26  * doesn't use a persistant store and is started at 1pm the job will not be
27  * scheduled until 10am the next day. Setting the to="17:00" means that if the
28  * shceduler is started at 1pm the job will be scheduled immediately as if
29  * it started at 10am that same day.
30  * <p>
31  * If the scheduler saves state then this schdule will always run
32  * from the last completed time. If the job last completed on Monday
33  * at 10am but the scheduler isn't started until Wednesday at 1pm the schedule
34  * will run immediately as if scheduled at 10am Tuesday, then immedately
35  * again as if scheduled at 10am Wednesday.
36  * <p>
37  *
38  * @oddjob.example
39  *
40  * <pre>
41  * &lt;ojschedule job="${ajob}" &gt;
42  * &lt;schedule&gt;
43  * &lt;dayofweek from="mon" to="fri" &gt;
44  * &lt;time from="10:00" to="17:00" /&gt;
45  * &lt;/dayofweek&gt;
46  * &lt;schedule&gt;
47  * &lt;retry&gt;
48  * &lt;interval interval="00:15" /&gt;
49  * &lt;/retry&gt;
50  * &lt;/ojschedule&gt;
51  * </pre>
52  *
53  * Also see the scheduling example.
54  *
55  * @author Rob Gordon.
56  */

57 public class OJScheduleInstruction extends ScheduleInstruction {
58     private static final long serialVersionUID = 20051119;
59     
60     /**
61      * @oddjob.property schedule
62      * @oddjob.description The regular schedule which is a
63      * {@link org.oddjob.schedules.ScheduleElement} type.
64      * @oddjob.required Yes.
65      */

66     private Schedule normalSchedule;
67
68     /**
69      * @oddjob.property retry
70      * @oddjob.description The schedule used in the event
71      * that the child job doesn't complete or is in an
72      * exception state. This is a
73      * {@link org.oddjob.schedules.ScheduleElement} type.
74      * @oddjob.required No.
75      */

76     private Schedule retrySchedule;
77     
78     /**
79      * @oddjob.property
80      * @oddjob.description The time zone the schedule is to run
81      * in. This is the text id of the time zone, such as "Europe/London".
82      * More information can be found at
83      * <a HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html">
84      * TimeZone</a>.
85      *
86      * @oddjob.required No.
87      */

88     private String JavaDoc timeZone;
89
90     /**
91      * Set the schedule.
92      *
93      * @param schedule The schedule.
94      */

95     public void setSchedule(Schedule schedule) {
96         this.normalSchedule = schedule;
97     }
98             
99     /**
100      * Get the schedule.
101      *
102      * @return The schedule.
103      */

104     public Schedule getSchedule() {
105         return this.normalSchedule;
106     }
107             
108     /**
109      * Set the retry schedule.
110      *
111      * @param retry
112      */

113     public void setRetry(Schedule retry) {
114         this.retrySchedule = retry;
115     }
116             
117     /**
118      * Get the retry schedule.
119      *
120      * @return The retry schedule.
121      */

122     public Schedule getRetry() {
123         return retrySchedule;
124     }
125             
126
127     /**
128      * Get the time zone id to use in this schedule.
129      *
130      * @return The time zone idbeing used.
131      */

132     public String JavaDoc getTimeZone() {
133         return timeZone;
134     }
135
136     /**
137      * Set the time zone.
138      *
139      * @param timeZoneId the timeZoneId.
140      */

141     public void setTimeZone(String JavaDoc timeZoneId) {
142         this.timeZone = timeZoneId;
143     }
144         
145 }
146
Popular Tags