comparison src/alice/topology/manager/keeparive/SendPing.java @ 312:6e0a3c680b82

Rename
author sugi
date Tue, 26 Nov 2013 18:20:18 +0900
parents src/alice/topology/manager/keeparive/PingScheduler.java@f1cd920ea913
children f1f0638861ab
comparison
equal deleted inserted replaced
311:4b38039e4454 312:6e0a3c680b82
1 package alice.topology.manager.keeparive;
2
3 import alice.codesegment.CodeSegment;
4 import alice.datasegment.CommandType;
5 import alice.datasegment.Receiver;
6
7 public class SendPing extends CodeSegment{
8 private Receiver info = ids.create(CommandType.TAKE);
9 private TaskInfo nowTask;
10 private boolean interruptFlag = false;
11 private long time = 0;
12
13 static class SingletonHolder {
14 private static SendPing Instance = new SendPing();
15 }
16 public static SendPing getInstance(){
17 return SingletonHolder.Instance;
18 }
19 public void setKey(){
20 info.setKey("_WAITINGLIST");
21 }
22
23 @Override
24 public synchronized void run() {
25 ListManager list = info.asClass(ListManager.class);
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 }
39 SendPing.getInstance().setKey();
40 }
41 public synchronized void interrupt(){
42 interruptFlag = true;
43 notify();
44 }
45
46 public TaskInfo getNowTask() {
47 return nowTask;
48 }
49
50 public long getTime(){
51 return time;
52 }
53 }
54