1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.scheduler;
18
19
20 /***
21 * Wrapper for a <code>JobEntry</code> to actually perform the job's action.
22 *
23 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
24 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
25 * @version $Id: WorkerThread.java 516448 2007-03-09 16:25:47Z ate $
26 */
27 public class WorkerThread
28 implements Runnable
29 {
30 /***
31 * The <code>JobEntry</code> to run.
32 */
33 private JobEntry je = null;
34
35 /***
36 * The {@link org.apache.fulcrum.logging.Logger} facility to use.
37 */
38
39 /***
40 * Creates a new worker to run the specified <code>JobEntry</code>.
41 *
42 * @param je The <code>JobEntry</code> to create a worker for.
43 */
44 public WorkerThread(JobEntry je)
45 {
46 this.je = je;
47 }
48
49 /***
50 * Run the job.
51 */
52 public void run()
53 {
54 if (je == null || je.isActive())
55 {
56 return;
57 }
58
59 try
60 {
61 if (! je.isActive())
62 {
63 je.setActive(true);
64 logStateChange("started");
65
66
67
68
69
70 String className = je.getTask();
71
72
73
74 ScheduledJob sc = (ScheduledJob)Class.forName(className).newInstance();
75 sc.execute(je);
76 }
77 }
78 catch (Exception e)
79 {
80
81
82
83 }
84 finally
85 {
86 if (je.isActive())
87 {
88 je.setActive(false);
89 logStateChange("completed");
90 }
91 }
92 }
93
94 /***
95 * Macro to log <code>JobEntry</code> status information.
96 *
97 * @param state The new state of the <code>JobEntry</code>.
98 */
99 private final void logStateChange(String state)
100 {
101
102
103
104 }
105 }