1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.vc.threads;
20
21 import nl.toolforge.karma.core.KarmaRuntimeException;
22 import nl.toolforge.karma.core.module.Module;
23
24 /***
25 * @author D.A. Smedes
26 * @version $Id: RunnerThread.java,v 1.6 2004/11/10 23:53:09 asmedes Exp $
27 */
28 public abstract class RunnerThread extends Thread {
29
30 private boolean running = true;
31
32 protected Throwable exception = null;
33 protected RunnerResult result = null;
34 private Module module = null;
35
36 public RunnerThread(Module module) {
37 this.module = module;
38 }
39
40 /***
41 * Must be implemented by subclasses. The subclass is where all logic is performed.
42 */
43 public abstract void run();
44
45 /***
46 * Should be called to demarkate the start of the 'transaction'.
47 */
48 protected void startRunning() {
49 running = true;
50 }
51
52 /***
53 * Should be called to demarkate the end of the 'transaction'.
54 */
55 protected void stopRunning() {
56 running = false;
57 }
58
59 /***
60 * Should be checked to ensure that <code>run()</code> is finished.
61 *
62 * @return
63 */
64 public final boolean isRunning() {
65 return running;
66 }
67
68 public final RunnerResult getResult() {
69 return result;
70 }
71
72 /***
73 * Returns the module status, irrespective of whether this thread has finished executing or not. This check can be
74 * performed by calling {@link #isRunning()}.
75 *
76 * @return The ModuleStatus instance generated based on what the {@link #run()} has done when executed properly.
77 */
78 public Module getModule() {
79 if (module == null) {
80 throw new KarmaRuntimeException("Module instance has not been set.");
81 }
82 return module;
83 }
84
85 public Throwable getException() {
86 return exception;
87 }
88
89 }