3 import java.rmi.RemoteException;
6 public class ScanThread extends Thread {
7 public static ScanThread Instance;
8 public boolean scanning = false;
10 public int timeBeforeKill;
12 public int neighborRank;
13 public boolean running = false;
15 private ScanThread() {
16 beat = HeartBeatThread.Instance().getHeartTime();
17 timeBeforeKill = beat * 3;
22 public static ScanThread Instance() {
23 if (Instance == null) {
24 System.out.println("Creating new ScanThread ");
25 Instance = new ScanThread();
30 public void setScanning(boolean bool) {
31 // System.out.println("in setScanning !!!!!");
40 @SuppressWarnings("static-access")
42 System.out.println("Start ScanThread.......");
44 // System.out.println("ScanThread alive.......");
45 if (scanning == false)
48 } catch (Exception e) {
51 // System.out.println("test Neighbor: "+neighborRank);
55 } catch (Exception e) {
61 @SuppressWarnings("static-access")
62 public void testNeighbor() {
71 //boolean changed = false;
73 TaskId id = Register.Instance().getListeOfTasks()
74 .getTaskIdOfHostStub(LocalHost.Instance().getStub());
75 myRank = id.getRank();
77 neighborRank = Register.Instance().getNbOfTasks() - 1;
79 neighborRank = myRank - 1;
81 // TaskId myTaskId = null;
82 TaskId neighborTask = Register.Instance().getListeOfTasks()
83 .getTaskIdOfRank(neighborRank);
84 JaceInterface jaceStub = neighborTask.getHostStub();
85 host = Register.Instance().getNodeOfStub(jaceStub);
86 // if (host.getAliveFlag() == true) {
87 workerTime = host.getAliveTime();
88 currentTime = System.currentTimeMillis();
89 if (currentTime - workerTime > timeBeforeKill) {
90 // Calendar cal = new GregorianCalendar();
91 // System.out.println("at time="+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
92 // System.out.println("currentTime="+currentTime+" workerTime="+workerTime+" timeBeforeKill="+timeBeforeKill);
94 host.setAliveFlag(false);
95 host.setAppliName(null);
97 // String ip = LocalHost.Instance().resolve(host.getName());
101 Node noeud = Register.Instance().getNodeOfStub(
104 reponse = host.getStub().ping();
105 if (reponse == true) {
106 noeud.setAliveFlag(true);
107 noeud.setAliveTime();
108 noeud.getAliveTime();
109 // System.out.println("the previous node is still alive");
113 host.getStub().suicide("Not responding");
114 System.out.println("\n\nNot responding node "
115 + host.getName() + " (" + host.getIP()
117 + Register.Instance().getNbOfTasks());
120 } catch (Exception e) {
124 System.out.println("\n\nDisconnection of "
125 + host.getName() + " (" + host.getIP()
127 + Register.Instance().getNbOfTasks());
131 JaceSpawnerInterface spawnerStub = Register.Instance()
133 if (spawnerStub == null)
134 System.err.println("SpawnerStub is null");
136 spawnerStub.signalDeadNode(jaceStub, neighborRank);
138 this.sleep(10 * beat);
140 } catch (RemoteException e1) {
141 System.err.println("Couldn't reach the spawner: "
147 } catch (Exception e) {
148 System.err.println("Error in testNeighbor: " + e);
150 } catch (Exception e) {
151 if (Register.Instance().getListeOfTasks() == null)
152 System.err.println("Task list is null: " + e);