3 import java.util.Vector;
5 class UpdateRegisterConcernedThread extends Thread {
10 @SuppressWarnings("unchecked")
12 int nbOfDeamonsPerThread;
15 @SuppressWarnings("unchecked")
16 public UpdateRegisterConcernedThread(Vector neighbors, Register r, int i,
17 int rank, Node noeud, Node tmpNode) {
23 this.neighbors = neighbors;
26 nbOfDeamonsPerThread = JaceSpawner.Instance().getNbOfDeamonsPerThread();
30 ListeTask listOfTasks = Register.Instance().getListeOfTasks().clone();
31 // boolean retry = false ;
33 // int nbRetryMax = 2 ;
37 // listOfTasks.viewAll();
38 for (int index = i * nbOfDeamonsPerThread; index < i
39 * nbOfDeamonsPerThread + nbOfDeamonsPerThread
40 && index < neighbors.size(); index++)
49 if (((Integer) neighbors.elementAt(index)).intValue() == rank) {
50 Register g = new Register();
51 ListeTask newListOfTasks = new ListeTask();
52 g.setAppliName(reg.getAppliName());
53 g.setParams(reg.getParams());
55 g.setSpawnerStub(JaceSpawner.Instance()
56 .getSpawnerResponsibleOn(rank));
57 g.setNbOfTasks(reg.getNbOfTasks());
59 for (int j = 0; j < neighbors.size(); j++) {
60 TaskId id = listOfTasks
61 .getTaskIdOfRank(((Integer) neighbors
62 .elementAt(j)).intValue()) ;
63 newListOfTasks.addTask( id ) ;
64 if( id.getHostStub() != null ) {
65 Node noeud = reg.getNodeOfStub( id.getHostStub() ) ;
71 noeud = reg.getNodeOfName( id.getHostName() ) ;
77 System.err.println( "UpdateRegisterConcernedThread: cannot found the corresponding node !" ) ;
83 g.setListeOfTasks(newListOfTasks);
85 TaskId neighborTask = listOfTasks
86 .getTaskIdOfRank((((Integer) neighbors
87 .elementAt(index)).intValue() + 1)
88 % listOfTasks.getSize());
89 JaceInterface stubVoisin = neighborTask.getHostStub();
90 JaceInterface stub = listOfTasks.getTaskIdOfRank(
91 ((Integer) neighbors.elementAt(index)).intValue())
93 if( stub == null || stubVoisin == null )
95 System.out.println("stub NULL");
97 name = listOfTasks.getTaskIdOfRank(
98 ((Integer) neighbors.elementAt(index))
99 .intValue()).getHostName();
104 // whatever the case, update the Register on each Node
106 // JaceSpawnerInterface
107 // ja=Register.Instance().getSpawnerStub();
108 // System.out.println("avant update register");
110 stub.updateRegister( g, stubVoisin, 0 ) ;
112 // System.out.println(" after update register");
113 // if updateRegister worked, that means Node is
115 noeud = Register.Instance()
116 .getNodeOfStub(stub);
118 noeud.setAliveFlag(true);
119 noeud.setAliveTime();
123 } catch( Exception e ) {
127 + LocalHost.Instance()
131 + ") cannot be reached by UpdateRegisterConcernedThread for new node "
133 + Register.Instance().getSize()
136 // Thread.sleep( (nbRetry + 1) * 2000 ) ;
137 // }catch(Exception sl){}
140 // if( nbRetry > nbRetryMax )
143 // System.err.println( "Cannot retry anymore!" ) ;
144 // if( noeud != null )
147 // JaceSpawner.Instance().signalDeadNode( noeud.getStub(), index ) ;
148 // } catch( Exception ex ) {
149 // JaceSpawner.Instance().signalDeadNode( null, index ) ;
152 // JaceSpawner.Instance().signalDeadNode( null, index ) ;
159 TaskId id = listOfTasks
160 .getTaskIdOfRank(((Integer) neighbors
161 .elementAt(index)).intValue());
162 name = id.getHostName();
166 JaceInterface stub = id.getHostStub() ;
167 stub.updateRegister( oldNode, node, rank ) ;
169 } catch (Exception e) {
173 + LocalHost.Instance().resolve(name)
176 + ") cannot be reached by UpdateRegisterConcernedThread size : "
177 + Register.Instance().getSize() + " :"
181 // Thread.sleep( (nbRetry + 1) * 2000 ) ;
182 // }catch(Exception sl){}
185 // if( nbRetry > nbRetryMax )
188 // System.err.println( "Cannot retry anymore!" ) ;
192 } catch( Exception e2 ) {
193 System.err.println("Error in updateRegisterConcernedThread :"
198 // if( nbRetry > nbRetryMax )
203 // System.out.println("at the end of an updateRegisterCon. j="+i);
204 // Register.Instance().getListeOfTasks().viewAll();
207 @SuppressWarnings("unused")
208 private Vector<Integer> getDependencies(int id, int jaceSize) {
209 // get computing dependencies
210 Vector<Integer> neighbors = new Vector<Integer>();
211 int[] dep = tache.getDependencies(id);
212 for (int z = 0; z < taille(dep); z++)
213 neighbors.add(dep[z]);
214 // System.out.println("la liste des voisins de calcul de: "+id);
215 // for(int z=0;z<neighbors.size();z++)
216 // System.out.print(((Integer)neighbors.elementAt(z)).intValue()+" ");
217 // System.out.println();
218 // get convergence neighbors
220 while (Math.pow(2, d) < jaceSize) {
221 if (id < Math.pow(2, d) && ((id + Math.pow(2, d)) < jaceSize))
222 if (!neighbors.contains((Object) ((int) (id + Math.pow(2, d)))))
223 neighbors.add((int) (id + Math.pow(2, d)));
224 if (id < Math.pow(2, d + 1) && id >= Math.pow(2, d))
225 if (!neighbors.contains((Object) ((int) (id - Math.pow(2, d)))))
226 neighbors.add((int) (id - Math.pow(2, d)));
230 // get backup neighbors
231 int nb = reg.getNumBackupNeighbors();
234 for (int j = 1; j <= nb; j++) {
235 // ------------ 1 - for backups "j + n" (to the right of j)
236 rankOfBackTask = (id + j) % jaceSize;
237 if (!neighbors.contains((Object) rankOfBackTask))
238 neighbors.add(rankOfBackTask);
240 // ------------ 2 - for backups "j - n" (to the left of j)
243 rankOfBackTask = tmp % jaceSize;
245 rankOfBackTask = jaceSize - (Math.abs(tmp) % jaceSize);
247 if (!neighbors.contains((Object) rankOfBackTask))
248 neighbors.add(rankOfBackTask);
256 public static int taille(int[] vect) {
259 while (x < vect.length && vect[x] >= 0) {