Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of some bugs and performance enhancement.
[jaceP2P.git] / src / jaceP2P / HeartBeatSNode.java
1 package jaceP2P;
2
3 public class HeartBeatSNode extends Thread {
4
5         // atributes
6         public static HeartBeatSNode Instance;
7
8         private JaceSuperNodeInterface server = null;
9         private int beat;
10         // private long time;
11
12         int count = 0;
13
14         // constructors
15         private HeartBeatSNode() {
16         }
17
18         public static HeartBeatSNode Instance() {
19                 if (Instance == null) {
20                         Instance = new HeartBeatSNode();
21                 }
22                 return Instance;
23         }
24
25         public void setHeartTime(int timeBeat) {
26                 beat = timeBeat;
27         }
28
29         public int getHeartTime() {
30                 return beat;
31         }
32
33         public void setServer(JaceSuperNodeInterface serverEntity) {
34                 server = serverEntity;
35                 count = 0;
36                 // JaceBuffer.Instance().purge();
37                 // MsgQueue.Instance().purge();
38
39         }
40
41         public JaceSuperNodeInterface getServer() {
42                 return server;
43         }
44
45         public void run() {
46                 // long timeGiven;
47                 // long begin;
48                 // long end;
49                 while (true) {
50                         try {
51                                 // each "time" milisecondes, get the register if it has changed
52                                 Thread.sleep(beat);
53                                 // System.out.println("sleeping for "+beat);
54                                 // time = System.currentTimeMillis();
55
56                                 server.beating(TokenThread.Instance().getToken());
57
58                                 yield();
59
60                         } catch (Exception e) {
61                         }
62
63                 }
64         }
65 }