comparison src/alice/topology/manager/keeparive/SendPing.java @ 314:f1f0638861ab

ping responce receivable
author sugi
date Fri, 06 Dec 2013 11:42:51 +0900
parents 6e0a3c680b82
children f9ec5bead150
comparison
equal deleted inserted replaced
313:4b99234c88d4 314:f1f0638861ab
7 public class SendPing extends CodeSegment{ 7 public class SendPing extends CodeSegment{
8 private Receiver info = ids.create(CommandType.TAKE); 8 private Receiver info = ids.create(CommandType.TAKE);
9 private TaskInfo nowTask; 9 private TaskInfo nowTask;
10 private boolean interruptFlag = false; 10 private boolean interruptFlag = false;
11 private long time = 0; 11 private long time = 0;
12 private static SendPing instance = new SendPing();
12 13
13 static class SingletonHolder { 14 private SendPing(){}
14 private static SendPing Instance = new SendPing(); 15 public static SendPing getInstance() {
15 } 16 return instance;
16 public static SendPing getInstance(){ 17 }
17 return SingletonHolder.Instance; 18
18 }
19 public void setKey(){ 19 public void setKey(){
20 ids.init();
20 info.setKey("_WAITINGLIST"); 21 info.setKey("_WAITINGLIST");
21 } 22 }
22 23
23 @Override 24 @Override
24 public synchronized void run() { 25 public synchronized void run() {
25 ListManager list = info.asClass(ListManager.class); 26 ListManager list = info.asClass(ListManager.class);
27 if (list.getTaskList().size() == 0){
28 ods.update("_WAITINGLIST", list);
29 new GetTask();
30 return;
31 }
26 try { 32 try {
27 nowTask = list.getTaskList().pollFirst(); 33 nowTask = list.getTaskList().pollFirst();
28 ods.update("_WAITINGLIST", list); 34 ods.update("_WAITINGLIST", list);
35 System.out.print("managerkey is "+ nowTask.getManagerKey());
36 System.out.println(" returnkey is "+ nowTask.getReturnKey());
29 time = System.currentTimeMillis(); 37 time = System.currentTimeMillis();
30 if (nowTask.getSleepTime()!=0) 38 if (nowTask.getSleepTime()!=0)
31 this.wait(nowTask.getSleepTime()); 39 this.wait(nowTask.getSleepTime());
32 if (interruptFlag){ 40 if (interruptFlag){
33 interruptFlag = false; 41 interruptFlag = false;
34 } else { 42 } else {
35 ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey()); 43 ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey());
44 new RespondPing(nowTask.getReturnKey());
36 } 45 }
37 } catch (InterruptedException e) { 46 } catch (InterruptedException e) {
38 } 47 }
39 SendPing.getInstance().setKey(); 48 new GetTask();
40 } 49 }
41 public synchronized void interrupt(){ 50 public synchronized void interrupt(){
42 interruptFlag = true; 51 interruptFlag = true;
43 notify(); 52 notify();
44 } 53 }