4 public class ScanThreadSuperNode extends Thread {
5 public static ScanThreadSuperNode Instance = null;
6 // public boolean scanning=false;
8 public int timeBeforeKill;
10 public int neighborRank;
11 private long aliveTime = System.currentTimeMillis();
12 private boolean token = false;
14 // public boolean running=false;
15 private ScanThreadSuperNode() {
16 beat = HeartBeatSNode.Instance().getHeartTime();
17 timeBeforeKill = beat * 4;
18 System.out.println("timebfk=" + timeBeforeKill);
23 public static ScanThreadSuperNode Instance() {
24 if (Instance == null) {
25 System.out.println("Creating new ScanThreadSuperNode ");
26 Instance = new ScanThreadSuperNode();
31 public synchronized void setAliveTime() {
32 aliveTime = System.currentTimeMillis();
33 // System.out.println("alive Time="+aliveTime);
36 public synchronized void setToken(boolean bool) {
40 // public void setScanning(boolean bool){
41 // System.out.println("in setScanning !!!!!");
44 // public void kill(){
48 @SuppressWarnings("static-access")
50 System.out.println("Start ScanThread for SuperNode.......");
52 // System.out.println("ScanThread alive.......");
54 * if(scanning==false) try{ this.wait(); }catch(Exception e){} else{
56 // System.out.println("test Neighbor: "+neighborRank);
60 } catch (Exception e) {
66 public void testNeighbor() {
75 //boolean changed = false;
78 currentTime = System.currentTimeMillis();
79 if (currentTime - aliveTime > timeBeforeKill) {
80 System.out.println("neighbor maybe Dead, "
81 + (currentTime - aliveTime) + " " + currentTime + " "
82 + aliveTime + " result "
83 + (currentTime - aliveTime > timeBeforeKill)
84 + " timebk=" + timeBeforeKill);
85 int index = SuperNodeListe.Instance().existSuperNode(
86 LocalHost.Instance().getIP());
90 index = SuperNodeListe.Instance().getListe().size() - 1;
92 synchronized (SuperNodeListe.Instance()) {
93 System.out.println("Removing "
94 + ((SuperNodeData) SuperNodeListe.Instance()
95 .getListe().elementAt(index)).getIP());
96 data = (SuperNodeData) SuperNodeListe.Instance().getListe()
98 SuperNodeListe.Instance().removeSuperNode(
99 ((SuperNodeData) SuperNodeListe.Instance()
100 .getListe().elementAt(index)));
103 // diffusing the message concerning a dead superNode
104 for (int i = 0; i < SuperNodeListe.Instance().getListe().size(); i++)
106 if (!((SuperNodeData) SuperNodeListe.Instance()
107 .getListe().elementAt(i)).getIP().equals(
108 LocalHost.Instance().getIP()))
109 ((SuperNodeData) SuperNodeListe.Instance()
110 .getListe().elementAt(i)).getStub()
111 .removeSuperNode(data);
112 } catch (Exception e2) {
114 .println("Error diffusing the message concerning a dead superNode: "
118 // synchronized(TokenThread.Instance()){
119 TokenThread.Instance().setToken();
120 // TokenThread.Instance().notify();
123 index = SuperNodeListe.Instance().existSuperNode(
124 LocalHost.Instance().getIP());
128 index = SuperNodeListe.Instance().getListe().size() - 1;
129 ((SuperNodeData) SuperNodeListe.Instance().getListe()
130 .elementAt(index)).getStub().updateHeart(
131 LocalHost.Instance().getSuperNodeStub());
134 } catch (Exception e) {
135 System.err.println("Error in testNeighbor: " + e);