345
|
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 RespondPing extends CodeSegment{
|
419
|
8 private Receiver respond = ids.create(CommandType.TAKE);
|
491
|
9 private long pingedTime = System.currentTimeMillis();
|
419
|
10
|
|
11 public RespondPing(String key) {
|
|
12 respond.setKey(key);
|
498
|
13 this.setPriority(10);
|
419
|
14 }
|
345
|
15
|
419
|
16 @Override
|
|
17 public void run() {
|
498
|
18 TaskExecuter exec = TaskExecuter.getInstance();
|
|
19 synchronized (exec){
|
|
20 RespondData d = respond.asClass(RespondData.class);
|
|
21 System.out.print("ping from "+d.from);
|
|
22 System.out.println(" Recieved time "+(d.time - pingedTime));
|
|
23
|
419
|
24 TaskInfo task = new TaskInfo(TaskType.CLOSE);
|
|
25 task.setInfo(d.from, null, 0);
|
498
|
26 if (!exec.compareAndSkip(task)){
|
|
27 System.out.println("falied RespondPing");
|
419
|
28 // case: remove task is still in the waiting queue.
|
|
29 ods.put("_REMOVETASK",task);
|
|
30 new RemoveTask();
|
|
31 }
|
498
|
32 }
|
419
|
33 }
|
345
|
34 }
|