1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.surf.task;
20
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28
29
30
31
32
33
34 public abstract class AbstractTask implements Task
35 {
36 protected static Log logger = LogFactory.getLog(AbstractTask.class);
37
38 protected boolean isError = false;
39 protected boolean isSuccess = false;
40 protected boolean isFinished = false;
41 protected boolean isRunning = false;
42 protected boolean isCancelled = false;
43 protected Throwable throwable = null;
44 protected String id = null;
45 protected String name = null;
46 protected String description = null;
47 protected String status;
48 protected int progress;
49 protected int progressSize;
50 protected List<String> history;
51 protected String creator;
52 protected Date startTime;
53 protected Date endTime;
54
55
56
57
58
59
60 public AbstractTask(String name)
61 {
62 this.name = name;
63 this.id = new org.springframework.extensions.surf.util.ObjectGUID().toString();
64
65 this.history = new ArrayList<String>();
66 this.description = "";
67 this.status = "";
68 this.creator = "unknown";
69 this.startTime = new Date();
70
71 progress = 0;
72 progressSize = 10;
73 }
74
75
76
77
78 public void increment()
79 {
80 progress++;
81 }
82
83
84
85
86 public String getId()
87 {
88 return id;
89 }
90
91
92
93
94 public String getName()
95 {
96 return name;
97 }
98
99
100
101
102 public void setDescription(String description)
103 {
104 this.description = description;
105 }
106
107
108
109
110 public String getDescription()
111 {
112 return description;
113 }
114
115
116
117
118 public void setCreator(String creator)
119 {
120 this.creator = creator;
121 }
122
123
124
125
126 public String getCreator()
127 {
128 return this.creator;
129 }
130
131
132
133
134 public abstract void execute()
135 throws Throwable;
136
137
138
139
140 public abstract void cancel();
141
142
143
144
145 public boolean isError()
146 {
147 return isError;
148 }
149
150
151
152
153 public boolean isSuccess()
154 {
155 return isSuccess;
156 }
157
158
159
160
161 public boolean isFinished()
162 {
163 return isFinished;
164 }
165
166
167
168
169 public boolean isRunning()
170 {
171 return isRunning;
172 }
173
174
175
176
177 public boolean isCancelled()
178 {
179 return isCancelled;
180 }
181
182
183
184
185 public Date getStartTime()
186 {
187 return this.startTime;
188 }
189
190
191
192
193 public Date getEndTime()
194 {
195 return this.endTime;
196 }
197
198
199
200
201 public Throwable getThrowable()
202 {
203 return throwable;
204 }
205
206
207
208
209 public String getStatus()
210 {
211 return this.status;
212 }
213
214
215
216
217 public void setStatus(String status)
218 {
219 this.status = status;
220
221 String pattern = "yyyy, MMMMM, d hh:mm";
222 java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat(pattern);
223 String result = formatter.format(new Date());
224 String text = "[" + result + "] " + status;
225
226 history.add(text);
227 }
228
229
230
231
232 public int getProgress()
233 {
234 return this.progress;
235 }
236
237
238
239
240 public int getProgressSize()
241 {
242 return this.progressSize;
243 }
244
245
246
247
248 public List<String> getHistory()
249 {
250 return history;
251 }
252 }