3 import java.util.Vector;
5 class UpdateRegisterThread extends Thread {
6 // Register reg = Register.Instance();
11 int nbOfDeamonsPerThread;
12 int nbOfDeamonsPerSpawner;
14 public UpdateRegisterThread(Task tache, Register r, int req, int i,
22 nbOfDeamonsPerThread = JaceSpawner.Instance().getNbOfDeamonsPerThread();
23 nbOfDeamonsPerSpawner = JaceSpawner.Instance()
24 .getNbOfDeamonsPerSpawner();
25 // requete=1 if beginning of appli to ping the spawner and not a
27 // requete=0 if only update Register
29 * told in another way : if requete = 1, update the Register AND the
30 * beating Server on each node else, only update the Register on each
36 // method launched by start()
38 ListeTask listOfTasks = reg.getListeOfTasks();
39 // System.out.println("Thread "+i+" start from "+(debut+i*nbOfDeamonsPerThread)+" till "+(debut+i*nbOfDeamonsPerThread+nbOfDeamonsPerThread)+" or "+(debut+nbOfDeamonsPerSpawner)+" or "+listOfTasks.getSize());
40 for (int index = debut + i * nbOfDeamonsPerThread; index < debut + i
41 * nbOfDeamonsPerThread + nbOfDeamonsPerThread
42 && index < debut + nbOfDeamonsPerSpawner
43 && index < listOfTasks.getSize(); index++) {
44 // Node node = Register.Instance().getNodeAt(index);
45 // Node node = reg.getNodeAt(index);
46 // Node voisin=reg.getNodeAt((index+1)%reg.getSize());
47 Vector<Integer> dependencies = getDependencies(index, listOfTasks.getSize());
48 // System.out.println("la liste des voisins de : "+index);
49 // for(int z=0;z<dependencies.size();z++)
50 // System.out.print(((Integer)dependencies.elementAt(z)).intValue()+" ");
51 // System.out.println();
52 System.out.println(dependencies.size());
53 Register g = new Register();
54 ListeTask newListOfTasks = new ListeTask();
55 g.setAppliName(reg.getAppliName());
56 g.setParams(reg.getParams());
57 g.setSpawnerStub(reg.getSpawnerStub());
58 g.setNbOfTasks(reg.getNbOfTasks());
59 // g.setVersion(reg.getVersion());
60 for (int j = 0; j < dependencies.size(); j++) {
61 TaskId id = listOfTasks.getTaskIdOfRank(((Integer) dependencies
62 .elementAt(j)).intValue());
63 // System.out.println("got id of :"+((Integer)dependencies.elementAt(j)).intValue());
64 newListOfTasks.addTask(id);
65 if (id.getHostStub() != null) {
66 Node noeud = reg.getNodeOfStub(id.getHostStub());
70 g.setListeOfTasks(newListOfTasks);
72 TaskId neighborTask = listOfTasks.getTaskIdOfRank((index + 1)
73 % listOfTasks.getSize());
74 // if (node == null) {
75 // System.out.println("node NUULL");
77 JaceInterface stubVoisin = neighborTask.getHostStub();
78 JaceInterface stub = listOfTasks.getTaskIdOfRank(index)
80 if (stub == null && stubVoisin == null) {
81 System.out.println("stub NULL");
84 String name = listOfTasks.getTaskIdOfRank(index).getHostName();
88 // whatever the case, uate the Register on each Node
90 // JaceSpawnerInterface ja=Register.Instance().getSpawnerStub();
91 // System.out.println("avant update register");
93 // 1 l'appli vient de commencer
94 stub.updateRegister(g, stubVoisin, requete);
95 // System.out.println("Envoi du registre a :"+index);
97 // System.out.println("ancien registre");
99 // System.out.println("Le registre initial");
100 // Register.Instance().viewAll();
101 // System.out.println(" after update register");
102 // if updateRegister worked, that means Node is Alive
103 Node noeud = Register.Instance().getNodeOfStub(stub);
105 noeud.setAliveFlag(true);
106 noeud.setAliveTime();
109 } catch (Exception e) {
110 System.err.println(name + " ("
111 + LocalHost.Instance().resolve(name) + " rank=" + index
112 + ") cannot be reached by UpdateRegisterThread "
113 + " size : " + Register.Instance().getSize() + " :"
116 stub.suicide(" by Update");
117 // System.out.println("I suicide " + name + "\n\n");
118 } catch (Exception e2) {
119 // System.out.println("It is already Dead " + name +
127 private Vector<Integer> getDependencies(int id, int jaceSize) {
128 // get computing dependencies
129 Vector<Integer> neighbors = new Vector<Integer>();
133 // System.out.println("tache = null");
134 dep = tache.getDependencies(id);
135 // }catch(Exception e)
136 // {e.printStackTrace(System.out);}
137 for (int z = 0; z < taille(dep); z++)
138 neighbors.add(dep[z]);
139 // System.out.println("la liste des voisins de calcul de: "+id);
140 // for(int z=0;z<neighbors.size();z++)
141 // System.out.print(((Integer)neighbors.elementAt(z)).intValue()+" ");
142 // System.out.println();
143 // get convergence neighbors
145 while (Math.pow(2, d) < jaceSize) {
146 if (id < Math.pow(2, d) && ((id + Math.pow(2, d)) < jaceSize))
147 if (!neighbors.contains((Object) ((int) (id + Math.pow(2, d)))))
148 neighbors.add((int) (id + Math.pow(2, d)));
149 if (id < Math.pow(2, d + 1) && id >= Math.pow(2, d))
150 if (!neighbors.contains((Object) ((int) (id - Math.pow(2, d)))))
151 neighbors.add((int) (id - Math.pow(2, d)));
154 // System.out.println("taille="+neighbors.size());
155 // get backup neighbors
156 int nb = reg.getNumBackupNeighbors();
159 for (int j = 1; j <= nb; j++) {
160 // System.out.println("dans la boucle nb="+nb+" j="+j);
161 // ------------ 1 - for backups "j + n" (to the right of j)
162 rankOfBackTask = (id + j) % jaceSize;
163 if (!neighbors.contains((Object) rankOfBackTask))
164 neighbors.add(rankOfBackTask);
166 // ------------ 2 - for backups "j - n" (to the left of j)
169 rankOfBackTask = tmp % jaceSize;
171 rankOfBackTask = jaceSize - (Math.abs(tmp) % jaceSize);
173 if (!neighbors.contains((Object) rankOfBackTask))
174 neighbors.add(rankOfBackTask);
176 // System.out.println("taille="+neighbors.size());
183 public static int taille(int[] vect) {
186 while (x < vect.length && vect[x] >= 0) {