Mercurial > hg > Members > sugi > javafx
comparison src/alice/topology/manager/keeparive/PingScheduler.java @ 32:e580cd6b225a
bug fixed (about totalTime)
author | sugi |
---|---|
date | Mon, 11 Nov 2013 16:25:55 +0900 |
parents | 5598fa745a51 |
children | f5cf57c645ab |
comparison
equal
deleted
inserted
replaced
31:5598fa745a51 | 32:e580cd6b225a |
---|---|
11 private HashMap<String, Integer> map = new HashMap<String, Integer>(); | 11 private HashMap<String, Integer> map = new HashMap<String, Integer>(); |
12 private long INTERVAL = 60 * 1000; | 12 private long INTERVAL = 60 * 1000; |
13 | 13 |
14 public boolean updateFlag = false; | 14 public boolean updateFlag = false; |
15 private boolean postponeFlag = false; | 15 private boolean postponeFlag = false; |
16 private boolean nowTaskFlag = false; | |
16 | 17 |
17 public long time = 0; | 18 public long time = 0; |
18 public int taskNum = 0; | 19 public int taskNum = 0; |
19 public TaskInfo nowTask; | 20 public TaskInfo nowTask; |
20 private long totalTime = 0; | 21 private long totalTime = 0; |
30 public synchronized void postpone(String name){ | 31 public synchronized void postpone(String name){ |
31 long postponeTime = nowTask.getTime() - (System.currentTimeMillis() - time); | 32 long postponeTime = nowTask.getTime() - (System.currentTimeMillis() - time); |
32 if (name.equals(nowTask.getName())){ | 33 if (name.equals(nowTask.getName())){ |
33 TaskInfo nextTask = list.get(0); | 34 TaskInfo nextTask = list.get(0); |
34 nextTask.setTime(postponeTime + nextTask.getTime()); | 35 nextTask.setTime(postponeTime + nextTask.getTime()); |
35 | 36 nowTaskFlag = true; |
36 } else { | 37 } else { |
37 for (int cnt = 0 ;cnt < list.size(); cnt++){ | 38 for (int cnt = 0 ;cnt < list.size(); cnt++){ |
38 TaskInfo task = list.get(cnt); | 39 TaskInfo task = list.get(cnt); |
39 if (name.equals(task.getName())){ | 40 if (name.equals(task.getName())){ |
40 if (cnt+1 < list.size()){ | 41 if (cnt+1 < list.size()){ |
42 tasknext.setTime(task.getTime()); | 43 tasknext.setTime(task.getTime()); |
43 } | 44 } |
44 list.remove(cnt); | 45 list.remove(cnt); |
45 task.setTime(INTERVAL); | 46 task.setTime(INTERVAL); |
46 addTask(task); | 47 addTask(task); |
47 postponeFlag = true; | |
48 break; | 48 break; |
49 } | 49 } |
50 } | 50 } |
51 } | 51 } |
52 postponeFlag = true; | |
52 notify(); | 53 notify(); |
53 } | 54 } |
54 | 55 |
55 | 56 |
56 public synchronized void addTask(TaskInfo newInfo){ | 57 public synchronized void addTask(TaskInfo newInfo){ |
62 newInfo.setTaskNum(taskNum); | 63 newInfo.setTaskNum(taskNum); |
63 } | 64 } |
64 if (list.isEmpty()) { | 65 if (list.isEmpty()) { |
65 list.add(newInfo); | 66 list.add(newInfo); |
66 } else { | 67 } else { |
67 int cnt = 0; | 68 for (int cnt = 0; cnt < list.size(); cnt++){ |
68 for (TaskInfo info : list){ | 69 TaskInfo info = list.get(cnt); |
69 if (info.getTime() < newInfo.getTime()){ | 70 if (info.getTime() < newInfo.getTime()){ |
70 newInfo.setTime(newInfo.getTime() - info.getTime()); | 71 newInfo.setTime(newInfo.getTime() - info.getTime()); |
71 if (cnt+1 == list.size()){ | 72 if (cnt+1 == list.size()){ |
73 list.add(newInfo); | |
72 break; | 74 break; |
73 } | 75 } |
74 } else if (info.getTime() == newInfo.getTime()){ | 76 } else if (info.getTime() == newInfo.getTime()){ |
75 newInfo.setTime(newInfo.getTime() - info.getTime()); | 77 newInfo.setTime(newInfo.getTime() - info.getTime()); |
76 cnt++; | 78 list.add(cnt+1, newInfo); |
77 break; | 79 break; |
78 } else if (info.getTime() > newInfo.getTime()){ | 80 } else if (info.getTime() > newInfo.getTime()){ |
79 info.setTime(info.getTime() - newInfo.getTime()); | 81 info.setTime(info.getTime() - newInfo.getTime()); |
82 list.add(cnt, newInfo); | |
80 break; | 83 break; |
81 } | 84 } |
82 cnt++; | |
83 } | 85 } |
84 list.add(cnt, newInfo); | |
85 } | 86 } |
86 updateFlag = true; | 87 updateFlag = true; |
87 } | 88 } |
88 | 89 |
89 @Override | 90 @Override |
98 if (nowTask.getTime()!=0) | 99 if (nowTask.getTime()!=0) |
99 this.wait(nowTask.getTime()); | 100 this.wait(nowTask.getTime()); |
100 if (postponeFlag){ | 101 if (postponeFlag){ |
101 long remainingTime = nowTask.getTime() - (System.currentTimeMillis() - time); | 102 long remainingTime = nowTask.getTime() - (System.currentTimeMillis() - time); |
102 totalTime += (System.currentTimeMillis() - time); | 103 totalTime += (System.currentTimeMillis() - time); |
103 nowTask.setTime(remainingTime); | 104 if (nowTaskFlag){ |
104 list.add(0, nowTask); | 105 nowTask.setTime(INTERVAL); |
106 addTask(nowTask); | |
107 } else { | |
108 nowTask.setTime(remainingTime); | |
109 list.add(0, nowTask); | |
110 updateFlag = true; | |
111 } | |
105 postponeFlag = false; | 112 postponeFlag = false; |
106 } else { | 113 } else { |
107 totalTime +=nowTask.getTime(); | 114 totalTime +=nowTask.getTime(); |
108 nowTask.setTime(INTERVAL); | 115 nowTask.setTime(INTERVAL); |
109 addTask(nowTask); | 116 addTask(nowTask); |