1
2
3
4
5
6
7
8 /
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public abstract class AbstractJobDescriptor
55 {
56
57
58 /*** The scheduled job's name. */
59 protected String name;
60
61 /*** The job's associated Schedule. */
62 protected Schedule schedule;
63
64 /*** The execution argument. */
65 protected String argument;
66
67 /*** The scheduled job's Job class name. */
68 protected String jobClassName;
69
70 /*** The job's execution count to date. */
71 protected int runCount;
72
73 /*** The job's execution count limit. */
74 protected int runCountLimit;
75
76 /*** The job's last run time. */
77 protected Date lastRunTime;
78
79 /*** The lower limit of job's execution period. */
80 protected Date runTimeLimitStart;
81
82 /*** The upper limit of job's execution period. */
83 protected Date runTimeLimitEnd;
84
85 /*** The job's reentrantness flag. */
86 protected boolean reentrant;
87
88 /*** The job's currently running flag. */
89 protected boolean running;
90
91 /*** The job's auto-clean flag. */
92 protected boolean autoClean;
93
94 /*** The job's enabled flag. */
95 protected boolean enabled;
96
97 /***
98 * Returns the name of the job.
99 *
100 * @return the name of the job.
101 */
102 public String getName()
103 {
104 return name;
105 }
106
107 /***
108 * Returns the associated schedule.
109 *
110 * @return the associated schedule.
111 */
112 public Schedule getSchedule()
113 {
114 return schedule;
115 }
116
117 /***
118 * Changes the shedule schedule.
119 *
120 * @param schedule the new schedule.
121 * @throws JobModificationException if the job state could not be saved.
122 */
123 public synchronized void setSchedule(Schedule schedule)
124 throws JobModificationException
125 {
126 this.schedule = schedule;
127 saveChanges();
128 }
129
130 /***
131 * Returns the job class name.
132 *
133 *
134 * @return the job class name.
135 */
136 public String getJobClassName()
137 {
138 return jobClassName;
139 }
140
141 /***
142 * Changes the job specification.
143 *
144 * @param jobClassName the job class name.
145 * @throws JobModificationException if the job state could not be saved.
146 */
147 public synchronized void setJobClassName(String jobClassName)
148 throws JobModificationException
149 {
150 this.jobClassName = jobClassName;
151 saveChanges();
152 }
153
154 /***
155 * Returns the job execution argument.
156 *
157 * <p>You can use the execution argument to specify the unit of work that
158 * the scheduled job should perform. You can have multiple parallel
159 * instanes of a Job class perfroming different units of work.</p>
160 *
161 * @return the execution argument, or <code>null</code> if undefined.
162 */
163 public String getArgument()
164 {
165 return argument;
166 }
167
168 /***
169 * Sets the job execution argument.
170 *
171 * <p>You can use the execution argument to specify the unit of work that
172 * the scheduled job should perform. You can have multiple parallel
173 * instanes of a Job class perfroming different units of work.</p>
174 *
175 * @param argument the execution argument, or <code>null</code> if undefined.
176 * @throws JobModificationException if the job state could not be saved.
177 */
178 public void setArgument(String argument)
179 throws JobModificationException
180 {
181 this.argument = argument;
182 saveChanges();
183 }
184
185 /***
186 * Returns the count of job executions to date.
187 *
188 * @return the coutn of job executions to date.
189 */
190 public int getRunCount()
191 {
192 return runCount;
193 }
194
195 /***
196 * Returns the maximum number of job executions.
197 *
198 * <p>When no limit is set, -1 will be returned. Newly created <code>
199 * ScheduledJobs</code> have no limit set.
200 *
201 * @return the maximum number of job executions, or -1 if disabled.
202 */
203 public int getRunCountLimit()
204 {
205 return runCountLimit;
206 }
207
208 /***
209 * Sets the maximum number of job executions.
210 *
211 * <p>Use value of -1 to disable the limit.
212 *
213 * @param limit the maximum number of job executions, or -1 if disabled.
214 * @throws JobModificationException if the job state could not be saved.
215 */
216 public synchronized void setRunCountLimit(int limit)
217 throws JobModificationException
218 {
219 this.runCountLimit = limit;
220 saveChanges();
221 }
222
223 /***
224 * Return the job's last execution time.
225 *
226 * @return the job's last execution time, or <code>null</code> if unknown.
227 */
228 public Date getLastRunTime()
229 {
230 return lastRunTime;
231 }
232
233 /***
234 * Returns lower limit of job execution period.
235 *
236 * <p>The job will not be run before the time returned. Newly created jobs
237 * have no limit set.</p>
238 *
239 * @return lower limit of job execution period, or <code>null</code> if
240 * disabled.
241 */
242 public Date getTimeLimitStart()
243 {
244 return runTimeLimitStart;
245 }
246
247 /***
248 * Returns upper limit of job execution period.
249 *
250 * <p>The job will not be run after the time returned. Newly created jobs
251 * have no limit set.</p>
252 *
253 * @return upper limit of job execution period, or <code>null</code> if
254 * disabled.
255 */
256 public Date getTimeLimitEnd()
257 {
258 return runTimeLimitEnd;
259 }
260
261 /***
262 * Sets the job execution period.
263 *
264 * <p>The job will only be run in the time period specified.</p>
265 *
266 * @param start lower limit of job execution period, or <code>null</code>
267 * if disabled.
268 * @param end upper limit of job execution period, or <code>null</code>
269 * if disabled.
270 * @throws JobModificationException if the job state could not be saved.
271 */
272 public void setTimeLimit(Date start, Date end)
273 throws JobModificationException
274 {
275 this.runTimeLimitStart = start;
276 this.runTimeLimitEnd = end;
277 saveChanges();
278 }
279
280 /***
281 * Checks if the job is being executed at the moment.
282 *
283 * @return <code>true</code> if the job is being executed at the moment.
284 */
285 public boolean isRunning()
286 {
287 return running;
288 }
289
290 /***
291 * Returns the job's auto-clean flag.
292 *
293 * <p>Jobs that have the auto-clean flag enabled are deleted once they
294 * exceed their run count limit, run time period, or their schedule's
295 * <code>getNextRunTime</code> method returns <code>null</code>.
296 *
297 * @return the job's auto-clean flag.
298 */
299 public boolean getAutoClean()
300 {
301 return autoClean;
302 }
303
304 /***
305 * Returns the job's auto-clean flag.
306 *
307 * <p>Jobs that have the auto-clean flag enabled are deleted once they
308 * exceed their run count limit, run time period, or their schedule's
309 * <code>getNextRunTime</code> method returns <code>null</code>.
310 *
311 * @param autoClean the job's auto-clean flag.
312 * @throws JobModificationException if the job state could not be saved.
313 */
314 public void setAutoClean(boolean autoClean)
315 throws JobModificationException
316 {
317 this.autoClean = autoClean;
318 saveChanges();
319 }
320
321 /***
322 * Returns the job's reentrantness flag.
323 *
324 * <p>If the flag is set, execution of the job may be started even if the
325 * pervious execution has not terminated yet. Newly created jobs are not
326 * reentrant by default.</p>
327 *
328 * @return the job's reentrantess flag state.
329 */
330 public boolean isReentrant()
331 {
332 return reentrant;
333 }
334
335 /***
336 * Sets the job's reentrantness flag.
337 *
338 * @param reentrant the job's reentrantess flag state.
339 * @throws JobModificationException if the job state could not be saved.
340 */
341 public synchronized void setReentrant(boolean reentrant)
342 throws JobModificationException
343 {
344 this.reentrant = reentrant;
345 saveChanges();
346 }
347
348 /***
349 * Checks if the job is enabled.
350 *
351 * <p>Newly created jobs are disabled by default. Only enabled jobs will
352 * be executed by the scheduler</p>
353 *
354 * @return <code>true</code> if the job is enabled.
355 */
356 public boolean isEnabled()
357 {
358 return enabled;
359 }
360
361
362
363 /***
364 * Initializes the job descriptor.
365 *
366 * @param name the scheduled job name.
367 * @param schedule the job's schedule.
368 * @param jobClassName the job class name.
369 */
370 public void init(String name, Schedule schedule, String jobClassName)
371 {
372 this.name = name;
373 this.schedule = schedule;
374 this.jobClassName = jobClassName;
375 this.runCount = 0;
376 this.runCountLimit = -1;
377 this.lastRunTime = null;
378 this.runTimeLimitStart = null;
379 this.runTimeLimitEnd = null;
380 this.running = false;
381 this.reentrant = false;
382 this.enabled = false;
383 }
384
385 /***
386 * Sets the job's last execution time.
387 *
388 * @param lastRunTime the job's last execution time.
389 */
390 synchronized void setLastRunTime(Date lastRunTime)
391 throws JobModificationException
392 {
393 this.lastRunTime = lastRunTime;
394 saveChanges();
395 }
396
397 /***
398 * Sets the count of job executions to date.
399 *
400 * @param runCount the count of job executions to date.
401 */
402 synchronized void setRunCount(int runCount)
403 throws JobModificationException
404 {
405 this.runCount = runCount;
406 saveChanges();
407 }
408
409 /***
410 * Sets the 'enabled' flag for the job.
411 *
412 * @param enabled <code>true</code> if the job is to be enabled.
413 */
414 synchronized void setEnabled(boolean enabled)
415 throws JobModificationException
416 {
417 this.enabled = enabled;
418 saveChanges();
419 }
420
421 /***
422 * Sets the 'currently running' flag for the job.
423 *
424 * @param running <code>true</code> if the job is being executed at the
425 * moment.
426 */
427 void setRunning(boolean running)
428 {
429 this.running = running;
430 }
431
432
433
434 /***
435 * Updates the persistent state.
436 *
437 * @throws JobModificationException if the job state could not be saved.
438 */
439 protected abstract void saveChanges()
440 throws JobModificationException;
441 }