1 | package felix.society; |
2 | |
3 | import tuffy.util.Config; |
4 | |
5 | |
6 | /** |
7 | * A worker is a Runnable object generated by Task/TaskList/TaskWorker. |
8 | * @author czhang |
9 | * |
10 | */ |
11 | public abstract class Worker implements Runnable{ |
12 | |
13 | /** |
14 | * Exception collected |
15 | */ |
16 | private Exception e = null; |
17 | |
18 | /** |
19 | * ID |
20 | */ |
21 | protected int id = -1; |
22 | |
23 | /** |
24 | * Constructor -- the ID is assigned here. |
25 | */ |
26 | public Worker(){ |
27 | this.id = Config.getNextGlobalCounter(); |
28 | } |
29 | |
30 | /** |
31 | * If there are exceptions collected while running |
32 | * this Worker, return it. |
33 | * @return |
34 | */ |
35 | public Exception getException(){ |
36 | return e; |
37 | } |
38 | |
39 | /** |
40 | * Collect exceptions while running (we cannot |
41 | * throw exceptions in run()) |
42 | * @param _e |
43 | */ |
44 | public void submitException(Exception _e){ |
45 | this.e = _e; |
46 | } |
47 | |
48 | /** |
49 | * Run!!!! |
50 | */ |
51 | public abstract void run(); |
52 | |
53 | } |