3 import java.io.FileOutputStream;
4 import java.io.OutputStreamWriter;
5 import java.io.PrintWriter;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
8 import java.rmi.UnmarshalException;
9 import java.util.Calendar;
10 import java.util.GregorianCalendar;
11 import java.util.Random;
12 import java.util.Vector;
14 import and.Mapping.Algo;
15 import and.Mapping.Utils;
17 public class JaceSpawner {
20 private Task tache = null;
21 public static JaceSpawner Instance;
22 private static String superNode_IP = null;
23 private int superNode_port = 1098;
24 private static int spawnerPort = 1098;
25 protected static JaceSuperNodeInterface centralServer = null;
26 private JaceSpawnerInterface spawnerRef = null;
28 private String appliName;
29 private String[] params = null;
30 @SuppressWarnings("unused")
31 private String protocol;
32 // private int registerVersion=0;
33 final int NB_HEART_DECONNECT = 3;
34 private int heartTime; // frequency of heartBeat
35 @SuppressWarnings("unused")
36 private int timeBeforeKill; // wait 3 non-response of heartBeat before
37 // considering de Daemon as dead
38 private boolean broadcasting = false;
39 @SuppressWarnings("unused")
41 private static int nbOfDaemonsPerSpawner;
42 private static int nbOfDeamonsPerThread;
43 private Vector<Object> spawnersList;
45 private int nbSavingNodes;
47 // Variables for Mapping
49 private double paramAlgo ;
50 private String idAlgo ;
55 protected int nbFault ;
56 protected int faultTime ;
58 public JaceSpawner(String superNode, int port, String comProtocol,
59 String[] args, int nbDaemonPerSpawner, int nbDaemonPerThread,
60 int nbSavingNodes, int _algo, double _paramAlgo, int _test, int _nbF, int _fT) {
61 // superNode_IP = LocalHost.Instance().resolve(superNode);
63 paramAlgo = _paramAlgo ;
71 superNode_IP = superNode;
73 protocol = comProtocol;
74 nbOfDaemonsPerSpawner = nbDaemonPerSpawner;
75 nbOfDeamonsPerThread = nbDaemonPerThread;
76 this.nbSavingNodes = nbSavingNodes;
79 // if less than 2 params (nb of tasks and name of the appli), error
80 System.err.println( "Parameters error !" ) ;
84 nbTasks = new Integer(args[0]).intValue(); // nb of tasks
87 } catch (Exception e) {
88 System.err.println("Number format exception :" + e ) ;
91 appliName = args[1]; // name of the class to launch
92 if (args.length > 2) { // get the eventual param of the appli
93 params = new String[args.length - 2];
94 for (int i = 0; i < params.length; i++) {
95 params[i] = args[2 + i];
99 c = load.load(appliName);
101 tache = ((Task) c.newInstance());
102 tache.setParam(params);
103 tache.setJaceSize(nbTasks);
105 // ****************//
107 } catch (Exception e) {
108 System.err.println( "Unable to instantiate the class " + e ) ;
118 public JaceSpawner(String[] params, String appliName, Register reg,
119 int nbTasks, JaceSuperNodeInterface snodeStub, int rank,
120 int heartTime, int tag, int nbdc, int nbsdc,
121 int nbDaemonPerSpawner, int nbDaemonPerThread, String _idAlgo) {
123 nbOfDaemonsPerSpawner = nbDaemonPerSpawner;
124 nbOfDeamonsPerThread = nbDaemonPerThread;
125 if (params.length != 0) {
126 this.params = new String[params.length];
127 for (int i = 0; i < params.length; i++)
128 this.params[i] = params[i];
131 System.err.println( "There is no parameter !" ) ;
133 } catch (Exception e) {
134 System.err.println("Error in copying the parameters: " + e ) ;
139 this.appliName = appliName;
141 this.nbTasks = nbTasks;
142 this.heartTime = heartTime;
143 LocalHost.Instance().setSuperNodeStub(snodeStub);
144 centralServer = snodeStub;
146 Register.Instance().replaceBy(reg);
147 Register.Instance().setSpawnerStub(this.spawnerRef);
148 Register.Instance().getListeOfTasks().viewAll();
152 c = load.load(appliName);
154 tache = ((Task) c.newInstance());
155 tache.setParam(params);
156 tache.setJaceSize(nbTasks);
157 // ****************//
159 } catch (Exception e) {
160 System.err.println("Unable to instantiate the class " + e);
162 RunningApplication.Instance().getChrono().start();
164 RunningApplication.Instance().setName(appliName);
165 RunningApplication.Instance().setNbTasks(nbTasks);
166 RunningApplication.Instance().setRunning(true);
167 RunningApplication.Instance().setNumberOfDisconnections(nbdc);
168 RunningApplication.Instance().setNumberOfSpawnerDisconnections(nbsdc);
172 broadcastRegister(1);
175 * x=Register.Instance().getListeOfTasks().getSize()/nbOfDaemonsPerSpawner
176 * ; int s; if(rank==x)
177 * s=(reg.getListeOfTasks().getSize()%nbOfDaemonsPerSpawner
178 * )/nbOfDeamonsPerThread; else
179 * s=nbOfDaemonsPerSpawner/nbOfDeamonsPerThread;
181 * int debut=nbOfDaemonsPerSpawnerrank;
184 * for(int i=0;i<s+1;i++){
186 * new BroadcastSpawner(i,
187 * debut,nbOfDaemonsPerSpawner,nbOfDeamonsPerThread).start(); }
191 System.out.println("########################");
194 public synchronized static JaceSpawner Instance() {
198 public int getNbOfDeamonsPerThread() {
199 return nbOfDeamonsPerThread;
202 public int getNbOfDeamonsPerSpawner() {
203 return nbOfDaemonsPerSpawner;
206 public void startProcess(Vector<Object> spawnersList) {
207 this.spawnersList = spawnersList;
209 int is = spawnersList.indexOf((Object) Register.Instance()
214 if (is == spawnersList.size() - 1)
217 nextNeighbour = is + 1;
219 * while((spawnersList.elementAt(nextNeighbour) instanceof Node))
221 * System.out.println("waiting till transform of spawner "+nextNeighbour
222 * +" is finished, for setServer"); Thread.sleep(20);
223 * }catch(Exception e1){}
225 HeartBeatSpawner.Instance().setServer(
226 (JaceSpawnerInterface) spawnersList.get(nextNeighbour));
227 HeartBeatSpawner.Instance().setHeartTime(heartTime);
228 HeartBeatSpawner.Instance().start();
229 int previousNeighbour;
231 previousNeighbour = spawnersList.size() - 1;
233 previousNeighbour = is - 1;
234 ScanThreadSpawner.Instance().setHeartTime(heartTime);
235 ScanThreadSpawner.Instance().setServer(
236 (JaceSpawnerInterface) spawnersList.get(previousNeighbour));
237 ScanThreadSpawner.Instance().start();
241 new StartScanning().start();
243 System.err.println("Cannot find myself in the spawnersList !");
248 public void setBroadcasting(boolean bool) {
252 public void initialize() {
253 // if(protocol.equals("rmi")){
254 // launch the JaceSpawnerServer
255 if (System.getSecurityManager() == null) {
256 System.setSecurityManager(new SecurityManager());
265 // get a Register on the Super Node
266 // completed with the required number of Daemons
267 getRegisterOnSuperNode();
270 createSpawnerNetwork();
273 new FaultMake().run() ;
277 public void startScanning() {
279 long time = RunningApplication.Instance().getChrono().getValue() / 1000;
280 System.out.println("Start scanning at time: " + time + "s");
281 // lancer le chrono qui gere les heart beat
282 while (RunningApplication.Instance().isRunning() == true) {
283 // 1 etape : scaner tous les "heartTime" milisecondes si les noeuds
284 // enregistes sont encore vivants
285 // res = scanConnectedHosts();
287 // 2 etape : a garder ou pas !!!!! regarder si l'appli est en
288 // attente de noeud pr lui en attribuer 1 nvx
291 Thread.sleep(heartTime);
292 } catch (Exception e) {
295 // /System.out.println("is running = false");
296 if (!JaceDaemon.Instance().isRunning())
300 public synchronized void signalDeadNode(JaceInterface host, int rankOfDead) {
303 TaskId myTaskId = null;
307 RunningApplication.Instance().incrementNumberOfDisconnections();
309 time = RunningApplication.Instance().getChrono().getValue() / 1000;
310 nb = RunningApplication.Instance().getNumberOfDisconnections();
311 nbC = RunningApplication.Instance().getNumberOfCouilles();
312 System.out.println("At time = " + time + "s, NbDisconnection = "
313 + nb + ", NbProblem = " + nbC);
316 System.err.println( "SIGNAL DE NODE NULL" ) ;
318 // !!!!!!!!!!!!!!actualiser le ListeTask ds le Register
320 myTaskId = Register.Instance().getListeOfTasks()
321 .getTaskIdOfHostStub(host);
322 } catch( Exception e ) {}
324 if (myTaskId == null) {
325 myTaskId = Register.Instance().getListeOfTasks()
326 .getTaskIdOfRank(rankOfDead);
327 if( myTaskId == null )
329 System.err.println("Houston we have a serious problem!!");
333 JaceInterface deadStub = myTaskId.getHostStub();
335 if( deadStub != null )
338 deadStub.suicide2("Not doing a good work");
339 }catch(Exception e){}
341 System.err.println( "Dead node stub unavailable!" );
345 Node noeud = Register.Instance().getNodeOfName( myTaskId.getHostName() ) ;
347 int rankDeaD = myTaskId.getRank();
349 String nomNoeud = "" ;
353 nomNoeud = noeud.getName();
358 if( ! nomNoeud.equals( "" ) )
360 b = Register.Instance().removeNodeOfName( nomNoeud ) ;
362 System.err.println( "Dead node name unknown!!" ) ;
367 b = Register.Instance().removeNode( noeud ) ;
372 System.out.println("Removing Node of rank "
373 + rankDeaD + " : size = "
374 + Register.Instance().getSize());
377 .println("Cannot remove the Node, it doesn't exist anymore: size = "
378 + Register.Instance().getSize());
381 Calendar cal = new GregorianCalendar();
382 System.out.println("At time=" + cal.get(Calendar.MINUTE) + ":"
383 + cal.get(Calendar.SECOND));
385 /**** Sébastien Miquée **/
386 Node tmpNode = null ;
387 int retry = 0, retryMax = 4 ;
389 while( tmpNode == null )
391 tmpNode = foundToReplaceThisNode(rankDeaD, nomNoeud, noeud);
393 if( tmpNode == null )
396 Thread.sleep( 1000 ) ;
397 } catch( Exception e ) {}
401 if( retry > retryMax )
403 System.err.println( "Unable to replace the dead node "+nomNoeud ) ;
410 updateConcernedNodes(rankDeaD, noeud, tmpNode);
413 System.out.println("Set scanning on "+tmpNode.getName());
414 tmpNode.getStub().setScanning( true ) ;
415 } catch (Exception e) {
417 Thread.sleep( 2000 ) ;
419 tmpNode.getStub().setScanning( true ) ;
420 } catch (InterruptedException e1) {
421 } catch (RemoteException e2) {
422 System.err.println( "Unable to setScanning on for the new node: " + e2 ) ;
424 System.err.println("Unable to setScanning on for the new node: "
428 for (int z = 0; z < spawnersList.size(); z++)
430 if (!((JaceSpawnerInterface) spawnersList.get(z))
431 .equals(Register.Instance().getSpawnerStub()))
434 ((JaceSpawnerInterface) spawnersList.get(z))
435 .replaceDeamonBy(noeud, tmpNode, rankDeaD);
437 } catch (Exception e) {
439 .println("Unable to broadcast the modifications to all the spawners: "
446 // verifie si les noeud notes vivant ds le Register.Instance() du SuperNode
448 // retourne 0 si erreur, 1 sinon
450 * private synchronized int scanConnectedHosts() { long time = 0; Node host;
451 * Node tmpNode; long workerTime; long currentTime; int rank; int restempo;
452 * int nb = 0; int nbC = 0; boolean changed = false; int index=0; try{
453 * JaceSpawnerInterface spawnerStub=Register.Instance().getSpawnerStub();
454 * if(spawnerStub.getFinished()==true){
455 * System.out.println("nbre de taches="+Register.Instance().getSize());
456 * ListeTask t=Register.Instance().getListeOfTasks();
457 * for(index=z;index<t.getSize();index++){ TaskId recev = null;
458 * System.out.println("deleting Task************"+index);
460 * recev = t.get(index); JaceInterface stub=recev.getHostStub();
461 * spawnerStub.killApplication(stub); }
465 * } }catch(Exception e){
466 * System.out.println("w aiiiiiiiiiiiiiirrrr"+e+" index="+index); z=index;
469 * if (Register.Instance().getSize() == 0) {
470 * System.out.println("aucun noeuds a scanner");
471 * RunningApplication.Instance().purge(); System.exit(0);
478 // trouver un noeud sur les superNode
479 // pr les requisitionner
481 /*** Sébastien Miquée ***/
482 private synchronized Node foundToReplaceThisNode(int theRank, String nom, Node _n)
484 boolean found = false ;
488 while( found == false ) {
492 node = centralServer.getNewNode( idAlgo, theRank ) ;
494 if( node != null && ! node.getIP().isEmpty() && node.getIP() != null
495 && ! node.getIP().equals( "" ) )
499 System.err.println("Returned node is null!");
502 Thread.sleep( 2000 ) ;
503 } catch( Exception e ) {}
505 } catch (Exception e) {
506 // trouver un autre superNode et lui demander le noeud a lui
508 System.err.println("Cannot localize SuperNode ! " + e);
513 if( Register.Instance().existNode( node ) != -1 )
522 System.out.println( "Using Node " + node.getName() + " in order to replace " + nom + "\n" ) ;
524 node.setAliveFlag(true);
527 // rajouter le noeud ds le Register
528 node.setAppliName(RunningApplication.Instance().getName());
530 // lui envoyer mon stub pr qu'il commence a me pinguer des
532 // TODO a mettre ds un thread ????
536 * neighborTask=Register.Instance().getListeOfTasks().getTaskIdOfRank
537 * ((theRank+1)%Register.Instance().getListeOfTasks().getSize());
538 * try{ node.getStub().updateHeart(neighborTask.getHostStub()); }
539 * catch(Exception e) {
540 * System.out.println("nvx noeud deja plu dispo2"); //node = null; }
542 // TODO verif pourkoi superNode me le redonne
543 // alors qu'il fait deja du calcul
544 // int is = Register.Instance().existNode(node.getIP());
545 int is = Register.Instance().existNode( node ) ;
549 System.out.println("The Node is already in the register ! I don't add it.");
550 System.out.println("Node " + node.getName() + " not added !") ;
553 Register.Instance().addNode(node);
555 // !!!!!!!!!!!!!!actualiser le ListeTask
556 TaskId myTaskId = Register.Instance().getListeOfTasks()
557 .getTaskIdOfRank(theRank);
558 myTaskId.setHostIP(node.getIP());
559 myTaskId.setHostName(node.getName());
560 myTaskId.setHostStub(node.getStub());
565 neighborRank = Register.Instance().getSize() - 1;
567 neighborRank = theRank - 1;
570 TaskId neighborTask2 = Register.Instance().getListeOfTasks()
571 .getTaskIdOfRank( neighborRank ) ;
573 int loop = 0, MAX_LOOP = 1 ;
575 JaceInterface jaceStub = null ;
577 while( !ok && loop < MAX_LOOP )
580 jaceStub = neighborTask2.getHostStub();
581 jaceStub.updateHeart(node.getStub());
584 } catch( Exception e ) {
587 if( loop < MAX_LOOP )
590 Thread.sleep( loop * 2000 ) ;
591 } catch (InterruptedException e1) {}
594 if( loop == MAX_LOOP )
596 System.err.println( "Next node unreachable! " + e ) ;
601 if( loop == MAX_LOOP )
605 node.getStub().suicide2( "Not reachable!" ) ;
606 } catch (RemoteException e1) {
607 System.err.println( "Unable to suicide the node!\n"+e1 );
608 signalDeadNode( null, neighborTask2.getRank() ) ;
615 System.out.println("I didn't receive a new Node !");
620 public void replaceBy(JaceSpawnerInterface oldStub,
621 JaceSpawnerInterface stub) {
622 int index = spawnersList.indexOf((Object) oldStub);
624 spawnersList.setElementAt(stub, index);
626 System.err.println("Spawner's stub not foud in spawnersList !");
629 public void getNewSpawner(JaceSpawnerInterface previousSpawner) {
630 //boolean found = false;
633 JaceSpawnerInterface spawnerStub = null;
635 // while (found == false) {
637 // TODO : trouver l'erreur !!!
639 // "pas localise le super node java.lang.NullPointerException"
640 if (centralServer == null) {
641 System.err.println("Central Server not localized !");
643 node = centralServer.getNewNode( idAlgo, -2 ) ;
644 RunningApplication.Instance()
645 .incrementNumberOfSpawnerDisconnections();
647 } catch (Exception e) {
648 // trouver un autre superNode et lui demander le noeud a lui
649 System.err.println("Super Node not localized !\n " + e);
650 System.err.println("My IP : " + LocalHost.Instance().getIP());
651 if (centralServer == null) {
652 System.err.println("CentralServer is NULL !");
658 index = spawnersList.indexOf((Object) previousSpawner);
660 System.out.println("Using Node " + node.getName()
662 + LocalHost.Instance().resolve(node.getName())
663 + ") to replace a dead spawner\n\n");
665 spawnerStub = node.getStub().transformIntoSpawner(
674 RunningApplication.Instance()
675 .getNumberOfDisconnections(),
676 RunningApplication.Instance()
677 .getNumberOfSpawnerDisconnections(),
678 nbOfDaemonsPerSpawner, nbOfDeamonsPerThread
680 spawnersList.setElementAt(spawnerStub, index);
683 new StartProcessThread(index).start();
685 } catch (Exception e) {
686 System.err.println("Unable to reach the new spawner: " + e);
688 for (int j = 0; j < spawnersList.size(); j++)
690 if (!((JaceSpawnerInterface) spawnersList.get(j))
691 .equals(Register.Instance().getSpawnerStub())
692 && !((JaceSpawnerInterface) spawnersList.get(j))
693 .equals(spawnerStub)) {
695 .println("Trying to broadcast to spawner of rank "
698 ((JaceSpawnerInterface) spawnersList.get(j))
699 .replaceBy(previousSpawner, spawnerStub);
701 } catch (Exception e) {
703 .println("Unable to broadcast to spawner of rank: "
704 + j + ". Error:" + e);
706 ScanThreadSpawner.Instance().setServer(spawnerStub);
710 previous = spawnersList.size() - 1;
712 previous = index - 1;
714 ((JaceSpawnerInterface) spawnersList.get(previous))
715 .updateHeart(spawnerStub);
716 } catch (Exception e) {
718 .println("Unable to change the server of the heartbeatThread for the previous node of rank "
719 + previous + ". error:" + e);
723 System.err.println("Node is null !");
728 public void broadcastFinished(boolean bool) {
729 for (int i = 0; i < spawnersList.size(); i++)
731 ((JaceSpawnerInterface) spawnersList.get(i)).setFinished(bool);
732 } catch (Exception e) {
734 .println("Unable to propagate the end of the application :"
739 private synchronized void scanAppliNodes() {
742 //ListeTask tskList = null;
746 JaceSpawnerInterface spawnerStub = Register.Instance()
748 if (spawnerStub.getFinished() == true) {
749 System.out.println("Number of tasks ="
750 + Register.Instance().getSize());
752 int x = Register.Instance().getListeOfTasks().getSize()
753 / nbOfDaemonsPerSpawner;
756 s = (Register.Instance().getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
757 / nbOfDeamonsPerThread;
759 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread;
761 int debut = nbOfDaemonsPerSpawner * rank;
763 // for(int i=debut;i<nbOfDaemonsPerSpawner*(rank+1) &&
764 // i<reg.getSize();i++)
765 // System.out.println(((Node)nodes.elementAt(i)).getName());
767 ListeTask t = Register.Instance().getListeOfTasks();
768 ScanThreadSpawner.Instance().kill();
769 HeartBeatSpawner.Instance().kill();
771 for (int i = 0; i < s + 1; i++) {
773 new KillThread(i, debut, nbOfDaemonsPerSpawner,
774 nbOfDeamonsPerThread, t).start();
779 long finalTime = RunningApplication.Instance().getChrono()
782 int nbe = RunningApplication.Instance()
783 .getNumberOfDisconnections();
785 int nbsdc = RunningApplication.Instance()
786 .getNumberOfSpawnerDisconnections();
788 System.out.println("Application finished successfully !");
790 System.out.println("TOTAL TIME in s : " + (finalTime / 1000));
791 System.out.println("nb of desconnections: " + nbe);
792 System.out.println("nb of spawners desconnections: " + nbsdc);
795 String path = "/home/lyon/smiquee/resultats/execTime_"+algo+"_"+test ;
796 PrintWriter ecrivain = null ;
797 ecrivain = new PrintWriter( new OutputStreamWriter( new FileOutputStream( path ), "UTF8" ) ) ;
799 ecrivain.println( "TOTAL TIME in s : " + (finalTime / 1000));
800 ecrivain.println( "nb of desconnections: " + nbe);
801 ecrivain.println( "nb of spawners desconnections: " + nbsdc);
802 ecrivain.println( "DH = "+dh ) ;
808 if (JaceDaemon.Instance().isRunning()) {
809 JaceDaemon.Instance().reconnectSuperNode();
811 RunningApplication.Instance().purge();
816 RunningApplication.Instance().purge();
819 /** Suprresion of the mapping algorithm on the SuperNode **/
820 centralServer.removeAlgo( idAlgo, 0 ) ;
822 } catch( Exception e ) {
823 System.err.println( "Error the application nodes scan!\n " + e ) ;
827 * if (Register.Instance().getSize() == 0) {
828 * System.out.println("aucun noeuds a scanner");
829 * RunningApplication.Instance().purge(); System.exit(0); return 0;
831 * } else{ tskList = Register.Instance().getListeOfTasks();
833 * //si mon appli a besoin d'un noeud //sinon, on fait rien if ((nbTasks
834 * - Register.Instance().getSize()) > 0) { cptReplaced = 0;
836 * //TODO demander des paquet de nodes, pas qu'un //on scanne toutes les
837 * taches de cette appli for (int ind = 0; ind < tskList.getSize();
838 * ind++) { //si 1 tache a pas de noeud, on trouve 1 remplacant
840 * //if (tskList.get(ind).getHostIP() == null) { if
841 * (tskList.get(ind).getHostStub() == null) { rank =
842 * tskList.get(ind).getRank(); node = foundToReplaceThisNodeTMP(rank);
843 * if (node != null) { cptReplaced++; }
847 * //qd fini de scanner taches, envoyer Register //si remplacement de
848 * noeud (c a d si Register modifier) if (cptReplaced != 0) {
849 * broadcastRegister(0); } try { Thread.currentThread().yield(); } catch
852 * }// fin if(appli.getNeededNodes() > 0) {
853 * //System.out.println("SCAN APPLI : taille : " +
854 * Register.Instance().getSize()); return 1; }
858 // @SuppressWarnings("unused")
859 // private synchronized Node foundToReplaceThisNodeTMP(int theRank) {
861 // boolean found = false;
863 // // while (found == false) {
865 // // TODO : trouver l'erreur !!!
867 // // "pas localise le super node java.lang.NullPointerException"
868 // if (centralServer == null) {
869 // System.out.println("centralServer est NUUUUUUUUULL");
871 // node = centralServer.getNewNode(LocalHost.Instance().getIP());
874 // } catch (Exception e) {
875 // // trouver un autre superNode et lui demander le noeud a lui
876 // System.out.println("TMP pas localise le super node " + e);
877 // System.out.println("TMP pas localise le super node " + e);
878 // System.out.println("TMP pas localise le super node " + e);
879 // System.out.println("TMP pas localise le super node " + e);
880 // System.out.println("TMP pas localise le super node " + e);
881 // System.out.println("TMP pas localise le super node " + e);
882 // System.out.println("TMP pas localise le super node " + e);
883 // System.out.println("mon IP : " + LocalHost.Instance().getIP());
884 // if (centralServer == null) {
885 // System.out.println("centralServer : NULL");
887 // connectSuperNode();
890 // if (node != null) {
891 // System.out.println("COOOOOOOOOOOOOOOOOOOOOOL : requisition de "
892 // + node.getName() + " taille avt add: "
893 // + Register.Instance().getSize() + "\n\n");
894 // node.setAliveFlag(true);
895 // node.setAliveTime();
897 // // rajouter le noeud ds le Register
898 // System.out.println("ds Register, manque "
899 // + (nbTasks - Register.Instance().getSize()));
900 // node.setAppliName(RunningApplication.Instance().getName());
902 // // lui envoyer mon stub pr qu'il commence a me pinguer des
904 // // TODO a mettre ds un thread ????
906 // TaskId neighborTask = Register.Instance().getListeOfTasks()
909 // % Register.Instance().getListeOfTasks()
911 // node.getStub().updateHeart(neighborTask.getHostStub());
912 // // node.getStub().updateHeart(this.spawnerRef);
914 // // int is = Register.Instance().existNode(node.getIP());
915 // int is = Register.Instance().existNode(node);
916 // // TODO verif pourkoi superNode me le redonne
917 // // alors qu'il fait deja du calcul
919 // System.out.println("j'ajoute pas le noeud, il y est deja");
920 // System.out.println("PAS AJOUTEE TMP " + node.getName());
921 // System.out.println("PAS AJOUTEE TMP " + node.getName());
922 // System.out.println("PAS AJOUTEE TMP " + node.getName());
923 // System.out.println("PAS AJOUTEE TMP " + node.getName());
924 // System.out.println("PAS AJOUTEE TMP " + node.getName());
927 // Register.Instance().addNode(node);
929 // // !!!!!!!!!!!!!!actualiser le ListeTask
930 // TaskId myTaskId = Register.Instance().getListeOfTasks()
931 // .getTaskIdOfRank(theRank);
932 // myTaskId.setHostIP(node.getIP());
933 // myTaskId.setHostName(node.getName());
934 // myTaskId.setHostStub(node.getStub());
935 // // Register.Instance().getListeOfTasks().getTaskIdOfRank(theRank).setHostIP(node.getIP());
936 // // Register.Instance().getListeOfTasks().getTaskIdOfRank(theRank).setHostName(node.getName());
937 // // Register.Instance().getListeOfTasks().getTaskIdOfRank(theRank).setHostStub(node.getStub());
939 // } catch (Exception e) {
940 // System.out.println("nvx noeud deja plu dispo");
944 // System.out.println("RADINNNNNNNNNNNNNN TMP ");
949 private void exportObject() {
951 JaceSpawnerServer spawnerServer = null;
953 System.out.println("Name of local machine is: "
954 + LocalHost.Instance().getName());
955 System.out.println("IP of local machine is: "
956 + LocalHost.Instance().getIP());
958 // launch the JaceSpawnerServer
959 spawnerServer = new JaceSpawnerServer();
960 java.rmi.registry.LocateRegistry.createRegistry(spawnerPort);
961 java.rmi.registry.LocateRegistry.getRegistry(spawnerPort).rebind(
962 "JaceSpawnerServer", spawnerServer);
963 spawnerRef = (JaceSpawnerInterface) Naming.lookup("rmi://"
964 + LocalHost.Instance().getIP() + ":" + spawnerPort
965 + "/JaceSpawnerServer");
967 } catch (Exception e) {
969 .println("JaceP2P_Error in JaceSpawner.exportObject() when creating the local JaceSpawnerServer "
971 // System.err.println("exit ds JaceSpawner.exportObject");
977 public void connectSuperNode() {
978 System.out.println("I'm looking for a super node");
979 boolean connected = false;
980 if (!(superNode_IP == null)) {
982 centralServer = null ;
985 System.out.println("Trying to invoke super node "
987 centralServer = (JaceSuperNodeInterface) Naming.lookup("rmi://"
988 + superNode_IP + ":" + superNode_port
990 System.out.println("Succesfully located " + superNode_IP);
992 // add stub and IP in LocalHost to store it until super node
994 LocalHost.Instance().setSuperNodeStub(centralServer);
995 LocalHost.Instance().setSuperNodeIP(superNode_IP);
996 heartTime = centralServer.getSuperNodeBeat();
997 timeBeforeKill = NB_HEART_DECONNECT * heartTime;
1000 } catch (Exception e) {
1001 System.err.println("Super Node not accessible, try another one (1/2s)");
1004 } catch (Exception e1) {
1009 if (connected == false) {
1011 SuperNodeListe.Instance().staticInitialization();
1012 while (connected == false
1013 && i < SuperNodeListe.Instance().getListe().size()) {
1014 SuperNodeData d = null;
1015 d = SuperNodeListe.Instance().getSuperNodeData(i);
1017 superNode_IP = LocalHost.Instance().resolve(d.getIP());
1018 superNode_port = d.getPort();
1019 // superNode_port = d.getPort();
1021 System.out.println("Trying to invoke Super Node "
1023 centralServer = (JaceSuperNodeInterface) Naming
1024 .lookup("rmi://" + superNode_IP + ":"
1025 + superNode_port + "/JaceSuperNode");
1026 System.out.println("Succesfully located SuperNode "
1028 LocalHost.Instance().setSuperNodeStub(centralServer);
1029 LocalHost.Instance().setSuperNodeIP(superNode_IP);
1030 heartTime = centralServer.getSuperNodeBeat();
1031 timeBeforeKill = NB_HEART_DECONNECT * heartTime;
1034 } catch (Exception e) {
1036 .println("SuperNode "
1038 + " not accessible, trying to locate another one in 0.5s\n");
1042 } catch (Exception e1) {
1048 if (connected == false) {
1049 System.err.println("All the Super Nodes in the list are not accessible. I'm unable to connect to the platform !");
1055 // get a Register on the SuperNode
1056 // completed with the required number of Daemons
1058 public synchronized void getRegisterOnSuperNode() {
1059 Register registerSpawner = null;
1061 boolean recieved = false;
1063 idAlgo = LocalHost.Instance().getIP() + ":" + LocalHost.Instance().getPort() ;
1065 System.out.println("Trying to get a Register on the SuperNode");
1066 int nbExtraSpawners = 0;
1067 if (nbTasks > nbOfDaemonsPerSpawner) {
1068 nbExtraSpawners = (nbTasks - 1) / nbOfDaemonsPerSpawner;
1075 paramAlgo = nbFault ;
1080 registerSpawner = centralServer.getRegisterSpawner(idAlgo,
1081 nbTasks, (Task) tache, nbTasks
1082 + nbExtraSpawners, algo, paramAlgo);
1084 } catch (Exception e) {
1086 .println("Unable to recieve a register from superNode "
1094 Algo al = centralServer.getAlgo( idAlgo ) ;
1096 dh = al.getGrid().getHeterogenityDegre() ;
1097 System.out.println( "### DH = " + dh ) ;
1099 Utils.writeGraph( al.getGraph(), "/home/lyon/smiquee/resultats/",
1100 "graph_"+algo+"_"+nbFault+"_"+test+".xml" ) ;
1101 Utils.writeGrid( al.getGrid(), "/home/lyon/smiquee/resultats/",
1102 "grid_"+algo+"_"+nbFault+"_"+test+".xml") ;
1103 Utils.writeMapping( al.getMapping(), "/home/lyon/smiquee/resultats/",
1104 "mapping_"+algo+"_"+nbFault+"_"+test+".xml" ) ;
1105 } catch (RemoteException e1) {
1106 System.err.println( "Problème avec Algo dans Spawner !" ) ;
1107 e1.printStackTrace();
1110 if (registerSpawner.getSize() != (nbTasks + nbExtraSpawners)) {
1111 System.err.println("I did not recieve enough nodes from superNode!!!! \n killing application !!!!");
1112 for (int i = 0; i < registerSpawner.getSize(); i++) {
1114 registerSpawner.getNodeAt(i).getStub().suicide( "Not enough nodes for the application" ) ;
1116 } catch (Exception e) {
1117 System.err.println("The reserved node was unable to reconnect to the super node");
1123 spawnersList = new Vector<Object>();
1124 for (int i = 0; i < nbExtraSpawners && i < registerSpawner.getSize(); i++) {
1125 spawnersList.add(registerSpawner.getNodeAt(0));
1127 registerSpawner.removeNodeOfName(registerSpawner.getNodeAt(0).getName());
1131 registerSpawner.setNbOfTasks(nbTasks);
1132 registerSpawner.setNumBackupNeighbors(nbSavingNodes);
1134 * System.out.println("Trying to connect another SuperNode");
1135 * connectSuperNode(); try { registerSpawner =
1136 * centralServer.getRegisterSpawner(LocalHost.Instance().getIP(),
1137 * nbTasks); } catch(Exception e1) {}
1140 if (registerSpawner != null) {
1141 System.out.println("I received the register");
1142 // registerSpawner.setVersion(registerVersion);
1143 // registerVersion++;
1144 Register.Instance().replaceBy(registerSpawner);
1145 System.out.println("It contains " + Register.Instance().getSize()
1146 + " Nodes" + " " + nbExtraSpawners + " ExtraSpawners");
1148 // set each Node aliveTime value to the Spawner current time
1149 for (int i = 0; i < Register.Instance().getSize(); i++) {
1150 noeud = Register.Instance().getNodeAt(i);
1151 noeud.setAliveFlag(true);
1152 noeud.setAliveTime();
1156 System.err.println("\n---------------WARNING--------------");
1157 System.err.println("No Daemon available on the SuperNode dispo, try later, please");
1163 public class TransformThread extends Thread {
1167 public TransformThread(int i, Node n) {
1175 System.out.println("Trying to transform the spawner ("
1176 + n.getName() + ") of rank " + i);
1177 spawnersList.setElementAt(n.getStub().transformIntoSpawner(
1178 params, appliName, Register.Instance(), nbTasks,
1179 centralServer, i, heartTime, 0, 0, 0,
1180 nbOfDaemonsPerSpawner, nbOfDeamonsPerThread, idAlgo), i);
1181 } catch (Exception e) {
1182 System.err.println("Error while contacting newly acquired spawner ("
1183 + n.getName() + "): " + e);
1185 n = centralServer.getNewNode( LocalHost.Instance().getIP(), null ) ;
1187 new TransformThread(i, n).start();
1188 } catch (Exception e1) {
1189 System.err.println("The Super Node is maybe dead: " + e1) ;
1190 for (int z = 0; z < Register.Instance().getSize(); z++) {
1192 Register.Instance().getNodeAt(z).getStub().suicide2("Problem") ;
1194 } catch (Exception ez) {
1195 System.err.println("The reserved node was unable to reconnect to the super node: \n"
1206 public class FaultMake extends Thread {
1208 public FaultMake(){}
1212 ListeTask t = null ;
1214 int next, old = -1 ;
1216 System.out.println( "Starting fault tolerance !" ) ;
1218 while( ! RunningApplication.Instance().isRunning() )
1220 /** Waiting some time the beginning of the computation **/
1223 } catch (InterruptedException e) {
1227 while( RunningApplication.Instance().isRunning() )
1229 /** Waiting some time ... **/
1231 sleep( faultTime * 1000 ) ;
1232 } catch (InterruptedException e) {
1235 /** ... and kill some daemons ! **/
1236 t = Register.Instance().getListeOfTasks();
1239 for( int i = 0 ; i < nbFault ; i++ )
1241 next = r.nextInt( t.getSize() ) ;
1243 while( next == old )
1245 next = r.nextInt( t.getSize() ) ;
1251 TaskId recev = null;
1252 System.out.println("Making fault on Task" + next);
1254 recev = t.getTaskIdOfRank( next );
1256 JaceInterface stub = recev.getHostStub();
1257 System.out.println("name = " + recev.getHostName());
1258 noeud = Register.Instance().getNodeOfStub( stub ) ;
1260 stub.suicide2( "Test fault tolerance" ) ;
1262 } catch (UnmarshalException ue ){
1263 } catch (Exception e) {
1265 System.err.println("Error in FaultMake on node: "
1266 + noeud.getName() + ". " + e);
1267 } catch (Exception e2) {
1268 System.err.println("(Fault)Error in error:" + e2);
1274 } catch (InterruptedException e) {
1283 public class StartProcessThread extends Thread {
1286 public StartProcessThread(int i) {
1294 * while((spawnersList.elementAt(i) instanceof Node)) try{
1295 * System.out.println("waiting till transform of spawner "+i+
1296 * " is finished"); Thread.sleep(20); }catch(Exception e1){}
1298 // System.out.println("start process on spawner of rank "+i);
1299 JaceSpawnerInterface spawnerStub = (JaceSpawnerInterface) spawnersList.get(i);
1300 spawnerStub.startProcess(spawnersList);
1301 } catch (Exception e) {
1302 e.printStackTrace(System.out);
1303 System.err.println("Unable to start the process on the spawner of rank "
1304 + i + ".error: " + e);
1309 public void createSpawnerNetwork() {
1312 for (i = 0; i < spawnersList.size(); i++) {
1313 n = (Node) spawnersList.elementAt(i);
1315 // Register.Instance().getListeOfTasks().viewAll();
1316 // spawnersList.setElementAt(n.getStub().transformIntoSpawner(
1317 // params, appliName, Register.Instance(),nbTasks, centralServer,i,
1318 // heartTime,0,0),i);
1319 new TransformThread(i, n).start();
1322 // broadcast the Register.Instance() to all the JaceServer
1323 // in order to start each task on the Daemons
1325 spawnersList.add(Register.Instance().getSpawnerStub());
1326 System.out.println(" rank="+rank+" spawnersList.size()=" + spawnersList.size());
1327 rank = spawnersList.size() - 1;
1329 broadcastRegister(1);
1331 for (int j = 0; j < spawnersList.size(); j++) {
1332 System.out.println("waiting till transform of spawner " + j
1334 while ((spawnersList.elementAt(j) instanceof Node))
1339 } catch (Exception e) {
1344 // for (int k = 0; k < spawnersList.size(); k++)
1347 // ((JaceSpawnerInterface) spawnersList.get( k )).setIdAlgo( idAlgo ) ;
1348 // } catch (Exception e) {
1349 // System.err.println("Unable to propagate the mapping algorithm identifier:" + e) ;
1353 System.out.println("End Transformation of all spawners. Beginning the computing processes");
1355 for (i = 0; i < spawnersList.size(); i++) {
1357 // while(!(spawnersList.elementAt(i) instanceof
1358 // JaceSpawnerInterface))
1360 new StartProcessThread(i).start();
1363 System.out.println("End create Spawner Network!!!!!!!!!");
1366 public JaceSpawnerInterface getSpawnerResponsibleOn(int rank) {
1367 int id = rank / nbOfDaemonsPerSpawner;
1368 return (JaceSpawnerInterface) spawnersList.get(id);
1371 public void createAppli() {
1376 ListeTask tsk = new ListeTask();
1378 JaceInterface nodeStub = null;
1379 TaskId myTask = null;
1381 System.out.println("Application launched, starting the chronometer");
1382 RunningApplication.Instance().getChrono().start();
1384 RunningApplication.Instance().setName(appliName);
1385 RunningApplication.Instance().setNbTasks(nbTasks);
1386 // RunningApplication.Instance().setRegister(Register.Instance());
1388 Register.Instance().setParams(params);
1389 Register.Instance().setAppliName(appliName);
1390 Register.Instance().setSpawnerStub(this.spawnerRef);
1392 // assign a TaskId to each Node of the Register
1393 // and insert the TaskId in tke ListTask
1394 while (i < Register.Instance().getSize() && count < nbTasks) {
1395 tmpNode = Register.Instance().getNodeAt(i);
1396 if (tmpNode.getAliveFlag() == true) {
1397 tmpNode.setAppliName(appliName);
1398 nodeStub = tmpNode.getStub();
1399 nodeName = tmpNode.getName();
1400 nodeIP = tmpNode.getIP();
1402 myTask = new TaskId(appliName, count, nodeStub);
1403 myTask.setHostIP(nodeIP);
1404 myTask.setHostName(nodeName);
1406 tsk.addTask(myTask);
1412 // if not enough Nodes in the Register,
1413 // insert not assigned TaskId in the ListTask
1414 if (count < nbTasks) {
1415 for (int j = count; j < nbTasks; j++) {
1416 tsk.addTask(new TaskId(appliName, j, null));
1418 System.out.println("in Register, misses "
1419 + (nbTasks - Register.Instance().getSize()) + " nodes");
1422 // insert the ListeTask in the Register of the appli
1423 Register.Instance().setListeOfTasks(tsk);
1424 // Register.Instance().getListeOfTasks().viewAll();
1425 RunningApplication.Instance().setRunning(true);
1426 System.out.println("fin create appli");
1429 public class BroadcastSpawner extends Thread {
1432 int nbOfDaemonsPerThread, nbOfDeamonsPerSpawner;
1434 public BroadcastSpawner(int i, int debut, int nbOfDeamonsPerSpawner,
1435 int nbOfDaemonsPerThread) {
1438 this.nbOfDaemonsPerThread = nbOfDaemonsPerThread;
1439 this.nbOfDeamonsPerSpawner = nbOfDeamonsPerSpawner;
1444 for (int index = debut + i * nbOfDaemonsPerThread; index < debut
1445 + i * nbOfDeamonsPerThread + nbOfDeamonsPerThread
1446 && index < debut + nbOfDeamonsPerSpawner
1447 && index < Register.Instance().getListeOfTasks().getSize(); index++) {
1449 Register.Instance().getNodeAt(index).getStub().setSpawner(
1450 Register.Instance().getSpawnerStub());
1451 } catch (Exception e) {
1452 System.out.println("can't change spawner stub on node: "
1453 + Register.Instance().getNodeAt(i).getName()
1460 public class KillThread extends Thread {
1463 int nbOfDaemonsPerThread, nbOfDeamonsPerSpawner;
1466 public KillThread(int i, int debut, int nbOfDeamonsPerSpawner,
1467 int nbOfDaemonsPerThread, ListeTask t) {
1470 this.nbOfDaemonsPerThread = nbOfDaemonsPerThread;
1471 this.nbOfDeamonsPerSpawner = nbOfDeamonsPerSpawner;
1478 for (int index = debut + i * nbOfDaemonsPerThread; index < debut
1479 + i * nbOfDeamonsPerThread + nbOfDeamonsPerThread
1480 && index < debut + nbOfDeamonsPerSpawner
1481 && index < t.getSize(); index++) {
1484 TaskId recev = null;
1485 System.out.println("deleting Task" + index);
1487 recev = t.getTaskIdOfRank(index);
1489 JaceInterface stub = recev.getHostStub();
1490 System.out.println("name=" + recev.getHostName());
1491 noeud = Register.Instance().getNodeOfStub(stub);
1492 noeud.setAppliName(null);
1493 new ReconnectThread(stub, noeud.getName()).start();
1494 Register.Instance().removeNode(noeud);
1495 // LocalHost.Instance().getSpawnerStub().killApplication(stub);
1497 } catch (Exception e) {
1499 System.err.println("error in killThread on node "
1500 + noeud.getName() + ". " + e);
1501 } catch (Exception e2) {
1502 System.err.println("error in error :" + e2);
1508 class ReconnectThread extends Thread {
1509 JaceInterface stub = null;
1512 public ReconnectThread(JaceInterface s, String name) {
1519 // System.out.println("reconnexion SuperNode");
1520 // Register.Instance().getNode(workerIP).getWorkerStub().reconnectSuperNode();
1522 // stub.reconnectSuperNode();
1523 stub.suicide("End of application");
1524 } catch (Exception e) {
1525 System.err.println("Cannot kill node " + name);
1533 // faire une copie du Register et l'envoyer aux noeuds qui le compose
1534 // car si il est modif en meme tmp, on envoi pas un truc coherent
1535 private synchronized void broadcastRegister(int requete) {
1536 // Register reg = Register.Instance().clone();
1537 Register reg = Register.Instance();
1540 System.out.println("name of spawner: "
1541 + Register.Instance().getSpawnerStub().getName());
1542 // launch 1 thread to send the Register to all the nodes
1543 while (broadcasting == true)
1545 broadcasting = true;
1546 // Register.Instance().setSpawnerStub(
1547 // Register.Instance().getSpawnerStub());
1548 int x = reg.getListeOfTasks().getSize() / nbOfDaemonsPerSpawner;
1551 if ((reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1552 % nbOfDeamonsPerThread == 0)
1553 s = (reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1554 / nbOfDeamonsPerThread;
1556 s = (reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1557 / nbOfDeamonsPerThread + 1;
1558 else if ((nbOfDaemonsPerSpawner % nbOfDeamonsPerThread) == 0)
1559 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread;
1561 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread + 1;
1562 int debut = nbOfDaemonsPerSpawner * rank;
1563 System.out.println("rank=" + rank + " debut=" + debut + " s=" + s
1564 + " nbOfDaemonsPerSpawner=" + nbOfDaemonsPerSpawner
1565 + " nbOfDeamonsPerThread=" + nbOfDeamonsPerThread + " x="
1567 for (int i = 0; i < s; i++)
1568 new UpdateRegisterThread(tache, reg, requete, i, debut).start();
1570 * This thread : -updates the goal of the Node beats if necessary
1571 * (stub.updateHeart) -updates the Register on each Node
1572 * (stub.updateRegister)
1574 JaceSpawner.Instance().setBroadcasting(false);
1577 } catch (Exception e) {
1580 } catch (Exception e) {
1582 .println("\n1 node has died during JaceSpawner.broadcastRegister()");
1586 private synchronized void broadcastScanning() {
1587 Register reg = Register.Instance();
1588 while (broadcasting == true)
1591 } catch (Exception e) {
1593 // Register.Instance().viewAll();
1594 Vector<?> nodes = (Vector<?>) Register.Instance().getListOfNodes().clone();
1595 int x = reg.getListeOfTasks().getSize() / nbOfDaemonsPerSpawner;
1598 s = (reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1599 / nbOfDeamonsPerThread;
1601 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread;
1603 int debut = nbOfDaemonsPerSpawner * rank;
1605 // for(int i=debut;i<nbOfDaemonsPerSpawner*(rank+1) &&
1606 // i<reg.getSize();i++)
1607 // System.out.println(((Node)nodes.elementAt(i)).getName());
1609 for (int i = 0; i < s + 1; i++) {
1611 new StartScanThread(i, nodes, debut).start();
1616 @SuppressWarnings("unchecked")
1617 public synchronized Register getRegister( int rank ) {
1619 ListeTask listOfTasks = Register.Instance().getListeOfTasks();
1620 Vector dependencies = getDependencies(rank, listOfTasks.getSize());
1621 Register g = new Register();
1622 ListeTask newListOfTasks = new ListeTask();
1624 g.setAppliName(Register.Instance().getAppliName());
1625 g.setParams(Register.Instance().getParams());
1626 g.setSpawnerStub(Register.Instance().getSpawnerStub());
1627 g.setNbOfTasks(Register.Instance().getNbOfTasks());
1628 // g.setVersion(reg.getVersion());
1630 for (int j = 0; j < dependencies.size(); j++) {
1631 TaskId id = listOfTasks.getTaskIdOfRank(((Integer) dependencies
1632 .elementAt(j)).intValue());
1633 newListOfTasks.addTask(id);
1634 if (id.getHostStub() != null) {
1635 Node noeud = Register.Instance()
1636 .getNodeOfName( id.getHostName() ) ;// (id.getHostStub());
1638 g.addNode( noeud ) ;
1640 System.err.println( "PAS BON DU TOUT" ) ;
1643 g.setListeOfTasks(newListOfTasks);
1647 @SuppressWarnings("unchecked")
1648 private void updateConcernedNodes(int rank, Node oldNode, Node node) {
1649 ListeTask listOfTasks = Register.Instance().getListeOfTasks();
1650 Vector dependencies = getDependencies(rank, listOfTasks.getSize());
1651 System.out.println("List of concerned neighbors of task " + rank+": ");
1652 for (int z = 0; z < dependencies.size(); z++)
1653 System.out.print(((Integer) dependencies.elementAt(z)).intValue()
1655 System.out.println();
1656 // Register.Instance().setVersion(registerVersion);
1657 // registerVersion++;
1658 // Register.Instance()
1659 // .setSpawnerStub(Register.Instance().getSpawnerStub());
1661 if ((dependencies.size() % nbOfDeamonsPerThread) == 0)
1662 s = dependencies.size() / nbOfDeamonsPerThread;
1664 s = dependencies.size() / nbOfDeamonsPerThread + 1;
1665 Register reg = Register.Instance();
1667 for (int j = 0; j < s; j++) {
1668 new UpdateRegisterConcernedThread(dependencies, reg, j, rank,
1669 oldNode, node).start();
1673 private Vector<Integer> getDependencies(int id, int jaceSize) {
1674 // get computing dependencies
1675 Vector<Integer> neighbors = new Vector<Integer>();
1676 int[] dep = tache.getDependencies(id);
1677 for (int z = 0; z < taille(dep); z++)
1678 neighbors.add(dep[z]);
1679 // System.out.println("la liste des voisins de calcul de: "+id+" concerne");
1680 // for(int z=0;z<neighbors.size();z++)
1681 // System.out.print(((Integer)neighbors.elementAt(z)).intValue()+" ");
1682 // System.out.println();
1684 // get convergence neighbors
1686 while (Math.pow(2, d) < jaceSize) {
1687 if (id < Math.pow(2, d) && ((id + Math.pow(2, d)) < jaceSize))
1688 if (!neighbors.contains((Object) ((int) (id + Math.pow(2, d)))))
1689 neighbors.add((int) (id + Math.pow(2, d)));
1690 if (id < Math.pow(2, d + 1) && id >= Math.pow(2, d))
1691 if (!neighbors.contains((Object) ((int) (id - Math.pow(2, d)))))
1692 neighbors.add((int) (id - Math.pow(2, d)));
1696 // get backup neighbors
1697 int nb = Register.Instance().getNumBackupNeighbors();
1700 for (int j = 1; j <= nb; j++) {
1701 // ------------ 1 - for backups "j + n" (to the right of j)
1702 rankOfBackTask = (id + j) % jaceSize;
1703 if (!neighbors.contains((Object) rankOfBackTask))
1704 neighbors.add(rankOfBackTask);
1706 // ------------ 2 - for backups "j - n" (to the left of j)
1709 rankOfBackTask = tmp % jaceSize;
1711 rankOfBackTask = jaceSize - (Math.abs(tmp) % jaceSize);
1713 if (!neighbors.contains((Object) rankOfBackTask))
1714 neighbors.add(rankOfBackTask);
1722 public static int taille(int[] vect) {
1725 while (x < vect.length && vect[x] >= 0) {
1732 class StartScanning extends Thread {
1734 public StartScanning() {
1744 class StartScanThread extends Thread {
1747 int nbOfDeamonsPerThread, nbOfDeamonsPerSpawner;
1749 StartScanThread(int i, Vector<?> nodes, int debut) {
1753 nbOfDeamonsPerThread = JaceSpawner.Instance().getNbOfDeamonsPerThread();
1754 nbOfDeamonsPerSpawner = JaceSpawner.Instance()
1755 .getNbOfDeamonsPerSpawner();
1760 for (index = debut + i * nbOfDeamonsPerThread; index < debut + i
1761 * nbOfDeamonsPerThread + nbOfDeamonsPerThread
1762 && index < debut + nbOfDeamonsPerSpawner
1763 && index < nodes.size(); index++) {
1765 Node node = (Node) nodes.elementAt(index);
1766 JaceInterface stub = node.getStub();
1767 String name = node.getName();
1770 stub.setScanning(true);
1771 // System.out.println("modify scanning to "+name);
1773 } catch (Exception e) {
1774 System.err.println("Unable to modify scanning to " + name + ":"
1778 // for(int x=0;x<nodes.size();x++)
1779 // System.out.println(((Node)nodes.elementAt(x)).getName());
1780 // System.out.println("nbre total: "+(index-1));