-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeCounter.java
More file actions
65 lines (55 loc) · 1.72 KB
/
TimeCounter.java
File metadata and controls
65 lines (55 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package entity;
import java.util.Timer;
import java.util.TimerTask;
public class TimeCounter {
/*得到邻居的路由器ID*/
private int sourceRouterId;
/*得到本身路由器*/
private Router router;
/*每个这个类一个计时器*/
private Timer timer = new Timer();
/*getters和 setters方法*/
public int getSourceRouterId() {
return sourceRouterId;
}
public void setSourceRouterId(int sourceRouterId) {
this.sourceRouterId = sourceRouterId;
}
public Router getRouter() {
return router;
}
public void setRouter(Router router) {
this.router = router;
}
/*默认构造方法*/
public TimeCounter() {
}
public TimeCounter(int sourceRouterId, Router router) {
super();
this.sourceRouterId = sourceRouterId;
this.router = router;
}
/*开启计时器*/
public void start() {
final long lastTime = router.getLastTimeMaps().get(sourceRouterId);
timer.schedule(new TimerTask() {
@Override
public void run() {
if (lastTime == router.getLastTimeMaps().get(sourceRouterId)) {
for (int i = 0; i < new NetMap().getInitInternetMap().length; i++) {
if (router.getRouterTable().getNextHop()[i] == sourceRouterId) {
router.getRouterTable().getDistance()[i] = 16;
router.getRouterTable().getNextHop()[i] = 0;
}
}
} else {
timer.cancel();
}
}
}, 10 * 1000);
}
/*关闭计时器*/
public void close(){
timer.cancel();
}
}