303
|
1 package alice.topology.manager.keeparive;
|
|
2
|
|
3 import alice.codesegment.CodeSegment;
|
309
|
4 import alice.datasegment.CommandType;
|
321
|
5 import alice.datasegment.DataSegment;
|
309
|
6 import alice.datasegment.Receiver;
|
303
|
7
|
319
|
8 public class TaskExecuter extends CodeSegment{
|
310
|
9 private Receiver info = ids.create(CommandType.TAKE);
|
|
10 private TaskInfo nowTask;
|
|
11 private boolean interruptFlag = false;
|
|
12 private long time = 0;
|
319
|
13 private static TaskExecuter instance = new TaskExecuter();
|
310
|
14
|
319
|
15 private TaskExecuter(){}
|
|
16 public static TaskExecuter getInstance() {
|
315
|
17 return instance;
|
|
18 }
|
|
19
|
309
|
20 public void setKey(){
|
314
|
21 ids.init();
|
309
|
22 info.setKey("_WAITINGLIST");
|
|
23 }
|
315
|
24
|
309
|
25 @Override
|
|
26 public synchronized void run() {
|
310
|
27 ListManager list = info.asClass(ListManager.class);
|
314
|
28 if (list.getTaskList().size() == 0){
|
|
29 ods.update("_WAITINGLIST", list);
|
316
|
30 setKey();
|
314
|
31 return;
|
320
|
32 }
|
|
33 nowTask = list.getTaskList().poll();
|
|
34 ods.update("_WAITINGLIST", list);
|
|
35 time = System.currentTimeMillis();
|
|
36 if (nowTask.getSleepTime()!=0){
|
315
|
37 try {
|
320
|
38 this.wait(nowTask.getSleepTime());
|
|
39 } catch (InterruptedException e) {}
|
|
40 }
|
|
41 if (interruptFlag){
|
|
42 interruptFlag = false;
|
|
43 } else {
|
321
|
44 if (nowTask.getType() == TaskType.PING) {
|
|
45 ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey());
|
|
46 new RespondPing(nowTask.getReturnKey());
|
|
47 } else {
|
|
48 DataSegment.get(nowTask.getManagerKey()).close();
|
|
49 }
|
|
50
|
309
|
51 }
|
321
|
52 nowTask = null;
|
316
|
53 setKey();
|
309
|
54 }
|
310
|
55 public synchronized void interrupt(){
|
303
|
56 interruptFlag = true;
|
|
57 notify();
|
309
|
58 }
|
315
|
59
|
310
|
60 public TaskInfo getNowTask() {
|
|
61 return nowTask;
|
|
62 }
|
315
|
63
|
310
|
64 public long getTime(){
|
|
65 return time;
|
|
66 }
|
303
|
67 }
|
|
68
|