303
|
1 package alice.topology.manager.keeparive;
|
|
2
|
|
3 import alice.codesegment.CodeSegment;
|
309
|
4 import alice.datasegment.CommandType;
|
|
5 import alice.datasegment.Receiver;
|
303
|
6
|
312
|
7 public class SendPing extends CodeSegment{
|
310
|
8 private Receiver info = ids.create(CommandType.TAKE);
|
|
9 private TaskInfo nowTask;
|
|
10 private boolean interruptFlag = false;
|
|
11 private long time = 0;
|
|
12
|
309
|
13 static class SingletonHolder {
|
312
|
14 private static SendPing Instance = new SendPing();
|
309
|
15 }
|
312
|
16 public static SendPing getInstance(){
|
309
|
17 return SingletonHolder.Instance;
|
|
18 }
|
|
19 public void setKey(){
|
|
20 info.setKey("_WAITINGLIST");
|
|
21 }
|
|
22
|
|
23 @Override
|
|
24 public synchronized void run() {
|
310
|
25 ListManager list = info.asClass(ListManager.class);
|
309
|
26 try {
|
|
27 nowTask = list.getTaskList().pollFirst();
|
|
28 ods.update("_WAITINGLIST", list);
|
|
29 time = System.currentTimeMillis();
|
|
30 if (nowTask.getSleepTime()!=0)
|
|
31 this.wait(nowTask.getSleepTime());
|
|
32 if (interruptFlag){
|
|
33 interruptFlag = false;
|
|
34 } else {
|
|
35 ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey());
|
|
36 }
|
|
37 } catch (InterruptedException e) {
|
|
38 }
|
312
|
39 SendPing.getInstance().setKey();
|
309
|
40 }
|
310
|
41 public synchronized void interrupt(){
|
303
|
42 interruptFlag = true;
|
|
43 notify();
|
309
|
44 }
|
310
|
45
|
|
46 public TaskInfo getNowTask() {
|
|
47 return nowTask;
|
|
48 }
|
|
49
|
|
50 public long getTime(){
|
|
51 return time;
|
|
52 }
|
303
|
53 }
|
|
54
|