1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.amsterdam.cron;
21
22 import org.backsource.amsterdam.metadata.ContentMapEntry;
23 /***
24 <p>
25 Represents a Job/Task to be run by a CronManager.
26 </p>
27
28 <p>A CronJob takes a string describing when it is to be run. The string
29 hase the same format as the date and time fields in a Unix/Vixie Crontab
30 entry. It also takes a ContentMapEntry. This is an opaque object that may be
31 accessed in the listener that is called when the CronManager "executes" the
32 job.
33 </p>
34
35 <p>The <strong>sceduleAt</strong> string follows the syntax of a cronlike Date/Timestring
36 <p>
37
38 <pre>
39 String: minute hour day-of-month month day-of-week
40
41 field allowed values
42 ----- --------------
43 minute 0-59
44 hour 0-23
45 day of month 1-31
46 month 1-12 (no names)
47 day of week 1-7 (1 is Sun)
48 </pre>
49 <p>
50 Currently ranges are not alowed, only skips, ie 0-12 is not allowed,
51 but *\/5 wich for minutes means every fifth minute.
52 <p>
53
54 <p>
55 Some examples:
56 </p>
57
58 <p>Run every minute: <strong>* * * * *</strong>.
59 <p>
60
61 <p>Run every fith minute: <strong>*\/5 * * * *</strong>.
62 <p>
63
64 <p>Run at three a clock every day: <strong>0 3 * * *</strong>.
65 <p>
66
67 <p>Run at three a clock every monday: <strong>0 3 * * 2</strong>.
68 <p>
69
70 *
71 * @author <a href="mailto:pra@mogul.com">Peter Antman</a>
72 * @version $Revision: 1.1.1.1 $
73 */
74
75 public class CronJob {
76
77 ContentMapEntry contentEntry;
78 String scheduledAt;
79
80 public CronJob(String scheduleAt, ContentMapEntry contentEntry) {
81 this.scheduledAt = scheduleAt;
82 this.contentEntry = contentEntry;
83 }
84
85 public String getCronDateTime() {
86 return scheduledAt;
87 }
88
89 public ContentMapEntry getContentEntry() {
90 return contentEntry;
91 }
92
93 public void setContentEntry(ContentMapEntry contentEntry) {
94 this.contentEntry = contentEntry;
95 }
96
97 public String toString() {
98 return contentEntry.getName()+":"+scheduledAt;
99 }
100
101 public String getContentAsXML(boolean prettyPrint){
102 StringBuffer sBuffer=new StringBuffer();
103 String newLine=prettyPrint?"\n":"";
104 sBuffer.append("<CronJob>").append(newLine);
105 sBuffer.append("<ScheduledAt>").append(scheduledAt).append("</ScheduledAt>" + newLine);
106 String indent = prettyPrint?"\t":"";
107 sBuffer.append(contentEntry.getContentAsXML(prettyPrint));
108 sBuffer.append("</CronJob>").append(newLine);
109 return sBuffer.toString();
110 }
111 }