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
98 while( ret == 1 && loop < LOOP_MAX )
100 ret = stub.updateRegister(g, stubVoisin, requete);
104 if( loop == LOOP_MAX )
106 System.err.println( "Problem during register update!" ) ;
108 // System.out.println("Envoi du registre a :"+index);
110 // System.out.println("ancien registre");
112 // System.out.println("Le registre initial");
113 // Register.Instance().viewAll();
114 // System.out.println(" after update register");
115 // if updateRegister worked, that means Node is Alive
116 Node noeud = Register.Instance().getNodeOfStub(stub);
118 noeud.setAliveFlag(true);
119 noeud.setAliveTime();
122 } catch (Exception e) {
123 System.err.println(name + " ("
124 + LocalHost.Instance().resolve(name) + " rank=" + index
125 + ") cannot be reached by UpdateRegisterThread "
126 + " size : " + Register.Instance().getSize() + " :"
129 stub.suicide(" by Update");
130 // System.out.println("I suicide " + name + "\n\n");
131 } catch (Exception e2) {
132 // System.out.println("It is already Dead " + name +
140 private Vector<Integer> getDependencies(int id, int jaceSize) {
141 // get computing dependencies
142 Vector<Integer> neighbors = new Vector<Integer>();
146 // System.out.println("tache = null");
147 dep = tache.getDependencies(id);
148 // }catch(Exception e)
149 // {e.printStackTrace(System.out);}
150 for (int z = 0; z < taille(dep); z++)
151 neighbors.add(dep[z]);
152 // System.out.println("la liste des voisins de calcul de: "+id);
153 // for(int z=0;z<neighbors.size();z++)
154 // System.out.print(((Integer)neighbors.elementAt(z)).intValue()+" ");
155 // System.out.println();
156 // get convergence neighbors
158 while (Math.pow(2, d) < jaceSize) {
159 if (id < Math.pow(2, d) && ((id + Math.pow(2, d)) < jaceSize))
160 if (!neighbors.contains((Object) ((int) (id + Math.pow(2, d)))))
161 neighbors.add((int) (id + Math.pow(2, d)));
162 if (id < Math.pow(2, d + 1) && id >= Math.pow(2, d))
163 if (!neighbors.contains((Object) ((int) (id - Math.pow(2, d)))))
164 neighbors.add((int) (id - Math.pow(2, d)));
167 // System.out.println("taille="+neighbors.size());
168 // get backup neighbors
169 int nb = reg.getNumBackupNeighbors();
172 for (int j = 1; j <= nb; j++) {
173 // System.out.println("dans la boucle nb="+nb+" j="+j);
174 // ------------ 1 - for backups "j + n" (to the right of j)
175 rankOfBackTask = (id + j) % jaceSize;
176 if (!neighbors.contains((Object) rankOfBackTask))
177 neighbors.add(rankOfBackTask);
179 // ------------ 2 - for backups "j - n" (to the left of j)
182 rankOfBackTask = tmp % jaceSize;
184 rankOfBackTask = jaceSize - (Math.abs(tmp) % jaceSize);
186 if (!neighbors.contains((Object) rankOfBackTask))
187 neighbors.add(rankOfBackTask);
189 // System.out.println("taille="+neighbors.size());
196 public static int taille(int[] vect) {
199 while (x < vect.length && vect[x] >= 0) {