X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/jaceP2P.git/blobdiff_plain/e4891bd929a468ef21bd083d2c9bb3fb06254c91..c7001582aeefb419483631f88a0b0ee5873ae951:/src/jaceP2P/JaceSpawner.java diff --git a/src/jaceP2P/JaceSpawner.java b/src/jaceP2P/JaceSpawner.java index 3cb20ea..4c1672f 100644 --- a/src/jaceP2P/JaceSpawner.java +++ b/src/jaceP2P/JaceSpawner.java @@ -6,10 +6,11 @@ import java.io.PrintWriter; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.UnmarshalException; +import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Random; -import java.util.Vector; +import java.util.concurrent.Semaphore; import and.Mapping.Algo; import and.Mapping.Utils; @@ -40,7 +41,7 @@ public class JaceSpawner { private int z = 0; private static int nbOfDaemonsPerSpawner; private static int nbOfDeamonsPerThread; - private Vector spawnersList; + private ArrayList spawnersList; private int rank; private int nbSavingNodes; @@ -49,6 +50,8 @@ public class JaceSpawner { private double paramAlgo ; private String idAlgo ; + private Semaphore sema ; + // ** Test ** // private int test; private double dh ; @@ -67,6 +70,7 @@ public class JaceSpawner { nbFault = _nbF ; faultTime = _fT ; + sema = new Semaphore( 1, true ) ; superNode_IP = superNode; spawnerPort = port; @@ -136,6 +140,8 @@ public class JaceSpawner { idAlgo = _idAlgo ; + sema = new Semaphore( 1, true ) ; + this.appliName = appliName; this.nbTasks = nbTasks; @@ -203,7 +209,7 @@ public class JaceSpawner { return nbOfDaemonsPerSpawner; } - public void startProcess(Vector spawnersList) { + public void startProcess(ArrayList spawnersList) { this.spawnersList = spawnersList; int is = spawnersList.indexOf((Object) Register.Instance() @@ -297,101 +303,117 @@ public class JaceSpawner { System.exit( 1 ) ; } - public synchronized void signalDeadNode(JaceInterface host, int rankOfDead) { + public synchronized void signalDeadNode(JaceInterface host, int rankOfDead ) + { + try { + sema.acquire() ; + } catch (InterruptedException e3) { + System.err.println( "Problem while acquiring the semaphore in signalDeadNode!" ) ; + e3.printStackTrace() ; + } - TaskId myTaskId = null; - int nb = 0; - int nbC = 0; - long time = 0; - RunningApplication.Instance().incrementNumberOfDisconnections(); - - time = RunningApplication.Instance().getChrono().getValue() / 1000; - nb = RunningApplication.Instance().getNumberOfDisconnections(); - nbC = RunningApplication.Instance().getNumberOfCouilles(); - System.out.println("At time = " + time + "s, NbDisconnection = " - + nb + ", NbProblem = " + nbC); - - if( host == null ) - System.err.println( "SIGNAL DE NODE NULL" ) ; - - // !!!!!!!!!!!!!!actualiser le ListeTask ds le Register - try { - myTaskId = Register.Instance().getListeOfTasks() - .getTaskIdOfHostStub(host); - } catch( Exception e ) {} - - if (myTaskId == null) { - myTaskId = Register.Instance().getListeOfTasks() - .getTaskIdOfRank(rankOfDead); - if( myTaskId == null ) - { - System.err.println("Houston we have a serious problem!!"); - return ; - } - - JaceInterface deadStub = myTaskId.getHostStub(); + + TaskId myTaskId = null; + int nb = 0; + int nbC = 0; + long time = 0; + RunningApplication.Instance().incrementNumberOfDisconnections(); + + time = RunningApplication.Instance().getChrono().getValue() / 1000; + nb = RunningApplication.Instance().getNumberOfDisconnections(); + nbC = RunningApplication.Instance().getNumberOfProblems(); + System.out.println( "At time = " + time + "s, NbDisconnection = " + + nb + ", NbProblem = " + nbC ) ; - if( deadStub != null ) - { - try{ - deadStub.suicide2("Not doing a good work"); - }catch(Exception e){} - } else { - System.err.println( "Dead node stub unavailable!" ); - } - } - - Node noeud = Register.Instance().getNodeOfName( myTaskId.getHostName() ) ; - - int rankDeaD = myTaskId.getRank(); - - String nomNoeud = "" ; + if( host == null ) + System.err.println( "Signal of a node null!" ) ; + + // !!!!!!!!!!!!!!actualiser le ListeTask ds le Register + try { + myTaskId = Register.Instance().getListeOfTasks() + .getTaskIdOfHostStub( host ) ; + } catch( Exception e ) {} - if( noeud != null ) + if (myTaskId == null) + { + myTaskId = Register.Instance().getListeOfTasks() + .getTaskIdOfRank( rankOfDead ) ; + if( myTaskId == null ) { - nomNoeud = noeud.getName(); + System.err.println( "Houston we have a serious problem!!" ) ; + sema.release() ; + return ; } - - boolean b = false ; - - if( ! nomNoeud.equals( "" ) ) + + JaceInterface deadStub = myTaskId.getHostStub() ; + + if( deadStub != null ) { - b = Register.Instance().removeNodeOfName( nomNoeud ) ; + try{ + deadStub.suicide2( "Not doing a good work" ) ; + }catch(Exception e){} } else { - System.err.println( "Dead node name unknown!!" ) ; + System.err.println( "Dead node stub unavailable!" ) ; } + } + + Node noeud = Register.Instance().getNodeOfName( myTaskId.getHostName() ) ; + + int rankDeaD = myTaskId.getRank() ; + + String nomNoeud = "" ; + + if( noeud != null ) + { + nomNoeud = noeud.getName() ; + } + + boolean b = false ; + + if( ! nomNoeud.equals( "" ) ) + { + b = Register.Instance().removeNodeOfName( nomNoeud ) ; + } else { + System.err.println( "Dead node name unknown!!" ) ; + } - if( ! b ) - { - b = Register.Instance().removeNode( noeud ) ; - } + if( ! b ) + { + b = Register.Instance().removeNode( noeud ) ; + } - if( b == true ) - { - System.out.println("Removing Node of rank " - + rankDeaD + " : size = " - + Register.Instance().getSize()); - } else { - System.err - .println("Cannot remove the Node, it doesn't exist anymore: size = " - + Register.Instance().getSize()); - } + if( b == true ) + { + System.out.println( "Removing Node of rank " + + rankDeaD + " : size = " + + Register.Instance().getSize() ) ; + } else { + System.err.println( "Cannot remove the Node, it doesn't exist anymore: size = " + + Register.Instance().getSize() ) ; + } - Calendar cal = new GregorianCalendar(); - System.out.println("At time=" + cal.get(Calendar.MINUTE) + ":" - + cal.get(Calendar.SECOND)); + Calendar cal = new GregorianCalendar() ; + System.out.println( "At time=" + cal.get(Calendar.MINUTE) + ":" + + cal.get(Calendar.SECOND) ) ; - /**** Sébastien Miquée **/ - Node tmpNode = null ; - int retry = 0, retryMax = 4 ; + /**** Sébastien Miquée **/ + Node tmpNode = null ; + boolean ok = false ; + int retry = 0, retryMax = 4 ; + + while( tmpNode == null && ! ok ) + { + ok = true ; while( tmpNode == null ) { - tmpNode = foundToReplaceThisNode(rankDeaD, nomNoeud, noeud); + tmpNode = foundToReplaceThisNode( rankDeaD, nomNoeud, noeud ) ; if( tmpNode == null ) { + System.err.println( "I didn't receive a new Node! (" + retry + ")" ) ; + try{ Thread.sleep( 1000 ) ; } catch( Exception e ) {} @@ -400,47 +422,137 @@ public class JaceSpawner { if( retry > retryMax ) { - System.err.println( "Unable to replace the dead node "+nomNoeud ) ; + System.err.println( "Unable to replace the dead node " + nomNoeud ) ; + sema.release() ; return ; } } } + + System.out.println( "Using Node " + tmpNode.getName() + " in order to replace " + nomNoeud + "\n" ) ; + + tmpNode.setAliveFlag( true ) ; + tmpNode.setAliveTime() ; + tmpNode.setAppliName( RunningApplication.Instance().getName() ) ; + + // Replacing the node in the Register + int is = Register.Instance().existNode( tmpNode ) ; + + if( is != -1 ) + { + System.out.println( "The Node is already in the register! I don't add it." ) ; + System.out.println( "Node " + tmpNode.getName() + " not added!" ) ; + tmpNode = null ; + } else { + Register.Instance().addNode( tmpNode ) ; + + myTaskId = Register.Instance().getListeOfTasks().getTaskIdOfRank( rankDeaD ) ; + myTaskId.setHostIP( tmpNode.getIP() ) ; + myTaskId.setHostName( tmpNode.getName() ) ; + myTaskId.setHostStub( tmpNode.getStub() ) ; + + int neighborRank ; + + if( rankDeaD == 0 ) + { + neighborRank = Register.Instance().getSize() - 1 ; + } else { + neighborRank = rankDeaD - 1 ; + } + + TaskId neighborTask2 = Register.Instance().getListeOfTasks() + .getTaskIdOfRank( neighborRank ) ; + + int loop = 0, MAX_LOOP = 1 ; + boolean ook = false ; + JaceInterface jaceStub = null ; + + while( !ook && loop < MAX_LOOP ) + { + try { + jaceStub = neighborTask2.getHostStub() ; + jaceStub.updateHeart( tmpNode.getStub() ) ; + + ook = true ; + } catch( Exception e ) { + loop++ ; + + if( loop < MAX_LOOP ) + { + try { + Thread.sleep( loop * 2000 ) ; + } catch( InterruptedException e1 ) {} + } + + if( loop == MAX_LOOP ) + { + System.err.println( "Next node unreachable! " + e ) ; + } + } + } + + if( loop == MAX_LOOP && ! ok ) + { + + try { + jaceStub.suicide2( "Not reachable!" ) ; + } catch (RemoteException e1) { + System.err.println( "Unable to suicide the node!\n"+e1 ) ; + } + + try { + int pos = Register.Instance().existNodeOfStub( jaceStub ) ; + + if( pos != -1 ) + { + centralServer.delGNodeFromList( Register.Instance().getNodeAt( pos ), 0, LocalHost.Instance().getIP() ) ; + } else { + System.err.println( "The ping neighbor of " + tmpNode.getName() + " does not respond. It is probably dead ..." ) ; + } + } catch( RemoteException e ) { + System.err.println( "Unable to signal dead node to SuperNode!" ) ; + e.printStackTrace() ; + } + } + } try { - updateConcernedNodes(rankDeaD, noeud, tmpNode); + updateConcernedNodes( rankDeaD, noeud, tmpNode ) ; - Thread.sleep(500); - System.out.println("Set scanning on "+tmpNode.getName()); + Thread.sleep( 500 ) ; tmpNode.getStub().setScanning( true ) ; - } catch (Exception e) { + System.out.println( "Set scanning on " + tmpNode.getName() ) ; + } catch( Exception e ) { try { Thread.sleep( 2000 ) ; tmpNode.getStub().setScanning( true ) ; - } catch (InterruptedException e1) { - } catch (RemoteException e2) { + } catch( InterruptedException e1 ) { + } catch( RemoteException e2 ) { System.err.println( "Unable to setScanning on for the new node: " + e2 ) ; + ok = false ; } - System.err.println("Unable to setScanning on for the new node: " - + e) ; } - for (int z = 0; z < spawnersList.size(); z++) + for( int z = 0 ; z < spawnersList.size() ; z++ ) { - if (!((JaceSpawnerInterface) spawnersList.get(z)) - .equals(Register.Instance().getSpawnerStub())) + if( !( (JaceSpawnerInterface) spawnersList.get( z ) ) + .equals(Register.Instance().getSpawnerStub() ) ) { try { ((JaceSpawnerInterface) spawnersList.get(z)) - .replaceDeamonBy(noeud, tmpNode, rankDeaD); + .replaceDeamonBy(noeud, tmpNode, rankDeaD); } catch (Exception e) { - System.err - .println("Unable to broadcast the modifications to all the spawners: " - + e); + System.err.println( "Unable to broadcast the modifications to all the spawners: " + + e ) ; + ok = false ; } } - } + } + } + + sema.release() ; } // verifie si les noeud notes vivant ds le Register.Instance() du SuperNode @@ -489,141 +601,161 @@ public class JaceSpawner { try { node = null ; + if( centralServer == null ) + { + centralServer = LocalHost.Instance().getSuperNodeStub() ; + + if( centralServer == null ) + { + System.err.println( "Connection lost to SuperNode!" ) ; + System.err.println( "Reconnecting..." ) ; + connectSuperNode() ; + } + } + node = centralServer.getNewNode( idAlgo, theRank ) ; if( node != null && ! node.getIP().isEmpty() && node.getIP() != null && ! node.getIP().equals( "" ) ) { - found = true ; + if( Register.Instance().existNode( node ) != -1 ) + { + found = false ; + } else { + found = true ; + } } else { - System.err.println("Returned node is null!"); + System.err.println( "Returned node is null!" ) ; nbNull++ ; try { Thread.sleep( 2000 ) ; } catch( Exception e ) {} } - } catch (Exception e) { + } catch (RemoteException e) { // trouver un autre superNode et lui demander le noeud a lui - - System.err.println("Cannot localize SuperNode ! " + e); - - connectSuperNode(); - } - - if( Register.Instance().existNode( node ) != -1 ) - { - found = false ; + System.err.println( "Cannot localize SuperNode ! " + e ) ; + connectSuperNode() ; } } + return node ; - if( node != null ) - { - System.out.println( "Using Node " + node.getName() + " in order to replace " + nom + "\n" ) ; - - node.setAliveFlag(true); - node.setAliveTime(); - - // rajouter le noeud ds le Register - node.setAppliName(RunningApplication.Instance().getName()); - - // lui envoyer mon stub pr qu'il commence a me pinguer des - // maintenant - // TODO a mettre ds un thread ???? - - /* - * TaskId - * neighborTask=Register.Instance().getListeOfTasks().getTaskIdOfRank - * ((theRank+1)%Register.Instance().getListeOfTasks().getSize()); - * try{ node.getStub().updateHeart(neighborTask.getHostStub()); } - * catch(Exception e) { - * System.out.println("nvx noeud deja plu dispo2"); //node = null; } - */ - // TODO verif pourkoi superNode me le redonne - // alors qu'il fait deja du calcul - // int is = Register.Instance().existNode(node.getIP()); - int is = Register.Instance().existNode( node ) ; +// if( node != null ) +// { +// System.out.println( "Using Node " + node.getName() + " in order to replace " + nom + "\n" ) ; +// +// node.setAliveFlag(true); +// node.setAliveTime(); +// +// // rajouter le noeud ds le Register +// node.setAppliName(RunningApplication.Instance().getName()); +// +// // lui envoyer mon stub pr qu'il commence a me pinguer des +// // maintenant +// // TODO a mettre ds un thread ???? +// +// /* +// * TaskId +// * neighborTask=Register.Instance().getListeOfTasks().getTaskIdOfRank +// * ((theRank+1)%Register.Instance().getListeOfTasks().getSize()); +// * try{ node.getStub().updateHeart(neighborTask.getHostStub()); } +// * catch(Exception e) { +// * System.out.println("nvx noeud deja plu dispo2"); //node = null; } +// */ +// // TODO verif pourkoi superNode me le redonne +// // alors qu'il fait deja du calcul +// // int is = Register.Instance().existNode(node.getIP()); +// int is = Register.Instance().existNode( node ) ; +// +// if( is != -1 ) +// { +// System.out.println("The Node is already in the register ! I don't add it."); +// System.out.println("Node " + node.getName() + " not added !") ; +// node = null; +// } else { +// Register.Instance().addNode(node); +// +// // !!!!!!!!!!!!!!actualiser le ListeTask +// TaskId myTaskId = Register.Instance().getListeOfTasks() +// .getTaskIdOfRank(theRank); +// myTaskId.setHostIP(node.getIP()); +// myTaskId.setHostName(node.getName()); +// myTaskId.setHostStub(node.getStub()); +// +// int neighborRank; +// if (theRank == 0) +// { +// neighborRank = Register.Instance().getSize() - 1; +// } else { +// neighborRank = theRank - 1; +// } +// +// TaskId neighborTask2 = Register.Instance().getListeOfTasks() +// .getTaskIdOfRank( neighborRank ) ; +// +// int loop = 0, MAX_LOOP = 1 ; +// boolean ok = false ; +// JaceInterface jaceStub = null ; +// +// while( !ok && loop < MAX_LOOP ) +// { +// try { +// jaceStub = neighborTask2.getHostStub(); +// jaceStub.updateHeart(node.getStub()); +// +// ok = true ; +// } catch( Exception e ) { +// loop++ ; +// +// if( loop < MAX_LOOP ) +// { +// try { +// Thread.sleep( loop * 2000 ) ; +// } catch (InterruptedException e1) {} +// } +// +// if( loop == MAX_LOOP ) +// { +// System.err.println( "Next node unreachable! " + e ) ; +// } +// } +// } +// +// if( loop == MAX_LOOP ) +// { +// +// try { +// node.getStub().suicide2( "Not reachable!" ) ; +// } catch (RemoteException e1) { +// System.err.println( "Unable to suicide the node!\n"+e1 ) ; +// return null ; +// //signalDeadNode( null, neighborTask2.getRank(), 1 ) ; +// } +// +// try { +// centralServer.delGNodeFromList( node, 0, LocalHost.Instance().getIP() ) ; +// } catch( RemoteException e ) { +// System.err.println( "Unable to signal dead node to SuperNode!" ) ; +// e.printStackTrace() ; +// } +// } +// +// } +// +// } else { +// System.out.println( "I didn't receive a new Node !" ) ; +// } - if( is != -1 ) - { - System.out.println("The Node is already in the register ! I don't add it."); - System.out.println("Node " + node.getName() + " not added !") ; - node = null; - } else { - Register.Instance().addNode(node); - - // !!!!!!!!!!!!!!actualiser le ListeTask - TaskId myTaskId = Register.Instance().getListeOfTasks() - .getTaskIdOfRank(theRank); - myTaskId.setHostIP(node.getIP()); - myTaskId.setHostName(node.getName()); - myTaskId.setHostStub(node.getStub()); - - int neighborRank; - if (theRank == 0) - { - neighborRank = Register.Instance().getSize() - 1; - } else { - neighborRank = theRank - 1; - } - - TaskId neighborTask2 = Register.Instance().getListeOfTasks() - .getTaskIdOfRank( neighborRank ) ; - - int loop = 0, MAX_LOOP = 1 ; - boolean ok = false ; - JaceInterface jaceStub = null ; - - while( !ok && loop < MAX_LOOP ) - { - try { - jaceStub = neighborTask2.getHostStub(); - jaceStub.updateHeart(node.getStub()); - - ok = true ; - } catch( Exception e ) { - loop++ ; - - if( loop < MAX_LOOP ) - { - try { - Thread.sleep( loop * 2000 ) ; - } catch (InterruptedException e1) {} - } - - if( loop == MAX_LOOP ) - { - System.err.println( "Next node unreachable! " + e ) ; - } - } - } - - if( loop == MAX_LOOP ) - { - - try { - node.getStub().suicide2( "Not reachable!" ) ; - } catch (RemoteException e1) { - System.err.println( "Unable to suicide the node!\n"+e1 ); - signalDeadNode( null, neighborTask2.getRank() ) ; - } - } - - } - - } else { - System.out.println("I didn't receive a new Node !"); - } - return node; +// return node ; } public void replaceBy(JaceSpawnerInterface oldStub, JaceSpawnerInterface stub) { - int index = spawnersList.indexOf((Object) oldStub); + int index = spawnersList.indexOf((Object) oldStub) ; if (index != -1) - spawnersList.setElementAt(stub, index); + spawnersList.set(index, stub ) ; else - System.err.println("Spawner's stub not foud in spawnersList !"); + System.err.println( "Spawner's stub not foud in spawnersList !" ) ; } public void getNewSpawner(JaceSpawnerInterface previousSpawner) { @@ -677,7 +809,7 @@ public class JaceSpawner { .getNumberOfSpawnerDisconnections(), nbOfDaemonsPerSpawner, nbOfDeamonsPerThread , idAlgo); - spawnersList.setElementAt(spawnerStub, index); + spawnersList.set( index, spawnerStub ) ; new StartProcessThread(index).start(); @@ -788,17 +920,17 @@ public class JaceSpawner { System.out.println("Application finished successfully !"); System.out.println("TOTAL TIME in s : " + (finalTime / 1000)); - System.out.println("nb of desconnections: " + nbe); - System.out.println("nb of spawners desconnections: " + nbsdc); + System.out.println("Number of node disconnections: " + nbe); + System.out.println("Number of spawner disconnections: " + nbsdc); // ** Tests ** // - String path = "/home/lyon/smiquee/resultats/execTime_"+algo+"_"+test ; + String path = "/home/lyon/smiquee/resultats/execTime_"+algo+"_"+nbFault+"_"+test ; PrintWriter ecrivain = null ; ecrivain = new PrintWriter( new OutputStreamWriter( new FileOutputStream( path ), "UTF8" ) ) ; ecrivain.println( "TOTAL TIME in s : " + (finalTime / 1000)); - ecrivain.println( "nb of desconnections: " + nbe); - ecrivain.println( "nb of spawners desconnections: " + nbsdc); + ecrivain.println( "Number of node disconnections: " + nbe); + ecrivain.println( "Number of spawner disconnections: " + nbsdc); ecrivain.println( "DH = "+dh ) ; ecrivain.flush() ; @@ -833,7 +965,7 @@ public class JaceSpawner { * //si mon appli a besoin d'un noeud //sinon, on fait rien if ((nbTasks * - Register.Instance().getSize()) > 0) { cptReplaced = 0; * - * //TODO demander des paquet de nodes, pas qu'un //on scanne toutes les + * //TO DO demander des paquet de nodes, pas qu'un //on scanne toutes les * taches de cette appli for (int ind = 0; ind < tskList.getSize(); * ind++) { //si 1 tache a pas de noeud, on trouve 1 remplacant * @@ -862,7 +994,7 @@ public class JaceSpawner { // Node node = null; // // while (found == false) { // try { -// // TODO : trouver l'erreur !!! +// // TO DO : trouver l'erreur !!! // // msg d'erreur : // // "pas localise le super node java.lang.NullPointerException" // if (centralServer == null) { @@ -901,7 +1033,7 @@ public class JaceSpawner { // // // lui envoyer mon stub pr qu'il commence a me pinguer des // // maintenant -// // TODO a mettre ds un thread ???? +// // TO DO a mettre ds un thread ???? // try { // TaskId neighborTask = Register.Instance().getListeOfTasks() // .getTaskIdOfRank( @@ -913,7 +1045,7 @@ public class JaceSpawner { // // // int is = Register.Instance().existNode(node.getIP()); // int is = Register.Instance().existNode(node); -// // TODO verif pourkoi superNode me le redonne +// // TO DO verif pourkoi superNode me le redonne // // alors qu'il fait deja du calcul // if (is != -1) { // System.out.println("j'ajoute pas le noeud, il y est deja"); @@ -1056,16 +1188,16 @@ public class JaceSpawner { // completed with the required number of Daemons // or gets NULL public synchronized void getRegisterOnSuperNode() { - Register registerSpawner = null; - Node noeud = null; - boolean recieved = false; + Register registerSpawner = null ; + Node noeud = null ; + boolean recieved = false ; idAlgo = LocalHost.Instance().getIP() + ":" + LocalHost.Instance().getPort() ; - System.out.println("Trying to get a Register on the SuperNode"); - int nbExtraSpawners = 0; + System.out.println( "Trying to get a Register on the SuperNode" ) ; + int nbExtraSpawners = 0 ; if (nbTasks > nbOfDaemonsPerSpawner) { - nbExtraSpawners = (nbTasks - 1) / nbOfDaemonsPerSpawner; + nbExtraSpawners = (nbTasks - 1) / nbOfDaemonsPerSpawner ; } @@ -1075,17 +1207,16 @@ public class JaceSpawner { paramAlgo = nbFault ; } - while (!recieved) { + while( !recieved ) + { try { registerSpawner = centralServer.getRegisterSpawner(idAlgo, nbTasks, (Task) tache, nbTasks + nbExtraSpawners, algo, paramAlgo); recieved = true; } catch (Exception e) { - System.err - .println("Unable to recieve a register from superNode " - + e); - connectSuperNode(); + System.err.println( "Unable to recieve a register from superNode: " + e ) ; + connectSuperNode() ; } } @@ -1102,9 +1233,9 @@ public class JaceSpawner { "grid_"+algo+"_"+nbFault+"_"+test+".xml") ; Utils.writeMapping( al.getMapping(), "/home/lyon/smiquee/resultats/", "mapping_"+algo+"_"+nbFault+"_"+test+".xml" ) ; - } catch (RemoteException e1) { - System.err.println( "Problème avec Algo dans Spawner !" ) ; - e1.printStackTrace(); + } catch( RemoteException e1 ) { + System.err.println( "Unable to retrieve Algo information in Spawner!" ) ; + e1.printStackTrace() ; } if (registerSpawner.getSize() != (nbTasks + nbExtraSpawners)) { @@ -1120,7 +1251,7 @@ public class JaceSpawner { System.exit( 1 ) ; } - spawnersList = new Vector(); + spawnersList = new ArrayList(); for (int i = 0; i < nbExtraSpawners && i < registerSpawner.getSize(); i++) { spawnersList.add(registerSpawner.getNodeAt(0)); @@ -1137,25 +1268,27 @@ public class JaceSpawner { * nbTasks); } catch(Exception e1) {} */ - if (registerSpawner != null) { - System.out.println("I received the register"); + if( registerSpawner.getSize() > 0 ) + { + System.out.println( "I received the register" ) ; // registerSpawner.setVersion(registerVersion); // registerVersion++; - Register.Instance().replaceBy(registerSpawner); - System.out.println("It contains " + Register.Instance().getSize() - + " Nodes" + " " + nbExtraSpawners + " ExtraSpawners"); + Register.Instance().replaceBy( registerSpawner ) ; + System.out.println( "It contains " + Register.Instance().getSize() + + " Nodes" + " " + nbExtraSpawners + " ExtraSpawners" ) ; // set each Node aliveTime value to the Spawner current time - for (int i = 0; i < Register.Instance().getSize(); i++) { - noeud = Register.Instance().getNodeAt(i); - noeud.setAliveFlag(true); - noeud.setAliveTime(); + for (int i = 0; i < Register.Instance().getSize(); i++) + { + noeud = Register.Instance().getNodeAt( i ) ; + noeud.setAliveFlag( true ) ; + noeud.setAliveTime() ; } } else { - System.err.println("\n---------------WARNING--------------"); - System.err.println("No Daemon available on the SuperNode dispo, try later, please"); - System.exit(0); + System.err.println( "\n---------------WARNING--------------" ) ; + System.err.println( "No Daemon available on the SuperNode, try later, please" ) ; + System.exit( 0 ) ; } } @@ -1174,10 +1307,10 @@ public class JaceSpawner { try { System.out.println("Trying to transform the spawner (" + n.getName() + ") of rank " + i); - spawnersList.setElementAt(n.getStub().transformIntoSpawner( + spawnersList.set( i, n.getStub().transformIntoSpawner( params, appliName, Register.Instance(), nbTasks, centralServer, i, heartTime, 0, 0, 0, - nbOfDaemonsPerSpawner, nbOfDeamonsPerThread, idAlgo), i); + nbOfDaemonsPerSpawner, nbOfDeamonsPerThread, idAlgo) ) ; } catch (Exception e) { System.err.println("Error while contacting newly acquired spawner (" + n.getName() + "): " + e); @@ -1213,7 +1346,7 @@ public class JaceSpawner { Random r = null ; int next, old = -1 ; - System.out.println( "Starting fault tolerance !" ) ; + System.out.println( "Starting faults simulation!" ) ; while( ! RunningApplication.Instance().isRunning() ) { @@ -1226,14 +1359,25 @@ public class JaceSpawner { while( RunningApplication.Instance().isRunning() ) { + /** Stop too long computation **/ + if( (RunningApplication.Instance().getChrono().getValue() / 1000) > 700 ) + { + try { + Register.Instance().getSpawnerStub().setFinished( true ) ; + } catch (RemoteException e) { + System.err.println( "Unable to stop the too long computation!" ) ; + e.printStackTrace() ; + } + } + /** Waiting some time ... **/ try { sleep( faultTime * 1000 ) ; - } catch (InterruptedException e) { + } catch( InterruptedException e ) { } /** ... and kill some daemons ! **/ - t = Register.Instance().getListeOfTasks(); + t = Register.Instance().getListeOfTasks() ; r = new Random() ; for( int i = 0 ; i < nbFault ; i++ ) @@ -1246,32 +1390,32 @@ public class JaceSpawner { } old = next ; - Node noeud = null; + Node noeud = null ; try { - TaskId recev = null; - System.out.println("Making fault on Task" + next); + TaskId recev = null ; + System.out.println( "Making fault on Task" + next ) ; - recev = t.getTaskIdOfRank( next ); + recev = t.getTaskIdOfRank( next ) ; - JaceInterface stub = recev.getHostStub(); - System.out.println("name = " + recev.getHostName()); + JaceInterface stub = recev.getHostStub() ; + System.out.println( "name = " + recev.getHostName() ) ; noeud = Register.Instance().getNodeOfStub( stub ) ; stub.suicide2( "Test fault tolerance" ) ; - } catch (UnmarshalException ue ){ - } catch (Exception e) { + } catch( UnmarshalException ue ) { + } catch( Exception e) { try { - System.err.println("Error in FaultMake on node: " - + noeud.getName() + ". " + e); + System.err.println( "Error in FaultMake on node: " + + noeud.getName() + ". " + e ) ; } catch (Exception e2) { - System.err.println("(Fault)Error in error:" + e2); + System.err.println( "(Fault) Error in error:" + e2 ) ; } } try { sleep( 500 ) ; - } catch (InterruptedException e) { + } catch( InterruptedException e ) { } } } @@ -1297,7 +1441,7 @@ public class JaceSpawner { */ // System.out.println("start process on spawner of rank "+i); JaceSpawnerInterface spawnerStub = (JaceSpawnerInterface) spawnersList.get(i); - spawnerStub.startProcess(spawnersList); + spawnerStub.startProcess( spawnersList ) ; } catch (Exception e) { e.printStackTrace(System.out); System.err.println("Unable to start the process on the spawner of rank " @@ -1310,7 +1454,7 @@ public class JaceSpawner { Node n; int i; for (i = 0; i < spawnersList.size(); i++) { - n = (Node) spawnersList.elementAt(i); + n = (Node) spawnersList.get( i ) ; // Register.Instance().getListeOfTasks().viewAll(); // spawnersList.setElementAt(n.getStub().transformIntoSpawner( @@ -1331,7 +1475,7 @@ public class JaceSpawner { for (int j = 0; j < spawnersList.size(); j++) { System.out.println("waiting till transform of spawner " + j + " is finished"); - while ((spawnersList.elementAt(j) instanceof Node)) + while ((spawnersList.get(j) instanceof Node)) { try { @@ -1415,7 +1559,7 @@ public class JaceSpawner { for (int j = count; j < nbTasks; j++) { tsk.addTask(new TaskId(appliName, j, null)); } - System.out.println("in Register, misses " + System.out.println("In Register, misses " + (nbTasks - Register.Instance().getSize()) + " nodes"); } @@ -1583,6 +1727,7 @@ public class JaceSpawner { } } + @SuppressWarnings("unchecked") private synchronized void broadcastScanning() { Register reg = Register.Instance(); while (broadcasting == true) @@ -1591,7 +1736,7 @@ public class JaceSpawner { } catch (Exception e) { } // Register.Instance().viewAll(); - Vector nodes = (Vector) Register.Instance().getListOfNodes().clone(); + ArrayList nodes = (ArrayList) Register.Instance().getListOfNodes().clone(); int x = reg.getListeOfTasks().getSize() / nbOfDaemonsPerSpawner; int s; if (rank == x) @@ -1613,44 +1758,44 @@ public class JaceSpawner { } - @SuppressWarnings("unchecked") public synchronized Register getRegister( int rank ) { - ListeTask listOfTasks = Register.Instance().getListeOfTasks(); - Vector dependencies = getDependencies(rank, listOfTasks.getSize()); - Register g = new Register(); - ListeTask newListOfTasks = new ListeTask(); + ListeTask listOfTasks = Register.Instance().getListeOfTasks() ; + ArrayList dependencies = getDependencies( rank, listOfTasks.getSize() ) ; + Register g = new Register() ; + ListeTask newListOfTasks = new ListeTask() ; - g.setAppliName(Register.Instance().getAppliName()); - g.setParams(Register.Instance().getParams()); - g.setSpawnerStub(Register.Instance().getSpawnerStub()); - g.setNbOfTasks(Register.Instance().getNbOfTasks()); + g.setAppliName( Register.Instance().getAppliName() ) ; + g.setParams( Register.Instance().getParams() ) ; + g.setSpawnerStub( Register.Instance().getSpawnerStub() ) ; + g.setNbOfTasks( Register.Instance().getNbOfTasks() ) ; // g.setVersion(reg.getVersion()); - for (int j = 0; j < dependencies.size(); j++) { - TaskId id = listOfTasks.getTaskIdOfRank(((Integer) dependencies - .elementAt(j)).intValue()); - newListOfTasks.addTask(id); - if (id.getHostStub() != null) { - Node noeud = Register.Instance() - .getNodeOfName( id.getHostName() ) ;// (id.getHostStub()); + for( int j = 0 ; j < dependencies.size() ; j++ ) + { + TaskId id = listOfTasks.getTaskIdOfRank( ( (Integer) dependencies + .get(j) ).intValue() ) ; + newListOfTasks.addTask( id ) ; + if( id.getHostStub() != null ) { + Node noeud = Register.Instance().getNodeOfName( id.getHostName() ) ;// (id.getHostStub()); if( noeud != null ) + { g.addNode( noeud ) ; - else + } else { System.err.println( "PAS BON DU TOUT" ) ; + } } } - g.setListeOfTasks(newListOfTasks); - return g; + g.setListeOfTasks(newListOfTasks) ; + return g ; } - @SuppressWarnings("unchecked") private void updateConcernedNodes(int rank, Node oldNode, Node node) { ListeTask listOfTasks = Register.Instance().getListeOfTasks(); - Vector dependencies = getDependencies(rank, listOfTasks.getSize()); + ArrayList dependencies = getDependencies(rank, listOfTasks.getSize()); System.out.println("List of concerned neighbors of task " + rank+": "); for (int z = 0; z < dependencies.size(); z++) - System.out.print(((Integer) dependencies.elementAt(z)).intValue() + System.out.print(((Integer) dependencies.get(z)).intValue() + " "); System.out.println(); // Register.Instance().setVersion(registerVersion); @@ -1670,19 +1815,22 @@ public class JaceSpawner { } } - private Vector getDependencies(int id, int jaceSize) { + private ArrayList getDependencies( int id, int jaceSize ) + { // get computing dependencies - Vector neighbors = new Vector(); - int[] dep = tache.getDependencies(id); - for (int z = 0; z < taille(dep); z++) - neighbors.add(dep[z]); + ArrayList neighbors = new ArrayList() ; + int[] dep = tache.getDependencies( id ) ; + for( int z = 0 ; z < taille(dep) ; z++ ) + { + neighbors.add( dep[z] ) ; + } // System.out.println("la liste des voisins de calcul de: "+id+" concerne"); // for(int z=0;z nodes; + ArrayList nodes; int nbOfDeamonsPerThread, nbOfDeamonsPerSpawner; - StartScanThread(int i, Vector nodes, int debut) { + StartScanThread(int i, ArrayList nodes, int debut) { this.i = i; this.nodes = nodes; this.debut = debut; @@ -1762,7 +1910,7 @@ class StartScanThread extends Thread { && index < debut + nbOfDeamonsPerSpawner && index < nodes.size(); index++) { - Node node = (Node) nodes.elementAt(index); + Node node = (Node) nodes.get(index); JaceInterface stub = node.getStub(); String name = node.getName(); try {