comparison src/alice/topology/manager/keeparive/TaskExecuter.java @ 330:d35ff0f588e8

keep alive may work... but bug exist.
author sugi
date Mon, 31 Mar 2014 22:28:52 +0900
parents 35b4e24e3e02
children 8266d7cfba7e
comparison
equal deleted inserted replaced
329:35b4e24e3e02 330:d35ff0f588e8
23 info.setKey("_WAITINGLIST"); 23 info.setKey("_WAITINGLIST");
24 } 24 }
25 25
26 @Override 26 @Override
27 public synchronized void run() { 27 public synchronized void run() {
28 ListManager list = info.asClass(ListManager.class); 28 ListManager list = info.asClass(ListManager.class);
29 if (list.getTaskList().size() == 0){ 29 if (list.getTaskList().size() == 0){
30 if (remainingTime !=0){ 30 if (remainingTime !=0){
31 TaskInfo info = new TaskInfo(TaskType.SKIP); 31 TaskInfo info = new TaskInfo(TaskType.SKIP);
32 info.setSleepTime(remainingTime); 32 info.setSleepTime(remainingTime);
33 remainingTime = 0; 33 remainingTime = 0;
51 wait(nowTask.getSleepTime()); 51 wait(nowTask.getSleepTime());
52 } catch (InterruptedException e) { 52 } catch (InterruptedException e) {
53 e.printStackTrace(); 53 e.printStackTrace();
54 } 54 }
55 } 55 }
56
57
58 if (!skipFlag){
59 execTask();
60 }
56 setNowTask(null); 61 setNowTask(null);
57 startTime = 0; 62 startTime = 0;
58
59 if (!skipFlag){
60 // ping or close
61 /*
62 if (nowTask.getType() == TaskType.PING) {
63 ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey());
64 TaskInfo task = new TaskInfo(TaskType.CLOSE);
65 task.setInfo(nowTask.getManagerKey(), 60 * 1000);
66 ods.put("_TASKINFO", task);
67 new RespondPing(nowTask.getReturnKey());
68 } else {
69 // no response from the Remote DataSegment. So close this connection.
70 DataSegment.get(nowTask.getManagerKey()).close();
71 }
72 */
73 }
74 } 63 }
75 setKey(); 64 setKey();
76 } 65 }
77 66
67 private synchronized void execTask(){
68 // ping or close
69 System.out.println("aaaa");
70 if (nowTask.getType() == TaskType.PING) {
71 System.out.println("bbb");
72 ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey());
73 TaskInfo task = new TaskInfo(TaskType.CLOSE);
74 task.setInfo(nowTask.getManagerKey(), 10 * 1000);
75 ods.put("_TASKINFO", task);
76 new RespondPing(nowTask.getReturnKey());
77 } else if (nowTask.getType() == TaskType.CLOSE) {
78 // no response from the Remote DataSegment. So close this connection.
79 //DataSegment.get(nowTask.getManagerKey()).close();
80 System.out.println("CLOSE");
81
82 nowTask.show();
83 System.exit(0);
84 }
85 }
86
78 public synchronized void skip() { 87 public synchronized void skip() {
79 skipFlag = true; 88 skipFlag = true;
80 if (startTime == 0){ 89 if (startTime == 0){
81 remainingTime = nowTask.getSleepTime(); 90 remainingTime = nowTask.getSleepTime();
82 } else { 91 } else {
83 remainingTime = nowTask.getSleepTime() - (System.currentTimeMillis() - startTime); 92 remainingTime = nowTask.getSleepTime() - (System.currentTimeMillis() - startTime);
84 } 93 }
94 System.out.println(remainingTime);
85 nowTask = null; 95 nowTask = null;
86 notify(); 96 notify();
97 System.out.println(nowTask);
87 } 98 }
88 99
89 public synchronized void ignore() { 100 public synchronized void ignore() {
90 skipFlag = true; 101 skipFlag = true;
91 remainingTime = 0; 102 remainingTime = 0;
92 nowTask = null; 103 nowTask = null;
93 notify(); 104 notify();
94 } 105 }
95 106
96 public TaskInfo getNowTask() { 107 public synchronized TaskInfo getNowTask() {
97 return nowTask; 108 return nowTask;
98 } 109 }
99 110
100 public synchronized void setNowTask(TaskInfo info) { 111 public synchronized void setNowTask(TaskInfo info) {
101 nowTask = info; 112 nowTask = info;
111 } else { 122 } else {
112 return remainingTime; 123 return remainingTime;
113 } 124 }
114 } 125 }
115 126
116 public long initRemainingTime() {
117 long time = remainingTime;
118 remainingTime = 0;
119 return time;
120 }
121
122 public boolean compareNowTask(TaskInfo task) { 127 public boolean compareNowTask(TaskInfo task) {
123 if (nowTask != null){ 128 if (nowTask != null){
124 if (nowTask.getType().equals(task.getType()) 129 if (nowTask.getType().equals(task.getType())
125 && nowTask.getManagerKey().equals(task.getManagerKey())){ 130 && nowTask.getManagerKey().equals(task.getManagerKey())){
126 return true; 131 return true;