Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New development version.
authorSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 7 May 2010 08:55:54 +0000 (10:55 +0200)
committerSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 7 May 2010 08:55:54 +0000 (10:55 +0200)
 - Correct interaction with the Mapping library.

 - Correction of some bugs.

 - Cleaning (partially) the code.

 - /!\ Some code is used for tests with fault tolerance ! This code is fully dependent on my account on Grid'5000 ! To be cleaned /!\

18 files changed:
src/jaceP2P/JaceDaemon.java
src/jaceP2P/JaceInterface.java
src/jaceP2P/JaceP2P.java
src/jaceP2P/JaceServer.java
src/jaceP2P/JaceSpawner.java
src/jaceP2P/JaceSpawnerServer.java
src/jaceP2P/JaceSuperNode.java
src/jaceP2P/JaceSuperNodeInterface.java
src/jaceP2P/JaceSuperNodeServer.java
src/jaceP2P/ListeTask.java
src/jaceP2P/LocalHost.java
src/jaceP2P/Register.java
src/jaceP2P/ScanThread.java
src/jaceP2P/SuperNodeListe.java
src/jaceP2P/Task.java
src/jaceP2P/TaskId.java
src/jaceP2P/UpdateRegisterConcernedThread.java
src/jaceP2P/UpdateRegisterThread.java

index 21a8c17..f894793 100644 (file)
@@ -3,30 +3,36 @@ package jaceP2P;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.rmi.Naming;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
 
 
+import and.Mapping.GNode;
 import and.Mapping.Utils;
 
 public class JaceDaemon {
        // attributes
        public static JaceDaemon Instance = null;
        private String snode_IP = null;
 import and.Mapping.Utils;
 
 public class JaceDaemon {
        // attributes
        public static JaceDaemon Instance = null;
        private String snode_IP = null;
-       private int snode_port = 1098;
-       private int daemonPort = 1098;
+       private int snode_port = 1099;
+       private int daemonPort = 1099;
        private int heartTime; // HeartBeat frequency
        private String protocol;
        private boolean running = false;
 
        private int heartTime; // HeartBeat frequency
        private String protocol;
        private boolean running = false;
 
-       public JaceDaemon(String superNode, int port, String comProtocol) {
-               if (!superNode.equals("-d")) {
+       public JaceDaemon( String superNode, int port, String comProtocol ) {
+               if( !superNode.equals( "-d" ) ) 
+               {
                        // snode_IP = LocalHost.Instance().resolve(superNode); // get IP of
                        // the super node
                        // snode_IP = LocalHost.Instance().resolve(superNode); // get IP of
                        // the super node
-                       snode_IP = superNode;
+                       snode_IP = superNode ;
                }
 
                }
 
-               daemonPort = port;
-               protocol = comProtocol;
-               running = true;
-               Instance = this;
+               daemonPort = port ;
+               protocol = comProtocol ;
+               running = true ;
+               Instance = this ;
 
                // initialize();
        }
 
                // initialize();
        }
@@ -66,20 +72,14 @@ public class JaceDaemon {
      *
      **/
        public void initialize() {
      *
      **/
        public void initialize() {
-               LocalHost.Instance().setPort(daemonPort);
-               exportObject(); // Iinstanciate the JaceServer localy
-               reconnectSuperNode(); // Connect to one of the SuperNodes
-               if (protocol.equals("socket")) {
-                       listenForRequests();
+               LocalHost.Instance().setPort( daemonPort ) ;
+               exportObject() ; // Instanciate the JaceServer localy
+               reconnectSuperNode() ; // Connect to one of the SuperNodes
+               
+               if( protocol.equals( "socket" ) ) 
+               {
+                       listenForRequests() ;
                }
                }
-
-               /*
-                * System.out.println("sleep de 5 secondes avt tuer Daemon"); try {
-                * Thread.sleep(5000); } catch(Exception e1) {}
-                * 
-                * 
-                * sortir();
-                */
        }
 
        /**
        }
 
        /**
@@ -112,20 +112,54 @@ public class JaceDaemon {
      *
      **/
        private void exportObject() {
      *
      **/
        private void exportObject() {
-               // if( protocol.equals( "rmi" ) ) {
-               JaceInterface ref = null;
-               JaceServer myServer = null;
-
-               //System.out.println("Name of local machine is : "
-               //              + LocalHost.Instance().getName());
-               //System.out.println("IP of local machine is : "
-               //              + LocalHost.Instance().getIP());
+               JaceInterface ref = null ;
+               JaceServer myServer = null ;
 
 
+               Registry reg ;
+               
                try {
                try {
+                       
+                       while( true )
+                       {
+                               reg = LocateRegistry.getRegistry( daemonPort ) ;
+
+                               String tab[] = reg.list() ;
+                       
+                               System.out.println( "There is an existing RMI Registry on port "+daemonPort+" with "+tab.length+" entries!" ) ;
+                               for( int i = 0 ; i < tab.length ; i++ )
+                               {
+                                       try {
+                                               if( UnicastRemoteObject.unexportObject( Naming.lookup(tab[i]), true ) )
+                                               {
+                                                       System.out.println( "Register successfuly deleted!" ) ;
+                                               } else {
+                                                       System.err.println( "Register undeleted !!!" ) ;
+                                               }
+                                       } catch (Exception e) {
+                                               e.printStackTrace();
+                                       }
+                               }
+                       
+                               if( UnicastRemoteObject.unexportObject( myServer, true ) )
+                               {
+                                       System.out.println( "Register successfuly deleted!" ) ;
+                               } else {
+                                       System.err.println( "Register undeleted !!!" ) ;
+                               }
+                       }
+               } catch( RemoteException e ) {
+               }       
+               
+               
+               try {
+                       if (System.getSecurityManager() == null) {
+                   System.setSecurityManager(new SecurityManager());
+               }
+                       
                        // launch the JaceServer
                        myServer = new JaceServer( /* this */);
                        // launch the JaceServer
                        myServer = new JaceServer( /* this */);
-                       java.rmi.registry.LocateRegistry.createRegistry(daemonPort);
-                       java.rmi.registry.LocateRegistry.getRegistry(daemonPort).rebind(
+                       LocateRegistry.createRegistry(daemonPort);
+                       LocateRegistry.getRegistry(daemonPort).rebind(
                                        "JaceServer", myServer);
                        ref = (JaceInterface) Naming.lookup("rmi://"
                                        + LocalHost.Instance().getIP() + ":" + daemonPort
                                        "JaceServer", myServer);
                        ref = (JaceInterface) Naming.lookup("rmi://"
                                        + LocalHost.Instance().getIP() + ":" + daemonPort
@@ -139,7 +173,6 @@ public class JaceDaemon {
                }
 
                LocalHost.Instance().setStub(ref);
                }
 
                LocalHost.Instance().setStub(ref);
-               // }
        }
 
        /**
        }
 
        /**
@@ -160,7 +193,8 @@ public class JaceDaemon {
                }
 
        }
                }
 
        }
-
+       
+       
        /**
      *
      **/
        /**
      *
      **/
@@ -189,11 +223,11 @@ public class JaceDaemon {
                        } catch (Exception e) {
                                //System.out
                                //              .println("Snode not launched, try another one (1/2s)");
                        } catch (Exception e) {
                                //System.out
                                //              .println("Snode not launched, try another one (1/2s)");
-                               try {
-                                       Thread.sleep(500);
-                               } catch (Exception e1) {
-                                       // nothing
-                               }
+//                             try {
+//                                     Thread.sleep(500);
+//                             } catch (Exception e1) {
+//                                     // nothing
+//                             }
                        }
                }
 
                        }
                }
 
@@ -254,10 +288,26 @@ public class JaceDaemon {
                                // LocalHost.Instance().getIP(),
                                // LocalHost.Instance().getName(),
                                // daemonPort ) ;
                                // LocalHost.Instance().getIP(),
                                // LocalHost.Instance().getName(),
                                // daemonPort ) ;
+                               
+                               GNode me = Utils.createGNode() ;
+                               
+                               if( me == null )
+                               {
+                                       System.err.println( "Problem during the creation of my GNode !!" ) ;
+                                       System.exit( 1 ) ;
+                               } else {
+                                       if( me.getIP().equals( "" ) || me.getIP() == null
+                                               || me.getIP().isEmpty() 
+                                               || ! me.getIP().equals( LocalHost.Instance().getIP()))
+                                       {
+                                               System.err.println( "Problem with my IP address in my GNode !!" ) ;
+                                               System.exit( 2 ) ;
+                                       }
+                               }
 
                                snodeStub.workerRegistering(LocalHost.Instance().getStub(),
                                                LocalHost.Instance().getIP(), LocalHost.Instance()
 
                                snodeStub.workerRegistering(LocalHost.Instance().getStub(),
                                                LocalHost.Instance().getIP(), LocalHost.Instance()
-                                                               .getName(), daemonPort, Utils.createGNode());
+                                               .getName(), daemonPort, me ) ;
 
                                // Launching the heart beat thread
                                HeartBeatThread.Instance().setHeartTime(heartTime);
 
                                // Launching the heart beat thread
                                HeartBeatThread.Instance().setHeartTime(heartTime);
@@ -317,13 +367,13 @@ public class JaceDaemon {
                LocalHost.Instance().setStartedThreads(false);
                System.out.println("Reinitialization of the Daemon");
 
                LocalHost.Instance().setStartedThreads(false);
                System.out.println("Reinitialization of the Daemon");
 
-               System.out.println("I kill the application if any exists");
+               System.out.println( "I kill the application if any exists" ) ;
                // ScanThread.Instance().setScanning( false ) ;
                // System.out.println( "Set ScanThread off" ) ;
                // Sender.Instance().kill() ;
 
                try {
                // ScanThread.Instance().setScanning( false ) ;
                // System.out.println( "Set ScanThread off" ) ;
                // Sender.Instance().kill() ;
 
                try {
-                       Thread.sleep(2500);
+                       Thread.sleep( 2500 ) ;
                } catch (Exception e) {
                        // nothing
                }
                } catch (Exception e) {
                        // nothing
                }
@@ -339,11 +389,11 @@ public class JaceDaemon {
                        Register.Instance().purge();
 
                } catch (Exception e) {
                        Register.Instance().purge();
 
                } catch (Exception e) {
-                       System.err.println("Crashed killing the application : " + e);
+                       System.err.println( "Crashed killing the application : " + e ) ;
                }
 
                }
 
-               System.out.println("Daemon reinitialized");
-               // Runtime.getRuntime().gc() ;
+               System.out.println( "Daemon reinitialized" ) ;
+               System.gc() ;
                reconnectSuperNode();
        }
 
                reconnectSuperNode();
        }
 
index f49b598..e6694df 100644 (file)
@@ -73,7 +73,9 @@ public interface JaceInterface extends Remote {
        public void setSpawner(JaceSpawnerInterface spawnerStub)
                        throws RemoteException;
 
        public void setSpawner(JaceSpawnerInterface spawnerStub)
                        throws RemoteException;
 
-       public void updateRegister(Node oldNode, Node node) throws RemoteException;
+       public int updateRegister(Node oldNode, Node node, int rank) throws RemoteException;
 
        public void getBackupForNewNode(int rank) throws RemoteException;
 
        public void getBackupForNewNode(int rank) throws RemoteException;
+
+       public void suicide2(String string)throws RemoteException ;
 }
 }
index b089874..3322d0a 100644 (file)
@@ -29,8 +29,8 @@ public class JaceP2P {
                        if (entity.equals("-Daemon")) {
                                System.out
                                                .println("\n*************** LAUNCHING ---- DAEMON *****");
                        if (entity.equals("-Daemon")) {
                                System.out
                                                .println("\n*************** LAUNCHING ---- DAEMON *****");
-                               JaceDaemon daemon = new JaceDaemon(superNodeName, port,
-                                               comProtocol);
+                               JaceDaemon daemon = new JaceDaemon( superNodeName, port,
+                                               comProtocol ) ;
                                daemon.initialize();
                        } else if (entity.equals("-Spawner")) {
                                if (args.length > 9) {
                                daemon.initialize();
                        } else if (entity.equals("-Spawner")) {
                                if (args.length > 9) {
@@ -40,28 +40,34 @@ public class JaceP2P {
                                        int nbDaemonPerThread = -1;
                                        int nbSavingNodes = -1;
                                        int algoMapping = -1;
                                        int nbDaemonPerThread = -1;
                                        int nbSavingNodes = -1;
                                        int algoMapping = -1;
+                                       int test = -1 ;
                                        double paramAlgo = 0.5 ;
                                        double paramAlgo = 0.5 ;
+                                       int nbFault = 0 ;
+                                       int faultTime = 0 ;
 
                                        try {
                                                nbDaemonPerSpawner = new Integer(args[4]).intValue();
                                                nbDaemonPerThread = new Integer(args[5]).intValue();
                                                nbSavingNodes = new Integer(args[6]).intValue();
 
                                        try {
                                                nbDaemonPerSpawner = new Integer(args[4]).intValue();
                                                nbDaemonPerThread = new Integer(args[5]).intValue();
                                                nbSavingNodes = new Integer(args[6]).intValue();
-                                               algoMapping = new Integer(args[7]).intValue();
-                                               paramAlgo = new Double(args[8]).doubleValue();
+                                               test = new Integer(args[7]).intValue();
+                                               nbFault = new Integer(args[8]).intValue();
+                                               faultTime = new Integer(args[9]).intValue();
+                                               algoMapping = new Integer(args[10]).intValue();
+                                               paramAlgo = new Double(args[11]).doubleValue();
                                        } catch (NumberFormatException e) {
                                                System.err.println("The number of Daemons per spawner and the number of daemons per thread must be integers: "
                                                                                + e);
                                                System.exit(0);
                                        }
                                        //System.out.println("=====> " + algoMapping);
                                        } catch (NumberFormatException e) {
                                                System.err.println("The number of Daemons per spawner and the number of daemons per thread must be integers: "
                                                                                + e);
                                                System.exit(0);
                                        }
                                        //System.out.println("=====> " + algoMapping);
-                                       param = new String[args.length - 9];
-                                       for (int i = 9; i < args.length; i++) {
-                                               param[i - 9] = args[i];
+                                       param = new String[args.length - 12];
+                                       for (int i = 12; i < args.length; i++) {
+                                               param[i - 12] = args[i];
                                                System.out.println("=> " + args[i]);
                                        }
                                        JaceSpawner spawner = new JaceSpawner(superNodeName, port,
                                                        comProtocol, param, nbDaemonPerSpawner,
                                                System.out.println("=> " + args[i]);
                                        }
                                        JaceSpawner spawner = new JaceSpawner(superNodeName, port,
                                                        comProtocol, param, nbDaemonPerSpawner,
-                                                       nbDaemonPerThread, nbSavingNodes, algoMapping, paramAlgo);
+                                                       nbDaemonPerThread, nbSavingNodes, algoMapping, paramAlgo, test, nbFault, faultTime);
                                        spawner.initialize();
                                }
 
                                        spawner.initialize();
                                }
 
@@ -100,19 +106,19 @@ public class JaceP2P {
                System.out
                                .println("-Daemon : <option> = [superNodeName] [daemonPort] [protocol]");
                System.out
                System.out
                                .println("-Daemon : <option> = [superNodeName] [daemonPort] [protocol]");
                System.out
-                               .println("ex : java jaceP2P.JaceP2P -Daemon cluster1 1098 rmi");
+                               .println("ex : java jaceP2P.JaceP2P -Daemon cluster1 1099 rmi");
                System.out.println("");
                System.out
                                .println("-SNode : <option> = [superNodeName] [superNodePort] [protocol] [timeHeartBeat]");
                System.out
                System.out.println("");
                System.out
                                .println("-SNode : <option> = [superNodeName] [superNodePort] [protocol] [timeHeartBeat]");
                System.out
-                               .println("ex : java jaceP2P.JaceP2P -SNode cluster1 1098 rmi 500");
+                               .println("ex : java jaceP2P.JaceP2P -SNode cluster1 1099 rmi 500");
                System.out.println("");
                System.out
                                .println("-Spawner : <option> = [superNodeName] [SpawnerPort] [protocol] nbDaemonPerSpawner nbDaemonPerThread nbresave nbTask URLToTaskName <TaskParam>");
                System.out
                System.out.println("");
                System.out
                                .println("-Spawner : <option> = [superNodeName] [SpawnerPort] [protocol] nbDaemonPerSpawner nbDaemonPerThread nbresave nbTask URLToTaskName <TaskParam>");
                System.out
-                               .println("ex : java jaceP2P.JaceP2P -Spawner cluster1 1098 rmi 8 4 3 16 http://bilbo/staff/vuillemi/java/LinSolv2 1000 0 20000 5");
+                               .println("ex : java jaceP2P.JaceP2P -Spawner cluster1 1099 rmi 8 4 3 16 http://bilbo/staff/vuillemi/java/LinSolv2 1000 0 20000 5");
                System.out
                System.out
-                               .println("ex : java jaceP2P.JaceP2P -Spawner cluster1 1098 rmi 8 4 3 16 file:/home/vuillemi/java/LinSolv2 1000 0 20000 5");
+                               .println("ex : java jaceP2P.JaceP2P -Spawner cluster1 1099 rmi 8 4 3 16 file:/home/vuillemi/java/LinSolv2 1000 0 20000 5");
                System.exit(0);
        }
 }
                System.exit(0);
        }
 }
index b92c31e..69f0195 100644 (file)
@@ -92,7 +92,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                return 0;
        }
 
                return 0;
        }
 
-       public void updateRegister(Node oldNode, Node node) throws RemoteException {
+       public int updateRegister( Node oldNode, Node node, int rank ) throws RemoteException {
 
                // if(tag==1)
                // HeartBeatThread.Instance().setServer((Object)node.getStub());
 
                // if(tag==1)
                // HeartBeatThread.Instance().setServer((Object)node.getStub());
@@ -100,28 +100,44 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                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));
-               System.out.println("Modify  REGISTER");
+               System.out.println("Modify REGISTER");
                try {
                try {
-                       // System.out.println("blablablablabalablablabalbalab");
-                       System.out.println("oldName=" + oldNode.getName());
-                       boolean b = Register.Instance().removeNodeOfName(oldNode.getName());
-                       if (b)
-                               System.out.println("removed old Node!!!!!");
-                       else
-                               System.out.println("didn't find old Node!!!!");
-
-                       Register.Instance().addNode(node);
-                       Register.Instance().viewAll();
+                       boolean b = false ;
+                       if( oldNode != null )
+                       {
+                               System.out.println("Old node name=" + oldNode.getName());
+                               b = Register.Instance().removeNodeOfName(oldNode.getName());
+                       }
+                       if( b )
+                       {
+                               System.out.println("Old node removed !");
+                       } else {
+                               System.out.println("Did not find the old Node !");
+                       }
+
+                       if( node != null )
+                       {
+                               Register.Instance().addNode(node);
+                       } else {
+                               System.err.println( "The new node is NULL !" ) ;
+                               return 1 ;
+                       }
+//                     Register.Instance().viewAll();
                        TaskId myTaskId = null;
                        TaskId myTaskId = null;
+//                     myTaskId = Register.Instance().getListeOfTasks()
+//                                     .getTaskIdOfHostStub(oldNode.getStub());
                        myTaskId = Register.Instance().getListeOfTasks()
                        myTaskId = Register.Instance().getListeOfTasks()
-                                       .getTaskIdOfHostStub(oldNode.getStub());
+                       .getTaskIdOfRank( rank ) ;
                        myTaskId.setHostIP(node.getIP());
                        myTaskId.setHostName(node.getName());
                        // Register.Instance().setVersion(version);
                        myTaskId.setHostStub(node.getStub());
                        myTaskId.setHostIP(node.getIP());
                        myTaskId.setHostName(node.getName());
                        // Register.Instance().setVersion(version);
                        myTaskId.setHostStub(node.getStub());
+                       
+                       return 0 ;
 
                } catch (Exception e) {
                        System.err.println("Error in updateregister :" + e);
 
                } catch (Exception e) {
                        System.err.println("Error in updateregister :" + e);
+                       return 1 ;
                        // e.printStackTrace();
                }
        }
                        // e.printStackTrace();
                }
        }
@@ -295,18 +311,32 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                }
 
                public void run() {
                }
 
                public void run() {
-                       BackupsManager.Instance().initialize(req);
+                       BackupsManager.Instance().initialize( req ) ;
 
                }
        }
 
        class ReinitDaemon extends Thread {
 
 
                }
        }
 
        class ReinitDaemon extends Thread {
 
-               public ReinitDaemon() {
-               }
+               public ReinitDaemon() {}
 
                public void run() {
 
                public void run() {
-                       JaceDaemon.Instance().reinitDaemon();
+                       JaceDaemon.Instance().reinitDaemon() ;
                }
        }
                }
        }
+
+       @Override
+       public void suicide2( String mes ) throws RemoteException 
+       {
+               System.out.println( "Killed because: " + mes ) ;
+               
+               try{ 
+               UnicastRemoteObject.unexportObject( this, true ) ; 
+           } 
+           catch( Exception e ) {
+               System.err.println( "Unable to unexport myself: " + e ) ;
+           } 
+                                 
+               System.exit( 0 ) ;
+       }
 }
 }
index 6976abb..69eb8a3 100644 (file)
@@ -1,19 +1,28 @@
 package jaceP2P;
 
 package jaceP2P;
 
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
 import java.rmi.Naming;
 import java.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.UnmarshalException;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
+import java.util.Random;
 import java.util.Vector;
 
 import java.util.Vector;
 
+import and.Mapping.Algo;
+import and.Mapping.Utils;
+
 public class JaceSpawner {
        private Class<?> c;
        private Loader load;
        private Task tache = null;
        public static JaceSpawner Instance;
        private static String superNode_IP = null;
 public class JaceSpawner {
        private Class<?> c;
        private Loader load;
        private Task tache = null;
        public static JaceSpawner Instance;
        private static String superNode_IP = null;
-       private int superNode_port = 1098;
+       private int superNode_port = 1099;
        private static int spawnerPort = 1099;
        private static int spawnerPort = 1099;
-       private static JaceSuperNodeInterface centralServer = null;
+       protected static JaceSuperNodeInterface centralServer = null;
        private JaceSpawnerInterface spawnerRef = null;
        private int nbTasks;
        private String appliName;
        private JaceSpawnerInterface spawnerRef = null;
        private int nbTasks;
        private String appliName;
@@ -39,14 +48,26 @@ public class JaceSpawner {
        private int algo;
        private double paramAlgo ;
        private String idAlgo ;
        private int algo;
        private double paramAlgo ;
        private String idAlgo ;
+       
+       // ** Test ** //
+       private int test;
+       private double dh ;
+       protected int nbFault ;
+       protected int faultTime ;
 
        public JaceSpawner(String superNode, int port, String comProtocol,
                        String[] args, int nbDaemonPerSpawner, int nbDaemonPerThread,
 
        public JaceSpawner(String superNode, int port, String comProtocol,
                        String[] args, int nbDaemonPerSpawner, int nbDaemonPerThread,
-                       int nbSavingNodes, int _algo, double _paramAlgo) {
+                       int nbSavingNodes, int _algo, double _paramAlgo, int _test, int _nbF, int _fT) {
                // superNode_IP = LocalHost.Instance().resolve(superNode);
                algo = _algo;
                paramAlgo = _paramAlgo ;
                
                // superNode_IP = LocalHost.Instance().resolve(superNode);
                algo = _algo;
                paramAlgo = _paramAlgo ;
                
+               
+               test = _test ;
+               nbFault = _nbF ;
+               faultTime = _fT ;
+               
+               
                superNode_IP = superNode;
                spawnerPort = port;
                protocol = comProtocol;
                superNode_IP = superNode;
                spawnerPort = port;
                protocol = comProtocol;
@@ -114,7 +135,7 @@ public class JaceSpawner {
                }
                
                idAlgo = _idAlgo ;
                }
                
                idAlgo = _idAlgo ;
-               // System.out.println("xxxxxxxxxxxxxxx reg size="+reg.getSize()+" xxxxxxxxxxxxxx");
+               
                this.appliName = appliName;
 
                this.nbTasks = nbTasks;
                this.appliName = appliName;
 
                this.nbTasks = nbTasks;
@@ -145,7 +166,7 @@ public class JaceSpawner {
                RunningApplication.Instance().setRunning(true);
                RunningApplication.Instance().setNumberOfDisconnections(nbdc);
                RunningApplication.Instance().setNumberOfSpawnerDisconnections(nbsdc);
                RunningApplication.Instance().setRunning(true);
                RunningApplication.Instance().setNumberOfDisconnections(nbdc);
                RunningApplication.Instance().setNumberOfSpawnerDisconnections(nbsdc);
-               // System.out.println("+++++++++++++++++++++++++");
+               
                Instance = this;
                // if(tag==0)
                broadcastRegister(1);
                Instance = this;
                // if(tag==0)
                broadcastRegister(1);
@@ -216,7 +237,7 @@ public class JaceSpawner {
                        ScanThreadSpawner.Instance().start();
 
                        broadcastScanning();
                        ScanThreadSpawner.Instance().start();
 
                        broadcastScanning();
-//                     System.out.println("apres broadcastScanning");
+
                        new StartScanning().start();
                } else {
                        System.err.println("Cannot find myself in the spawnersList !");
                        new StartScanning().start();
                } else {
                        System.err.println("Cannot find myself in the spawnersList !");
@@ -231,6 +252,12 @@ public class JaceSpawner {
        public void initialize() {
                // if(protocol.equals("rmi")){
                // launch the JaceSpawnerServer
        public void initialize() {
                // if(protocol.equals("rmi")){
                // launch the JaceSpawnerServer
+               if (System.getSecurityManager() == null) {
+            System.setSecurityManager(new SecurityManager());
+        }
+
+//             signal = false ;
+               
                exportObject();
 
                connectSuperNode();
                exportObject();
 
                connectSuperNode();
@@ -242,6 +269,8 @@ public class JaceSpawner {
                createAppli();
                createSpawnerNetwork();
 
                createAppli();
                createSpawnerNetwork();
 
+               // ** Tests ** //
+               new FaultMake().run() ;
                // }
        }
 
                // }
        }
 
@@ -269,7 +298,8 @@ public class JaceSpawner {
        }
 
        public synchronized void signalDeadNode(JaceInterface host, int rankOfDead) {
        }
 
        public synchronized void signalDeadNode(JaceInterface host, int rankOfDead) {
-               try {
+               
+
                        TaskId myTaskId = null;
                        int nb = 0;
                        int nbC = 0;
                        TaskId myTaskId = null;
                        int nb = 0;
                        int nbC = 0;
@@ -281,33 +311,64 @@ public class JaceSpawner {
                        nbC = RunningApplication.Instance().getNumberOfCouilles();
                        System.out.println("At time = " + time + "s,      NbDisconnection = "
                                        + nb + ",     NbProblem =  " + nbC);
                        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
 
                        // !!!!!!!!!!!!!!actualiser le ListeTask ds le Register
-                       myTaskId = Register.Instance().getListeOfTasks()
+                       try {
+                               myTaskId = Register.Instance().getListeOfTasks()
                                        .getTaskIdOfHostStub(host);
                                        .getTaskIdOfHostStub(host);
+                       } catch( Exception e ) {}
+                       
                        if (myTaskId == null) {
                        if (myTaskId == null) {
-                               Register.Instance.getListeOfTasks().viewAll();
                                myTaskId = Register.Instance().getListeOfTasks()
                                                .getTaskIdOfRank(rankOfDead);
                                myTaskId = Register.Instance().getListeOfTasks()
                                                .getTaskIdOfRank(rankOfDead);
+                               if( myTaskId == null )
+                               {
+                                       System.err.println("Houston we have a serious problem!!");
+                                       return ;
+                               }
+                               
                                JaceInterface deadStub = myTaskId.getHostStub();
                                JaceInterface deadStub = myTaskId.getHostStub();
-                               deadStub.suicide("Not doing a good work");
+                               
+                               if( deadStub != null )
+                               {
+                                       try{
+                                               deadStub.suicide2("Not doing a good work");
+                                       }catch(Exception e){}
+                               } else {
+                                       System.err.println( "Dead node stub unavailable!" );
+                               }
                        }
                        }
-                       myTaskId.setHostIP(null);
-                       myTaskId.setHostName(null);
-                       Node noeud = Register.Instance().getNodeOfStub(
-                                       myTaskId.getHostStub());
-                       myTaskId.setHostStub(null);
+
+                       Node noeud = Register.Instance().getNodeOfName( myTaskId.getHostName() ) ;
+
                        int rankDeaD = myTaskId.getRank();
 
                        int rankDeaD = myTaskId.getRank();
 
-                       String nomNoeud = noeud.getName();
-                       // Register.Instance().removeNodeAt(i);
-                       // Register.Instance().removeNode(host.getIP());
-                       // System.out.println("fait le remove    : taille = " +
-                       // Register.Instance().getSize());
+                       String nomNoeud = "" ;
+                       
+                       if( noeud != null )
+                       {
+                               nomNoeud = noeud.getName();
+                       }
 
 
-                       boolean b = Register.Instance().removeNodeOfName(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 == true) {
+                       if( b == true ) 
+                       {
                                System.out.println("Removing Node of rank "
                                                + rankDeaD + "  : size = "
                                                + Register.Instance().getSize());
                                System.out.println("Removing Node of rank "
                                                + rankDeaD + "  : size = "
                                                + Register.Instance().getSize());
@@ -321,28 +382,54 @@ public class JaceSpawner {
                        System.out.println("At time=" + cal.get(Calendar.MINUTE) + ":"
                                        + cal.get(Calendar.SECOND));
 
                        System.out.println("At time=" + cal.get(Calendar.MINUTE) + ":"
                                        + cal.get(Calendar.SECOND));
 
-                       // retrouver SI POSSIBLE un autre libre pr remplacer celui la pr
-                       // cette tache
-                       
                        /**** Sébastien Miquée **/
                        /**** Sébastien Miquée **/
-                       //Node tmpNode = foundToReplaceThisNode(rankDeaD, nomNoeud);
-                       Node tmpNode = foundToReplaceThisNode(rankDeaD, nomNoeud, noeud);
+                       Node tmpNode = null ;
+                       int retry = 0, retryMax = 4 ;
+                       
+                       while( tmpNode == null )
+                       {
+                               tmpNode = foundToReplaceThisNode(rankDeaD, nomNoeud, noeud);
+                               
+                               if( tmpNode == null )
+                               {
+                                       try{
+                                               Thread.sleep( 1000 ) ;
+                                       } catch( Exception e ) {}
+                                       
+                                       retry++ ;
+                                       
+                                       if( retry > retryMax )
+                                       {
+                                               System.err.println( "Unable to replace the dead node "+nomNoeud ) ;
+                                               return ;
+                                       }
+                               }
+                       }
+                       
                        try {
                        try {
-                               // broadcastRegister(0);
                                updateConcernedNodes(rankDeaD, noeud, tmpNode);
 
                                Thread.sleep(500);
                                updateConcernedNodes(rankDeaD, noeud, tmpNode);
 
                                Thread.sleep(500);
-                               System.out.println("Set scanning on %%%%%%");
-                               tmpNode.getStub().setScanning(true);
+                               System.out.println("Set scanning on "+tmpNode.getName());
+                               tmpNode.getStub().setScanning( true ) ;
                        } catch (Exception e) {
                        } catch (Exception e) {
-                               System.err.println("Unable to setScannig on for the new node: "
-                                               + e);
+                               try {
+                                       Thread.sleep( 2000 ) ;
+                                       
+                                       tmpNode.getStub().setScanning( true ) ;
+                               } catch (InterruptedException e1) {
+                               } catch (RemoteException e2) {
+                                       System.err.println( "Unable to setScanning on for the new node: " + e2 ) ;
+                               }
+                               System.err.println("Unable to setScanning on for the new node: "
+                                               + e) ;
                        }
 
                        }
 
-                       // Register.Instance().getListeOfTasks().viewAll();
                        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);
                                        try {
                                                ((JaceSpawnerInterface) spawnersList.get(z))
                                                                .replaceDeamonBy(noeud, tmpNode, rankDeaD);
@@ -352,9 +439,8 @@ public class JaceSpawner {
                                                                .println("Unable to broadcast the modifications to all the spawners: "
                                                                                + e);
                                        }
                                                                .println("Unable to broadcast the modifications to all the spawners: "
                                                                                + e);
                                        }
-               } catch (Exception ee) {
-                       System.err.println("Error in signalDeadNode() :" + ee);
-               }
+                               }
+                       }                                       
        }
 
        // verifie si les noeud notes vivant ds le Register.Instance() du SuperNode
        }
 
        // verifie si les noeud notes vivant ds le Register.Instance() du SuperNode
@@ -393,25 +479,28 @@ public class JaceSpawner {
        // pr les requisitionner
        
        /*** Sébastien Miquée ***/
        // pr les requisitionner
        
        /*** Sébastien Miquée ***/
-       
-       //private synchronized Node foundToReplaceThisNode(int theRank, String nom) {
-       private synchronized Node foundToReplaceThisNode(int theRank, String nom, Node _n) {
-               // int i = 0;
+       private synchronized Node foundToReplaceThisNode(int theRank, String nom, Node _n) 
+       {
                boolean found = false ;
                Node node = null ;
                boolean found = false ;
                Node node = null ;
+               int nbNull = 0 ;
 
                while( found == false ) {
                        try {
 
                while( found == false ) {
                        try {
-
-                               //node = centralServer.getNewNode(LocalHost.Instance().getIP());
-                               node = centralServer.getNewNode( idAlgo, _n);
+                               node = null ;
                                
                                
-                               if( node != null )
+                               node = centralServer.getNewNode( idAlgo, theRank ) ;
+
+                               if( node != null && ! node.getIP().isEmpty() && node.getIP() != null
+                                       && ! node.getIP().equals( "" ) )
                                {
                                        found = true ;
                                } else {
                                {
                                        found = true ;
                                } else {
-                                       Thread.sleep( 1000 ) ;
-                                       System.out.println("Pas de bon retour !");
+                                       System.err.println("Returned node is null!");
+                                       nbNull++ ;
+                                       try {
+                                               Thread.sleep( 2000 ) ;
+                                       } catch( Exception e ) {}
                                }
                        } catch (Exception e) {
                                // trouver un autre superNode et lui demander le noeud a lui
                                }
                        } catch (Exception e) {
                                // trouver un autre superNode et lui demander le noeud a lui
@@ -420,14 +509,18 @@ public class JaceSpawner {
 
                                connectSuperNode();
                        }
 
                                connectSuperNode();
                        }
+                       
+                       if( Register.Instance().existNode( node ) != -1 ) 
+                       {
+                               found = false ;
+                       }
                }
                
                
                }
                
                
-               if (node != null) {
-                       System.out.println("Using Node " + node.getName() + "       ("
-                                       + node.getIP() + ") in order to replace " + nom
-                                       + "   size before add: " + Register.Instance().getSize()
-                                       + "\n\n");
+               if( node != null ) 
+               {
+                       System.out.println( "Using Node " + node.getName() + " in order to replace " + nom + "\n" ) ;
+                                       
                        node.setAliveFlag(true);
                        node.setAliveTime();
 
                        node.setAliveFlag(true);
                        node.setAliveTime();
 
@@ -449,8 +542,10 @@ public class JaceSpawner {
                        // TODO verif pourkoi superNode me le redonne
                        // alors qu'il fait deja du calcul
                        // int is = Register.Instance().existNode(node.getIP());
                        // 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) {
+                       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;
                                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;
@@ -464,20 +559,54 @@ public class JaceSpawner {
                                myTaskId.setHostName(node.getName());
                                myTaskId.setHostStub(node.getStub());
 
                                myTaskId.setHostName(node.getName());
                                myTaskId.setHostStub(node.getStub());
 
-                               // Register.Instance().getListeOfTasks().viewAll();
                                int neighborRank;
                                if (theRank == 0)
                                int neighborRank;
                                if (theRank == 0)
+                               {
                                        neighborRank = Register.Instance().getSize() - 1;
                                        neighborRank = Register.Instance().getSize() - 1;
-                               else
+                               } else {
                                        neighborRank = theRank - 1;
                                        neighborRank = theRank - 1;
+                               }
+                               
                                TaskId neighborTask2 = Register.Instance().getListeOfTasks()
                                TaskId neighborTask2 = Register.Instance().getListeOfTasks()
-                                               .getTaskIdOfRank(neighborRank);
-                               try {
-                                       JaceInterface jaceStub = neighborTask2.getHostStub();
-                                       jaceStub.updateHeart(node.getStub());
-                               } catch (Exception e) {
-                                       System.err.println("Next node unreachable ! " + e);
-                                       // node = null;
+                                               .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() ) ;
+                                       }
                                }
 
                        }
                                }
 
                        }
@@ -511,20 +640,13 @@ public class JaceSpawner {
                        if (centralServer == null) {
                                System.err.println("Central Server not localized !");
                        }
                        if (centralServer == null) {
                                System.err.println("Central Server not localized !");
                        }
-                       node = centralServer.getNewNode( idAlgo, null ) ;
+                       node = centralServer.getNewNode( idAlgo, -2 ) ;
                        RunningApplication.Instance()
                                        .incrementNumberOfSpawnerDisconnections();
                        //found = true;
                } catch (Exception e) {
                        // trouver un autre superNode et lui demander le noeud a lui
                        System.err.println("Super Node not localized !\n " + e);
                        RunningApplication.Instance()
                                        .incrementNumberOfSpawnerDisconnections();
                        //found = true;
                } catch (Exception e) {
                        // trouver un autre superNode et lui demander le noeud a lui
                        System.err.println("Super Node not localized !\n " + e);
-//                     System.out.println("pas localise le super node " + e);
-//                     System.out.println("pas localise le super node " + e);
-//                     System.out.println("pas localise le super node " + e);
-//                     System.out.println("pas localise le super node " + e);
-//                     System.out.println("pas localise le super node " + e);
-//                     System.out.println("pas localise le super node " + e);
-//                     System.out.println("pas localise le super node " + e);
                        System.err.println("My IP : " + LocalHost.Instance().getIP());
                        if (centralServer == null) {
                                System.err.println("CentralServer is NULL !");
                        System.err.println("My IP : " + LocalHost.Instance().getIP());
                        if (centralServer == null) {
                                System.err.println("CentralServer is NULL !");
@@ -540,8 +662,6 @@ public class JaceSpawner {
                                                + LocalHost.Instance().resolve(node.getName())
                                                + ") to replace a dead spawner\n\n");
                                try {
                                                + LocalHost.Instance().resolve(node.getName())
                                                + ") to replace a dead spawner\n\n");
                                try {
-                                       // Register.Instance().viewAll();
-                                       // Register.Instance().getListeOfTasks().viewAll();
                                        spawnerStub = node.getStub().transformIntoSpawner(
                                                        params,
                                                        appliName,
                                        spawnerStub = node.getStub().transformIntoSpawner(
                                                        params,
                                                        appliName,
@@ -559,11 +679,9 @@ public class JaceSpawner {
                                                        , idAlgo);
                                        spawnersList.setElementAt(spawnerStub, index);
                                        
                                                        , idAlgo);
                                        spawnersList.setElementAt(spawnerStub, index);
                                        
-//                                     spawnerStub.setIdAlgo( idAlgo ) ;
-                                       
                                        
                                        new StartProcessThread(index).start();
                                        
                                        new StartProcessThread(index).start();
-                                       // spawnerStub.startProcess( spawnersList);
+
                                } catch (Exception e) {
                                        System.err.println("Unable to reach the new spawner: " + e);
                                }
                                } catch (Exception e) {
                                        System.err.println("Unable to reach the new spawner: " + e);
                                }
@@ -668,16 +786,25 @@ public class JaceSpawner {
                                                .getNumberOfSpawnerDisconnections();
                                
                                System.out.println("Application finished successfully !");
                                                .getNumberOfSpawnerDisconnections();
                                
                                System.out.println("Application finished successfully !");
-//                             System.out.println("Application finished successfully !!!!!!");
-//                             System.out.println("Application finished successfully !!!!!!");
-//                             System.out.println("Application finished successfully !!!!!!");
-//                             System.out.println("Application finished successfully !!!!!!");
-//                             System.out.println("Application finished successfully !!!!!!");
-//                             System.out
-//                                             .println("Application finished successfully !!!!!!\n");
+
                                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("TOTAL TIME in s : " + (finalTime / 1000));
                                System.out.println("nb of desconnections: " + nbe);
                                System.out.println("nb of spawners desconnections: " + nbsdc);
+                               
+                               // ** Tests ** //
+                               String path = "/home/lyon/smiquee/resultats/execTime_CG_"+algo+"_"+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( "DH = "+dh ) ;
+                               
+                               ecrivain.flush() ;
+                               ecrivain.close() ;
+                               
+                               
                                if (JaceDaemon.Instance().isRunning()) {
                                        JaceDaemon.Instance().reconnectSuperNode();
 
                                if (JaceDaemon.Instance().isRunning()) {
                                        JaceDaemon.Instance().reconnectSuperNode();
 
@@ -687,7 +814,6 @@ public class JaceSpawner {
                                        // purger l'appli
 
                                        RunningApplication.Instance().purge();
                                        // purger l'appli
 
                                        RunningApplication.Instance().purge();
-                                       // System.exit(1);
                                }
                                
                                /** Suprresion of the mapping algorithm on the SuperNode **/
                                }
                                
                                /** Suprresion of the mapping algorithm on the SuperNode **/
@@ -853,6 +979,9 @@ public class JaceSpawner {
                boolean connected = false;
                if (!(superNode_IP == null)) {
                        try {
                boolean connected = false;
                if (!(superNode_IP == null)) {
                        try {
+                               centralServer = null ; 
+                               System.gc() ;
+                               
                                System.out.println("Trying to invoke super node "
                                                + superNode_IP);
                                centralServer = (JaceSuperNodeInterface) Naming.lookup("rmi://"
                                System.out.println("Trying to invoke super node "
                                                + superNode_IP);
                                centralServer = (JaceSuperNodeInterface) Naming.lookup("rmi://"
@@ -931,6 +1060,8 @@ public class JaceSpawner {
                Node noeud = null;
                boolean recieved = false;
 
                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;
                if (nbTasks > nbOfDaemonsPerSpawner) {
                System.out.println("Trying to get a Register on the SuperNode");
                int nbExtraSpawners = 0;
                if (nbTasks > nbOfDaemonsPerSpawner) {
@@ -939,8 +1070,8 @@ public class JaceSpawner {
                }
                while (!recieved) {
                        try {
                }
                while (!recieved) {
                        try {
-                               registerSpawner = centralServer.getRegisterSpawner(LocalHost
-                                               .Instance().getIP(), nbTasks, (Task) tache, nbTasks
+                               registerSpawner = centralServer.getRegisterSpawner(idAlgo, 
+                                               nbTasks, (Task) tache, nbTasks
                                                + nbExtraSpawners, algo, paramAlgo);
                                recieved = true;
                        } catch (Exception e) {
                                                + nbExtraSpawners, algo, paramAlgo);
                                recieved = true;
                        } catch (Exception e) {
@@ -951,13 +1082,30 @@ public class JaceSpawner {
                        }
                }
                
                        }
                }
                
-               idAlgo = LocalHost.Instance().getIP() + ":" + LocalHost.Instance().getPort() ;
+               // ** Tests ** //
+               try {
+                       Algo al = centralServer.getAlgo( idAlgo ) ;
+                       
+                       dh = al.getGrid().getHeterogenityDegre() ;
+                       System.out.println( "### DH = " + dh ) ;
+                       
+                       Utils.writeGraph( al.getGraph(), "/home/lyon/smiquee/resultats/", 
+                                       "graph_CG_"+algo+"_"+test+".xml" ) ;
+                       Utils.writeGrid( al.getGrid(), "/home/lyon/smiquee/resultats/", 
+                                       "grid_CG_"+algo+"_"+test+".xml") ;
+                       Utils.writeMapping( al.getMapping(), "/home/lyon/smiquee/resultats/",
+                                       "mapping_CG_"+algo+"_"+test+".xml" ) ;
+               } catch (RemoteException e1) {
+                       System.err.println( "Problème avec Algo dans Spawner !" ) ;
+                       e1.printStackTrace();
+               }
                
                if (registerSpawner.getSize() != (nbTasks + nbExtraSpawners)) {
                        System.err.println("I did not recieve enough nodes from superNode!!!! \n killing application !!!!");
                        for (int i = 0; i < registerSpawner.getSize(); i++) {
                                try {
                
                if (registerSpawner.getSize() != (nbTasks + nbExtraSpawners)) {
                        System.err.println("I did not recieve enough nodes from superNode!!!! \n killing application !!!!");
                        for (int i = 0; i < registerSpawner.getSize(); i++) {
                                try {
-                                       registerSpawner.getNodeAt(i).getStub().reconnectSuperNode();
+                                       registerSpawner.getNodeAt(i).getStub().suicide( "Not enough nodes for the application" ) ;
+
                                } catch (Exception e) {
                                        System.err.println("The reserved node was unable to reconnect to the super node");
                                }
                                } catch (Exception e) {
                                        System.err.println("The reserved node was unable to reconnect to the super node");
                                }
@@ -968,9 +1116,9 @@ public class JaceSpawner {
                spawnersList = new Vector<Object>();
                for (int i = 0; i < nbExtraSpawners && i < registerSpawner.getSize(); i++) {
                        spawnersList.add(registerSpawner.getNodeAt(0));
                spawnersList = new Vector<Object>();
                for (int i = 0; i < nbExtraSpawners && i < registerSpawner.getSize(); i++) {
                        spawnersList.add(registerSpawner.getNodeAt(0));
-//                                     * nbOfDaemonsPerSpawner));
+
                        registerSpawner.removeNodeOfName(registerSpawner.getNodeAt(0).getName());
                        registerSpawner.removeNodeOfName(registerSpawner.getNodeAt(0).getName());
-//                                     * nbOfDaemonsPerSpawner));
+
                }
 
                registerSpawner.setNbOfTasks(nbTasks);
                }
 
                registerSpawner.setNbOfTasks(nbTasks);
@@ -1005,18 +1153,6 @@ public class JaceSpawner {
        }
        
        
        }
        
        
-//     /**
-//      * Set the identifier of the mapping algorithm used.
-//      * @param _s The mapping identifier
-//      * 
-//      * @author S&eacute;bastien Miqu&eacute;e
-//      */
-//     public void setIdAlgo( String _s ) throws RemoteException
-//     {
-//             System.err.println("############# SET ID ALGO ################# "+_s);
-//             idAlgo = _s ;
-//     }
-
        public class TransformThread extends Thread {
                int i;
                Node n;
        public class TransformThread extends Thread {
                int i;
                Node n;
@@ -1046,8 +1182,8 @@ public class JaceSpawner {
                                        System.err.println("The Super Node is maybe dead: " + e1) ;
                                        for (int z = 0; z < Register.Instance().getSize(); z++) {
                                                try {
                                        System.err.println("The Super Node is maybe dead: " + e1) ;
                                        for (int z = 0; z < Register.Instance().getSize(); z++) {
                                                try {
-                                                       Register.Instance().getNodeAt(z).getStub()
-                                                                       .reconnectSuperNode();
+                                                       Register.Instance().getNodeAt(z).getStub().suicide2("Problem") ;
+
                                                } catch (Exception ez) {
                                                        System.err.println("The reserved node was unable to reconnect to the super node: \n"
                                                                                        + ez);
                                                } catch (Exception ez) {
                                                        System.err.println("The reserved node was unable to reconnect to the super node: \n"
                                                                                        + ez);
@@ -1058,6 +1194,84 @@ public class JaceSpawner {
                        }
                }
        }
                        }
                }
        }
+       
+       
+       public class FaultMake extends Thread {
+
+               public FaultMake(){}
+
+               public void run()
+               {
+                       ListeTask t = null ;
+                       Random r = null ;
+                       int next, old = -1 ;
+                       
+                       System.out.println( "Starting fault tolerance !" ) ;
+
+                       while( ! RunningApplication.Instance().isRunning() )
+                       {
+                               /** Waiting some time the beginning of the computation **/
+                               try {
+                                       sleep( 1000 ) ;
+                               } catch (InterruptedException e) {                              
+                               }
+                       }
+
+                       while( RunningApplication.Instance().isRunning() )
+                       {
+                               /** Waiting some time ... **/
+                               try {
+                                       sleep( faultTime * 1000 ) ;
+                               } catch (InterruptedException e) {                              
+                               }
+
+                               /** ... and kill some daemons ! **/
+                               t = Register.Instance().getListeOfTasks();
+                               r = new Random() ;
+                               
+                               for( int i = 0 ; i < nbFault ; i++ )
+                               {
+                                       next = r.nextInt( t.getSize() ) ;
+               
+                                       while( next == old )
+                                       {
+                                               next = r.nextInt( t.getSize() ) ;
+                                       }
+                                       old = next ;
+                                       
+                                       Node noeud = null;
+                                       try {
+                                               TaskId recev = null;
+                                               System.out.println("Making fault on Task" + next);
+                                               
+                                               recev = t.getTaskIdOfRank( next );
+                                               
+                                               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) {
+                                               try {
+                                                       System.err.println("Error in FaultMake on node: "
+                                                                       + noeud.getName() + ". " + e);
+                                               } catch (Exception e2) {
+                                                       System.err.println("(Fault)Error in error:" + e2);
+                                               }
+                                       }
+                                       
+                                       try {
+                                               sleep( 500 ) ;
+                                       } catch (InterruptedException e) {                              
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       
 
        public class StartProcessThread extends Thread {
                int i;
 
        public class StartProcessThread extends Thread {
                int i;
@@ -1299,9 +1513,9 @@ public class JaceSpawner {
                                        // Register.Instance().getNode(workerIP).getWorkerStub().reconnectSuperNode();
 
                                        // stub.reconnectSuperNode();
                                        // Register.Instance().getNode(workerIP).getWorkerStub().reconnectSuperNode();
 
                                        // stub.reconnectSuperNode();
-                                       stub.suicide("fin d'appli");
+                                       stub.suicide("End of application");
                                } catch (Exception e) {
                                } catch (Exception e) {
-                                       System.err.println("can't kill node " + name);
+                                       System.err.println("Cannot kill node " + name);
                                }
                                yield();
                        }
                                }
                                yield();
                        }
@@ -1392,43 +1606,50 @@ public class JaceSpawner {
 
        }
 
 
        }
 
-       public Register getRegister(int rank) {
+       @SuppressWarnings("unchecked")
+       public synchronized Register getRegister( int rank ) {
 
                ListeTask listOfTasks = Register.Instance().getListeOfTasks();
 
                ListeTask listOfTasks = Register.Instance().getListeOfTasks();
-               Vector<Integer> dependencies = getDependencies(rank, listOfTasks.getSize());
+               Vector dependencies = getDependencies(rank, listOfTasks.getSize());
                Register g = new Register();
                ListeTask newListOfTasks = new ListeTask();
                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.setVersion(reg.getVersion());
                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()
                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()
-                                               .getNodeOfStub(id.getHostStub());
-                               g.addNode(noeud);
+                                               .getNodeOfName( id.getHostName() ) ;// (id.getHostStub());
+                               if( noeud != null )
+                                       g.addNode( noeud ) ;
+                               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();
        private void updateConcernedNodes(int rank, Node oldNode, Node node) {
                ListeTask listOfTasks = Register.Instance().getListeOfTasks();
-               Vector<?> dependencies = getDependencies(rank, listOfTasks.getSize());
-               System.out.println("la liste des voisins concernes de : " + rank);
+               Vector 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.println();
                // Register.Instance().setVersion(registerVersion);
                // registerVersion++;
                for (int z = 0; z < dependencies.size(); z++)
                        System.out.print(((Integer) dependencies.elementAt(z)).intValue()
                                        + " ");
                System.out.println();
                // Register.Instance().setVersion(registerVersion);
                // registerVersion++;
-               Register.Instance()
-                               .setSpawnerStub(Register.Instance().getSpawnerStub());
+//             Register.Instance()
+//                             .setSpawnerStub(Register.Instance().getSpawnerStub());
                int s;
                if ((dependencies.size() % nbOfDeamonsPerThread) == 0)
                        s = dependencies.size() / nbOfDeamonsPerThread;
                int s;
                if ((dependencies.size() % nbOfDeamonsPerThread) == 0)
                        s = dependencies.size() / nbOfDeamonsPerThread;
index 5515dc7..e210d88 100644 (file)
@@ -127,20 +127,26 @@ public class JaceSpawnerServer extends UnicastRemoteObject implements
                else
                        System.out.println("Node " + oldNode.getName() + " of rank " + rank
                                        + " hasn't been removed");
                else
                        System.out.println("Node " + oldNode.getName() + " of rank " + rank
                                        + " hasn't been removed");
-               Register.Instance().addNode(node);
+               
+               if( node != null )
+               {
+                       Register.Instance().addNode(node);
 
 
-               TaskId myTaskId = Register.Instance().getListeOfTasks()
+                       TaskId myTaskId = Register.Instance().getListeOfTasks()
                                .getTaskIdOfHostStub(oldNode.getStub());
 
                                .getTaskIdOfHostStub(oldNode.getStub());
 
-               myTaskId.setHostIP(node.getIP());
+                       myTaskId.setHostIP(node.getIP());
 
 
-               myTaskId.setHostName(node.getName());
-               myTaskId.setHostStub(node.getStub());
-               // Register.Instance().setVersion(Register.Instance().getVersion()+1);
-               RunningApplication.Instance().incrementNumberOfDisconnections();
-               System.out.println("Replacing node: " + oldNode.getName() + " with: "
+                       myTaskId.setHostName(node.getName());
+                       myTaskId.setHostStub(node.getStub());
+                       // Register.Instance().setVersion(Register.Instance().getVersion()+1);
+                       RunningApplication.Instance().incrementNumberOfDisconnections();
+                       System.out.println("Replacing node: " + oldNode.getName() + " with: "
                                + node.getName());
                                + node.getName());
-               // Register.Instance().getListeOfTasks().viewAll();
+                       // Register.Instance().getListeOfTasks().viewAll();
+               } else {
+                       System.err.println( "ReplaceDaemon: The new node is null!" ) ;
+               }
        }
 
 //     @Override
        }
 
 //     @Override
index 09b25b3..5392cf9 100644 (file)
@@ -7,7 +7,7 @@ public class JaceSuperNode {
        final int NB_HEART_DECONNECT = 3;
        // attribute
        private int heartTime; // frequency of heartBeat
        final int NB_HEART_DECONNECT = 3;
        // attribute
        private int heartTime; // frequency of heartBeat
-       private int port = 1098; // par la suite, donner par fichier de conf
+       private int port = 1099; // par la suite, donner par fichier de conf
        private int timeBeforeKill; // wait for 3 non response of heartBeat to kill
                                                                // the Daemon
        String protocol;
        private int timeBeforeKill; // wait for 3 non response of heartBeat to kill
                                                                // the Daemon
        String protocol;
@@ -29,6 +29,11 @@ public class JaceSuperNode {
                // create his list of SuperNode
                // containing the IPs and ports
                // but not already the stubs
                // create his list of SuperNode
                // containing the IPs and ports
                // but not already the stubs
+               if (System.getSecurityManager() == null) {
+            System.setSecurityManager(new SecurityManager());
+        }
+
+               
                SuperNodeListe.Instance().staticInitialization();
 
                HeartBeatSNode.Instance().setHeartTime(heartTime);
                SuperNodeListe.Instance().staticInitialization();
 
                HeartBeatSNode.Instance().setHeartTime(heartTime);
index e54e9b3..f3ef6bc 100644 (file)
@@ -31,7 +31,9 @@ public interface JaceSuperNodeInterface extends Remote {
 
 //     public Node getNewNode(String spawnerIP) throws RemoteException;
        
 
 //     public Node getNewNode(String spawnerIP) throws RemoteException;
        
-       public Node getNewNode(String spawnerIP, Node _deadNode) throws RemoteException;
+       public Node getNewNode( String _spawnerIP, int _rank ) throws RemoteException ;
+       
+       public Node getNewNode( String spawnerIP, GNode _deadNode ) throws RemoteException;
 
        public Vector<?> sendStub(String IP, int port, JaceSuperNodeInterface stub)
                        throws RemoteException;
 
        public Vector<?> sendStub(String IP, int port, JaceSuperNodeInterface stub)
                        throws RemoteException;
@@ -62,6 +64,13 @@ public interface JaceSuperNodeInterface extends Remote {
        public ArrayList<GNode> getGNodes() throws RemoteException ;
        
        public void removeAlgo( String _id, int _mode ) throws RemoteException ;
        public ArrayList<GNode> getGNodes() throws RemoteException ;
        
        public void removeAlgo( String _id, int _mode ) throws RemoteException ;
+       
+       public void setMapped( GNode _g, int _mode ) throws RemoteException ;
+       
+       public void removeMappedGNode( GNode _g, int _mode ) throws RemoteException ;
+       
+       // ** Tests ** //
+       public Algo getAlgo( String _spID ) throws RemoteException ;
 }
 
 /** ! **/
 }
 
 /** ! **/
index 5f74bbb..463887a 100644 (file)
@@ -7,14 +7,14 @@ import java.util.Vector;
 
 import and.Mapping.Algo;
 import and.Mapping.DefaultMapping;
 
 import and.Mapping.Algo;
 import and.Mapping.DefaultMapping;
+import and.Mapping.FT_AIAC_QM;
+import and.Mapping.FT_FEC;
 import and.Mapping.GNode;
 import and.Mapping.GTask;
 import and.Mapping.Graph;
 import and.Mapping.Grid;
 import and.Mapping.GNode;
 import and.Mapping.GTask;
 import and.Mapping.Graph;
 import and.Mapping.Grid;
-import and.Mapping.LSM;
-import and.Mapping.QM;
+import and.Mapping.Maheve;
 import and.Mapping.Simple;
 import and.Mapping.Simple;
-import and.Mapping.Utils;
 
 
 public class JaceSuperNodeServer extends UnicastRemoteObject implements
 
 
 public class JaceSuperNodeServer extends UnicastRemoteObject implements
@@ -25,9 +25,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        private int beat;
        private ArrayList<GNode> gnodes = null;
        private ArrayList<Algo> algos = null ;
        private int beat;
        private ArrayList<GNode> gnodes = null;
        private ArrayList<Algo> algos = null ;
-       private int count = 0 ;
        private boolean inDemand = false, operating = false, authorized = false ;
        private boolean inDemand = false, operating = false, authorized = false ;
-//     private boolean daemonListChange ;
        
        // Constructors
 
        
        // Constructors
 
@@ -36,7 +34,6 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                beat = timeBeat ;
                gnodes = new ArrayList<GNode>() ;
                algos = new ArrayList<Algo>() ;
                beat = timeBeat ;
                gnodes = new ArrayList<GNode>() ;
                algos = new ArrayList<Algo>() ;
-//             daemonListChange = true ;
        }
 
        public int getSuperNodeBeat() throws RemoteException {
        }
 
        public int getSuperNodeBeat() throws RemoteException {
@@ -128,24 +125,26 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                // Create the node
                Node noeud = new Node(workerStub);
                noeud.setName(workerName);
                // Create the node
                Node noeud = new Node(workerStub);
                noeud.setName(workerName);
-               noeud.setIP(workerIP);
+               noeud.setIP(g.getIP());
                noeud.setAliveFlag(true);
                noeud.setAliveTime();
                noeud.setPort(port);
                noeud.setAppliName(null);
                noeud.setNbOfBeats(0);
                noeud.setAliveFlag(true);
                noeud.setAliveTime();
                noeud.setPort(port);
                noeud.setAppliName(null);
                noeud.setNbOfBeats(0);
-               noeud.setId( count ) ;
-               noeud.setId( Long.parseLong( workerIP.replace( ".", "" ) ) ) ;
+               
+               String sid = workerIP.replace( ".", "" ) + port ;
+               Long id = Long.parseLong( sid ) ;
+               noeud.setId( id ) ;
 
                g.setNode( noeud ) ;
 
                g.setNode( noeud ) ;
-               g.setId( noeud.getId() ) ;
+               g.setId( id ) ;
                g.setMapped( false ) ;
                
                workingOnGnodes() ;
                
                gnodes.add( g ) ;
                g.setMapped( false ) ;
                
                workingOnGnodes() ;
                
                gnodes.add( g ) ;
+               updateGrids( g ) ;
                
                
-//             daemonListChange = true ;
 
                // Insert the node in the Register.Instance() of the Super Node
                Register.Instance().addNode(noeud);
 
                // Insert the node in the Register.Instance() of the Super Node
                Register.Instance().addNode(noeud);
@@ -169,6 +168,25 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                operating = false ;
        }
 
                operating = false ;
        }
 
+       
+       /**
+        * Update all mapping algorithms with a new node.
+        * @param _g The new node
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
+       private synchronized void updateGrids( GNode _g )
+       {
+               if( _g != null )
+               {
+                       for( int i = 0 ; i < algos.size() ; i++ )
+                       {
+                               algos.get( i ).getGrid().addGNode( _g ) ;
+                       }
+               }
+               
+       }
+
        /****************************************************/
        /****************************************************/
 
        /****************************************************/
        /****************************************************/
 
@@ -217,7 +235,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * @author S&eacute;bastien Miqu&eacute;e        
         */
        @Override
         * @author S&eacute;bastien Miqu&eacute;e        
         */
        @Override
-       public Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
+       public synchronized Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
                        int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
 
                // Have we the correct application ?
                        int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
 
                // Have we the correct application ?
@@ -239,8 +257,12 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                workingOnGnodes() ;
                
                /** Initialization of Grid architecture (G5K for now) **/
                workingOnGnodes() ;
                
                /** Initialization of Grid architecture (G5K for now) **/
-               Grid grid = Utils.createGridG5k(gnodes);
-//             grid.initClusters();
+               Grid grid = new Grid() ;
+
+               for( int i = 0 ; i < gnodes.size() ; i++ )
+               {
+                       grid.addGNode( gnodes.get( i ) ) ;
+               }
                
                
                /** Informing about the grid heterogeneity **/
                
                
                /** Informing about the grid heterogeneity **/
@@ -276,19 +298,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        graph.addGTask(ts.get(i));
                }
 
                        graph.addGTask(ts.get(i));
                }
 
-               // -- debug !
-               // graph.print() ;
-
-               // try {
-               // Thread.sleep(10000) ;
-               // } catch( Exception e ) {}
-
-               // grid.print() ;
-               // 
-               // try {
-               // Thread.sleep( 10000 ) ;
-               // } catch( Exception e ) {}
-
+               /** TODO Loading algorithm class with parameters in a configuration file **/
                /** Selection of the mapping algorithm **/
                Algo al = null ;
 
                /** Selection of the mapping algorithm **/
                Algo al = null ;
 
@@ -297,11 +307,14 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        al = new Simple(graph, grid);
                        break;
                case 1:
                        al = new Simple(graph, grid);
                        break;
                case 1:
-                       al = new QM(graph, grid, paramAlgo);
+                       al = new FT_AIAC_QM(graph, grid, paramAlgo);
                        break;
                case 2:
                        break;
                case 2:
-                       al = new LSM(graph, grid, paramAlgo);
+                       al = new FT_FEC(graph, grid, paramAlgo);
                        break;
                        break;
+               case 3:
+                       al = new Maheve( graph, grid ) ;
+                       break ;
                default:
                        al = new DefaultMapping( graph, grid, gnodes ) ;
                }
                default:
                        al = new DefaultMapping( graph, grid, gnodes ) ;
                }
@@ -314,14 +327,31 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
 
                        /** Creating the register **/
                        ArrayList<GNode> ag = al.getMapping().getMappedGNodes();
 
                        /** Creating the register **/
                        ArrayList<GNode> ag = al.getMapping().getMappedGNodes();
+                       
+                       System.out.println("NB returned nodes : "+ag.size());
 
 
+                       
+                       /** Setting the algorithm's identifier **/
+                       al.setIdS( spawnerIP ) ;
+                       
+                       /** Adding the algorithm in the list **/
+                       algos.add( al ) ;
+                       
+                       int idAlgo = searchAlgo( spawnerIP ) ;
+                       
+                       /** Mapping distribution over other SuperNodes */
+                       SuperNodeListe.Instance().setMapping( al ) ;
+                       
+                       
+                       
                        authorized = true ;
                        
                        for( int i = 0; i < ag.size(); i++ ) {
                                reg.addNode((Node) ag.get(i).getNode());
                        authorized = true ;
                        
                        for( int i = 0; i < ag.size(); i++ ) {
                                reg.addNode((Node) ag.get(i).getNode());
-                               delGNodeFromList( (Node) ag.get(i).getNode(), 2, spawnerIP ) ;
-//                             gnodes.remove(ag.get(i));
-//                             Register.Instance().removeNode((Node) ag.get(i).getNode());
+                               
+                               ag.get(i).setMapped( true ) ;
+                               setMapped( ag.get(i), 1 ) ;
+                               Register.Instance().removeNode((Node) ag.get(i).getNode());
                        }
                        
                        
                        }
                        
                        
@@ -333,9 +363,11 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                                
                                for( int i = 0 ; i < nb ; i ++ )
                                {
                                
                                for( int i = 0 ; i < nb ; i ++ )
                                {
-                                       sup = al.getOtherGNode( gnodes ) ;
+                                       sup = algos.get(idAlgo).getOtherGNode( gnodes ) ;
+                                       algos.get(idAlgo).getMapping().addOtherNode( sup ) ;
                                        reg.addNodeBeg( (Node) sup.getNode() ) ;
                                        reg.addNodeBeg( (Node) sup.getNode() ) ;
-                                       delGNodeFromList( (Node) sup.getNode(), 2, spawnerIP ) ;
+                                       setMapped( sup, 1 ) ;
+                                       Register.Instance().removeNode((Node) sup.getNode());
                                }
                        }
                        
                                }
                        }
                        
@@ -344,20 +376,9 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        if (ag.size() != 0) {
                                SuperNodeListe.Instance().forwardCountNode();
                        }
                        if (ag.size() != 0) {
                                SuperNodeListe.Instance().forwardCountNode();
                        }
-                       
-                       /** Setting the algorithm's identifier **/
-                       al.setIdS( spawnerIP ) ;
-                       
-                       /** Adding the algorithm in the list **/
-                       algos.add( al ) ;
 
                } 
                
 
                } 
                
-//             System.out.println( "Spawner returned reg: " + reg ) ;
-               
-               /** Mapping distribution over other SuperNodes */
-               SuperNodeListe.Instance().setMapping( al ) ;
-               
                operating = false ;
                
                /** Returning result **/
                operating = false ;
                
                /** Returning result **/
@@ -365,6 +386,39 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        }
 
        
        }
 
        
+       public synchronized void setMapped( GNode _g, int _mode ) throws RemoteException 
+       {
+               if( _g != null )
+               {
+                       _g.setMapped( true ) ;
+                       
+                       for( int i = 0 ; i < gnodes.size() ; i++ )
+                       {
+                               if( _g.getId() == gnodes.get( i ).getId() )
+                               {
+                                       gnodes.remove( i ) ;
+                                       break ;
+                               }
+                       }
+                       
+                       for( int i = 0 ; i < algos.size() ; i++ )
+                       {
+                               algos.get( i ).getGrid().setMappedStatus( _g, true ) ;
+                       }
+                       
+                       if( _mode == 1 )
+                       {
+                               authorized = true ;
+                       
+                               SuperNodeListe.Instance().setMappedGNode( _g, 0 ) ;
+                       
+                               authorized = false ;
+                       }
+               } else {
+                       System.err.println( "GNode is null is setMapped!" ) ;
+               }
+       }
+
        /**
         * Suppress a node from the gnodes list if this node is free, or remove
         * it from the Mapping class of the mapping algorithm if this node is
        /**
         * Suppress a node from the gnodes list if this node is free, or remove
         * it from the Mapping class of the mapping algorithm if this node is
@@ -376,7 +430,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * @author S&eacute;bastien Miqu&eacute;e        
         */
        @Override
         * @author S&eacute;bastien Miqu&eacute;e        
         */
        @Override
-       public GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
+       public synchronized GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
        {
                GNode removedGNode = null ;
                
        {
                GNode removedGNode = null ;
                
@@ -389,59 +443,33 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                                workingOnGnodes() ;
                                free = true ;
                        }
                                workingOnGnodes() ;
                                free = true ;
                        }
-                       
-                       /** The dead node is not in the mapping **/
-                       if( _mode == 0 || _mode == 2)
+
+                       if( _mode == 0 )
                        {
                        {
+                               GNode dead = null ;
+                               
                                for( int i = 0 ; i < gnodes.size() ; i++ )
                                {
                                for( int i = 0 ; i < gnodes.size() ; i++ )
                                {
-                                       if( ((Node)gnodes.get(i).getNode()).getId() == _n.getId() ) 
+                                       if( _n.getId() == ((Node) gnodes.get(i).getNode()).getId() )
                                        {
                                        {
-                                               removedGNode = gnodes.remove( i ) ;
-                                               Register.Instance().removeNodeOfName( removedGNode.getName() ) ;
+                                               dead = gnodes.remove( i ) ;
                                                break ;
                                        }
                                }
                                                break ;
                                        }
                                }
-                       }
-                       
-                       /** The dead node is in the mapping **/
-                       if( _mode == 1 )
-                       {
-                               /** Searching the algorithm **/ 
-                               int idAlgo = searchAlgo( _spawnerIp ) ;
                                
                                
-                               if( idAlgo == -1 )
+                               if( dead != null )
                                {
                                {
-                                       System.err.println( "No algorithm found for this Spawner!" ) ;
-                                       return null ;
-                               }
-                               
-                               ArrayList<GNode> temp = algos.get( idAlgo ).getMapping().getMappedGNodes() ;
-                               
-                               for( int i = 0 ; i < temp.size() ; i++ )
-                               {
-                                       if( ((Node)temp.get(i).getNode()).getId() == _n.getId() ) 
+                                       for( int i = 0 ; i < algos.size() ; i++ )
                                        {
                                        {
-                                               removedGNode = temp.get( i ) ;
-                                               Register.Instance().removeNodeOfName( removedGNode.getName() ) ;
-                                               break ;
+                                               algos.get( i ).getGrid().removeGNode( dead ) ;
+                                               Register.Instance().removeNodeOfName( dead.getName() ) ;
+                                               SuperNodeListe.Instance().removeGNode( dead, _mode, _spawnerIp ) ;
                                        }
                                        }
-                               }       
-                       }
-                       
-                       /** Removing the dead node from the Grid **/
-                       if( _mode == 0 || _mode == 1 ) {
-                               int idAlgo = searchAlgo( _spawnerIp ) ;
-                               
-                               if( idAlgo != -1 && _mode == 1 )
-                               {
-                                       algos.get( idAlgo ).getGrid().removeGNode( removedGNode ) ;
+                               } else {
+                                       System.err.println( "The dead node signaled does not exist!" ) ;
                                }
                        }
                        
                                }
                        }
                        
-                       /** Propagation of the deletion **/
-                       SuperNodeListe.Instance().removeGNode( removedGNode, _mode, _spawnerIp ) ;
-                       
                        if( free )
                        {
                                operating = false ;
                        if( free )
                        {
                                operating = false ;
@@ -481,7 +509,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * 
         * @author S&eacute;bastien Miqu&eacute;e        
         */
         * 
         * @author S&eacute;bastien Miqu&eacute;e        
         */
-       private void workingOnGnodes()
+       private synchronized void workingOnGnodes()
        {
                boolean tmp = true ;    
                
        {
                boolean tmp = true ;    
                
@@ -511,6 +539,58 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                
                inDemand = false ;
        }
                
                inDemand = false ;
        }
+       
+       /**
+        * Search and return a new node when one failed or when JaceP2P needs another
+        * one. For the first case, the given failed node should not be null, and
+        * null in the other case.
+        * @param _spawnerIP IP of the requester
+        * @param _rank The task number number of the dead node
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
+       @Override
+       public synchronized Node getNewNode( String _spawnerIP, int _rank ) throws RemoteException
+       {
+               int idNode = -1 ;
+               int idAlgo = searchAlgo( _spawnerIP ) ;
+               
+               if( idAlgo == -1 )
+               {
+                       System.err.println( "No algorithm found for this Spawner!" ) ;
+                       return null ;
+               }
+               
+               /** We have to replace a Spawner **/
+               if( _rank == -2 )
+               {
+                       idNode = -2 ;
+               } else {
+               /** We have to replace a computing node **/
+                       idNode = algos.get( idAlgo ).getMapping().getIdOfAssociation( _rank ) ;
+               }
+               
+               if( idNode == -1 )
+               {
+                       System.err.println( "No tasks corresponds to rank "+_rank+"!" ) ;
+                       return null ;
+               }
+               
+               GNode dead = null ;
+               
+               if( idNode >= 0 ) 
+               {
+                       dead = algos.get( idAlgo ).getMapping().getAssociation( idNode ).getGNode() ;
+               }
+               
+               if( dead == null && idNode >= 0 )
+               {
+                       System.err.println( "The GNode corresponding to the task "+_rank+" is null!" ) ;
+                       System.err.println( "Trying to find a new node for this task (not optimal)..." ) ;
+               }
+               
+               return getNewNode( _spawnerIP, dead ) ;
+       }
 
        /**
         * Search and return a new node when one failed or when JaceP2P needs another
 
        /**
         * Search and return a new node when one failed or when JaceP2P needs another
@@ -522,10 +602,10 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * @author S&eacute;bastien Miqu&eacute;e
         */
        @Override
         * @author S&eacute;bastien Miqu&eacute;e
         */
        @Override
-       public Node getNewNode( String _spawnerIP, Node _deadNode ) throws RemoteException
+       public synchronized Node getNewNode( String _spawnerIP, GNode _deadNode ) throws RemoteException
        {
                Node node = null ;
        {
                Node node = null ;
-               GNode remp = null, gnode = null ;
+               GNode remp = null ;
 
                int idAlgo = searchAlgo( _spawnerIP ) ;
                
 
                int idAlgo = searchAlgo( _spawnerIP ) ;
                
@@ -535,24 +615,35 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        return null ;
                }
                
                        return null ;
                }
                
+               
                /** Can we use gnodes ?**/
                workingOnGnodes() ;
                
                /** Can we use gnodes ?**/
                workingOnGnodes() ;
                
-               if( _deadNode != null )
+               if( _deadNode != null )         
                {
                        authorized = true ;
                        
                {
                        authorized = true ;
                        
-                       gnode = delGNodeFromList( _deadNode, 1, _spawnerIP ) ;
+                       removeMappedGNode( _deadNode, 1 ) ;
+                       
+                       authorized = false ;
 
 
-                       remp = algos.get( idAlgo ).replaceNode( gnode, gnodes ) ;
+                       remp = algos.get( idAlgo ).replaceNode( _deadNode, gnodes ) ;
                
                        if( remp != null )
                        {
                                System.out.println( "Replacing node found." ) ;
                                
                
                        if( remp != null )
                        {
                                System.out.println( "Replacing node found." ) ;
                                
+                               authorized = true ;
+                               
                                remp.setMapped( true ) ;
                                
                                remp.setMapped( true ) ;
                                
-                               delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ;
+                               setMapped( remp, 1 ) ;
+                               Register.Instance().removeNodeOfName( remp.getName() ) ;
+                               
+                               
+                               /** Updating all mapping **/
+                               updateMappedNode( _deadNode, remp, _spawnerIP ) ;
+                               propagateReplaceNode( _deadNode, remp, _spawnerIP ) ;
                                
                                authorized = false ;
                                
                                
                                authorized = false ;
                                
@@ -571,7 +662,8 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                                
                                authorized = true ;
                                
                                
                                authorized = true ;
                                
-                               delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ;
+                               setMapped( remp, 1 ) ;
+                               Register.Instance().removeNodeOfName( remp.getName() ) ;
                                
                                authorized = false ;
                                
                                
                                authorized = false ;
                                
@@ -584,14 +676,11 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                if( remp != null )
                {
                        node = (Node) remp.getNode() ;
                if( remp != null )
                {
                        node = (Node) remp.getNode() ;
+               } else {
+                       System.err.println( "SuperNode: No new node found!" ) ;
                }
                
                
                }
                
                
-               /** Updating all mapping **/
-               updateMappedNode( gnode, remp, _spawnerIP ) ;
-               propagateReplaceNode( gnode, remp, _spawnerIP ) ;
-               
-               
                /** Free the gnodes use **/
                operating = false ;
                
                /** Free the gnodes use **/
                operating = false ;
                
@@ -599,6 +688,24 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        }
        
        
        }
        
        
+       public synchronized void removeMappedGNode( GNode _g, int _mode ) throws RemoteException
+       {
+               if( _g != null )
+               {
+                       for( int i = 0 ; i < algos.size() ; i++ )
+                       {
+                               algos.get( i ).getGrid().removeGNode( _g ) ;
+                       }
+                       
+                       if( _mode == 1 )
+                       {
+                               SuperNodeListe.Instance().removeGNode( _g, 0 ) ;
+                       }
+               } else {
+                       System.err.println( "GNode to be deleted is null!" ) ;
+               }
+       }
+       
        /**
         * Replace a failed GNode in the mapping by another one.
         * This method is called by the SuperNodeList, to broadcast the modification.
        /**
         * Replace a failed GNode in the mapping by another one.
         * This method is called by the SuperNodeList, to broadcast the modification.
@@ -608,7 +715,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * @author S&eacute;bastien Miqu&eacute;e
         */
        @Override
         * @author S&eacute;bastien Miqu&eacute;e
         */
        @Override
-       public void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP ) 
+       public synchronized void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP ) 
        {
                if( _remp != null )
                {
        {
                if( _remp != null )
                {
@@ -627,18 +734,19 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        if( pos != -1 )
                        {
                                /** Changing the node in the mapping **/
                        if( pos != -1 )
                        {
                                /** Changing the node in the mapping **/
-                               algos.get( idAlgo ).getMapping().getMapping().get( pos ).setGNode( _remp ) ;
-                               
-                               System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
-                       }               
+                               if( algos.get( idAlgo ).getMapping().getMapping().get( pos ).setGNode( _remp ) )
+                               {
+                                       System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
+                               } else {
+                                       System.err.println( "Failed in replacing the fallen node in the mapping!" ) ;
+                               }
+                       } else {
+                               System.err.println( "The dead node was not found in the mapping!" ) ;
+                       }
                        
                        
-                       /** Changing the status in the grid **/
-                       algos.get( idAlgo ).getGrid().setMappedStatus( _remp, true ) ;
-               
-                       algos.get( idAlgo ).updateGrid() ;
                } else {
                        System.err.println( "The new GNode is null!" ) ;
                } else {
                        System.err.println( "The new GNode is null!" ) ;
-               }
+               }       
        }
 
        
        }
 
        
@@ -649,11 +757,13 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * 
         * @author S&eacute;bastien Miqu&eacute;e        
         */
         * 
         * @author S&eacute;bastien Miqu&eacute;e        
         */
-       private void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
+       private synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
        {
                if( _remp != null )
                {       
                        SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp, _spawnerIP ) ;
        {
                if( _remp != null )
                {       
                        SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp, _spawnerIP ) ;
+               } else {
+                       System.err.println( "The replacement node is null!" ) ;
                }
        }
 
                }
        }
 
@@ -682,42 +792,14 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        
                        gnodes.add( _g ) ;
                        
                        
                        gnodes.add( _g ) ;
                        
+                       updateGrids( _g ) ;
+                       
                        if( free )
                                operating = false ;
                }
        }
        
 
                        if( free )
                                operating = false ;
                }
        }
        
 
-//     @Override
-//     public void removeGNode( GNode _g ) throws RemoteException 
-//     {
-//             if( _g != null )
-//             {
-//                     boolean free = false ;
-//                     
-//                     if( ! operating )
-//                     {
-//                             workingOnGnodes() ;
-//                             free = true ;
-//                     }
-//                     
-//                     for( int i = 0 ; i < gnodes.size() ; i++ )
-//                     {
-//                             if( ((Node)gnodes.get(i).getNode()).getId() == ((Node)_g.getNode()).getId() ) 
-//                             {
-//                                     gnodes.remove( i ) ;
-//                                     Register.Instance().removeNodeOfName( _g.getName() ) ;
-//                                     break ;
-//                             }
-//                     }
-//                     
-//                     if( free )
-//                             operating = false ;
-//             }
-//             
-//     }
-       
-
        /**
         * Set the local mapping with another done on an other SuperNode.
         * @param _al The new mapping
        /**
         * Set the local mapping with another done on an other SuperNode.
         * @param _al The new mapping
@@ -725,10 +807,14 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * @author S&eacute;bastien Miqu&eacute;e
         */
        @Override
         * @author S&eacute;bastien Miqu&eacute;e
         */
        @Override
-       public void setMapping( Algo _al ) throws RemoteException 
+       public synchronized void setMapping( Algo _al ) throws RemoteException 
        {
                if( searchAlgo( _al.getIdS() ) == -1 )
        {
                if( searchAlgo( _al.getIdS() ) == -1 )
-                       algos.add( _al ) ;                      
+               {
+                       algos.add( _al ) ;
+               } else {
+                       System.err.println( "I already have this mapping algorithm!" ) ;
+               }
        }
 
        
        }
 
        
@@ -781,21 +867,41 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         */
        public void removeAlgo( String _id, int _mode ) throws RemoteException
        {
         */
        public void removeAlgo( String _id, int _mode ) throws RemoteException
        {
-               int i ;
+               int pos ;
                
                
-               i = searchAlgo( _id ) ;
+               pos = searchAlgo( _id ) ;
                
                
-               if( i != -1 )
+               if( pos != -1 )
                {
                {
-                       algos.remove( i ) ;
+                       algos.remove( pos ) ;
                        
                        if( _mode == 0 )
                        {
                                SuperNodeListe.Instance().removeAlgo( _id ) ;
                        }
                        
                        if( _mode == 0 )
                        {
                                SuperNodeListe.Instance().removeAlgo( _id ) ;
                        }
+               } else {
+                       System.err.println( "The mapping algorithm requested for deletion does not exist!" ) ;
                }
        }
        
                }
        }
        
+       
+       // ** Tests ** //
+       public Algo getAlgo( String _spID ) throws RemoteException
+       {
+               int pos ;
+               Algo ret = null ;
+               
+               pos = searchAlgo( _spID ) ;
+               
+               if( pos != -1 )
+               {
+                       ret = algos.get( pos ) ;
+               }
+               
+               return ret ;
+       }
+       
+       
 }
 
 /** ! **/
 }
 
 /** ! **/
index fdc76ad..701b123 100644 (file)
@@ -2,17 +2,16 @@ package jaceP2P;
 
 import java.util.Vector;
 
 
 import java.util.Vector;
 
-public class ListeTask implements java.io.Serializable, java.lang.Cloneable {
-
-       private static final long serialVersionUID = 1L;
+public class ListeTask implements java.io.Serializable, java.lang.Cloneable 
+{
+       private static final long serialVersionUID = 1L ;
 
        // attributes
 
        // attributes
-       protected Vector<TaskId> liste = new Vector<TaskId>();
-       protected TaskId task;
+       protected Vector<TaskId> liste = new Vector<TaskId>() ;
+       protected TaskId task ;
 
        // constructor
 
        // constructor
-       public ListeTask() {
-       };
+       public ListeTask() {} 
 
        @SuppressWarnings("unchecked")
        public synchronized ListeTask clone() {
 
        @SuppressWarnings("unchecked")
        public synchronized ListeTask clone() {
index 89dc107..79716f2 100644 (file)
@@ -74,10 +74,12 @@ public class LocalHost {
        }
 
        public synchronized void setStub(JaceInterface stub) {
        }
 
        public synchronized void setStub(JaceInterface stub) {
+               ref = null ;
                ref = stub;
        }
 
        public synchronized void setSuperNodeStub(JaceSuperNodeInterface stub) {
                ref = stub;
        }
 
        public synchronized void setSuperNodeStub(JaceSuperNodeInterface stub) {
+               refSuperNode = null ;
                refSuperNode = stub;
        }
 
                refSuperNode = stub;
        }
 
@@ -86,6 +88,7 @@ public class LocalHost {
        }
 
        public synchronized void setSuperNodeIP(String IP) {
        }
 
        public synchronized void setSuperNodeIP(String IP) {
+               superNodeIP = null ;
                superNodeIP = IP;
        }
 
                superNodeIP = IP;
        }
 
index 680c05d..1c4fdb6 100644 (file)
@@ -62,26 +62,26 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
         * public void setVersion(int version){ this.version=version; }
         */
 
         * public void setVersion(int version){ this.version=version; }
         */
 
-       public synchronized void addNode(Node host) {
-               int is = -1;
-               if (host == null) {
-                       System.err
-                                       .println("In Register.addNode : host.getIP() == null !");
+       public synchronized int addNode( Node host ) 
+       {
+               int is = -1 ;
+               if( host == null ) 
+               {
+                       System.err.println( "In Register.addNode : host == null !" ) ;
+                       return 1 ;
                }
                }
-               is = existNodeOfStub(host.getStub());
+               
+               is = existNodeOfStub( host.getStub() ) ;
+               
                if (is != -1) {
                        System.out.println("This node exists yet, I replace it");
                if (is != -1) {
                        System.out.println("This node exists yet, I replace it");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
-                       // System.out.println("MERDE !!");
+
                        liste.setElementAt(host, is);
                } else {
                        liste.add(host);
                }
                        liste.setElementAt(host, is);
                } else {
                        liste.add(host);
                }
+               
+               return 0 ;
        }
 
        /**
        }
 
        /**
@@ -180,24 +180,28 @@ public class Register implements java.io.Serializable, java.lang.Cloneable {
        }
 
        public synchronized boolean removeNode(Node n) {
        }
 
        public synchronized boolean removeNode(Node n) {
-               return (liste.remove(n));
+               return ( liste.remove( n ) ) ;
        }
 
        }
 
-       public synchronized boolean removeNodeOfName(String s) {
-               boolean removed = false;
-               int i = 0;
+       public synchronized boolean removeNodeOfName( String s ) 
+       {
+               boolean removed = false ;
+               int i = 0 ;
                // System.out.println("begin remove");
                // viewAll();
                // System.out.println("begin remove");
                // viewAll();
-               while (i < liste.size() && !removed) {
+               while( i < liste.size() && ! removed ) 
+               {
                        // System.out.println("i="+i+" s="+s);
                        // System.out.println("i="+i+" s="+s);
-                       if (((Node) liste.get(i)).getName().equals(s)) {
-                               liste.remove(i);
-                               removed = true;
-                       } else
-                               i++;
+                       if( ((Node) liste.get(i)).getName().equals(s) ) 
+                       {
+                               liste.remove( i ) ;
+                               removed = true ;
+                       } else {
+                               i++ ;
+                       }
                }
                // System.out.println("end remove");
                }
                // System.out.println("end remove");
-               return removed;
+               return removed ;
        }
 
        public synchronized int getSize() {
        }
 
        public synchronized int getSize() {
index f7aa36c..f11667c 100644 (file)
@@ -58,7 +58,7 @@ public class ScanThread extends Thread {
                }
        }
 
                }
        }
 
-       @SuppressWarnings("static-access")
+//     @SuppressWarnings("static-access")
        public void testNeighbor() {
                Node host;
                //Node tmpNode;
        public void testNeighbor() {
                Node host;
                //Node tmpNode;
@@ -110,7 +110,7 @@ public class ScanThread extends Thread {
                                                } else {
                                                        dead = true;
                                                        //changed = true;
                                                } else {
                                                        dead = true;
                                                        //changed = true;
-                                                       host.getStub().suicide("Not responding");
+                                                       host.getStub().suicide2("Not responding");
                                                        System.out.println("\n\nNot responding node "
                                                                        + host.getName() + " (" + host.getIP()
                                                                        + ")      size : "
                                                        System.out.println("\n\nNot responding node "
                                                                        + host.getName() + " (" + host.getIP()
                                                                        + ")      size : "
@@ -135,7 +135,7 @@ public class ScanThread extends Thread {
                                                try {
                                                        spawnerStub.signalDeadNode(jaceStub, neighborRank);
 
                                                try {
                                                        spawnerStub.signalDeadNode(jaceStub, neighborRank);
 
-                                                       this.sleep(10 * beat);
+                                                       Thread.sleep(10 * beat);
 
                                                } catch (RemoteException e1) {
                                                        System.err.println("Couldn't reach the spawner: "
 
                                                } catch (RemoteException e1) {
                                                        System.err.println("Couldn't reach the spawner: "
index b207bba..8d9484f 100644 (file)
@@ -62,7 +62,7 @@ public class SuperNodeListe implements Cloneable {
                        BufferedReader br = new BufferedReader(ipsr);
 
                        while ((adr = br.readLine()) != null) {
                        BufferedReader br = new BufferedReader(ipsr);
 
                        while ((adr = br.readLine()) != null) {
-                               liste.add(new SuperNodeData(adr, 1098));
+                               liste.add(new SuperNodeData(adr, 1099));
                        }
 
                        br.close();
                        }
 
                        br.close();
@@ -81,9 +81,9 @@ public class SuperNodeListe implements Cloneable {
 
                // String adr3="193.52.61.140";
                // System.out.println("adr3 = " + adr3);
 
                // String adr3="193.52.61.140";
                // System.out.println("adr3 = " + adr3);
-               // liste.add(new SuperNodeData(adr1, 1098));
-               // liste.add(new SuperNodeData(adr2, 1098));
-               // liste.add(new SuperNodeData(adr3, 1098));
+               // liste.add(new SuperNodeData(adr1, 1099));
+               // liste.add(new SuperNodeData(adr2, 1099));
+               // liste.add(new SuperNodeData(adr3, 1099));
        }
 
        public void fileInitialization(String fileName) {
        }
 
        public void fileInitialization(String fileName) {
@@ -344,7 +344,7 @@ public class SuperNodeListe implements Cloneable {
        /*********** Sébastien Miquée ***********/
        /****************************************/
        
        /*********** Sébastien Miquée ***********/
        /****************************************/
        
-       public void addGNode( GNode _g )
+       public synchronized void addGNode( GNode _g )
        {
                if( _g != null )
                {
        {
                if( _g != null )
                {
@@ -369,7 +369,7 @@ public class SuperNodeListe implements Cloneable {
                }
        }
 
                }
        }
 
-       public void removeGNode( GNode _g, int _mode, String _spawnerIP  )
+       public synchronized void removeGNode( GNode _g, int _mode, String _spawnerIP  )
        {
                if( _g != null )
                {
        {
                if( _g != null )
                {
@@ -394,6 +394,56 @@ public class SuperNodeListe implements Cloneable {
                }
        }
        
                }
        }
        
+       public synchronized void removeGNode( GNode _g, int _mode  )
+       {
+               if( _g != null )
+               {
+                       
+                       SuperNodeData d = null ;
+                       JaceSuperNodeInterface remoteStub = null ;
+
+                       for( int i = 0 ; i < liste.size() ; i++ ) 
+                       {
+                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
+                               {
+                                       // if not me, I inform the other super nodes
+                                       remoteStub = d.getStub() ;
+                                       try {
+                                               remoteStub.removeMappedGNode( _g, _mode ) ;
+                                       } catch( Exception e ) {
+                                               System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       public synchronized void setMappedGNode( GNode _g, int _mode )
+       {
+               if( _g != null )
+               {
+                       
+                       SuperNodeData d = null ;
+                       JaceSuperNodeInterface remoteStub = null ;
+
+                       for( int i = 0 ; i < liste.size() ; i++ ) 
+                       {
+                               d = (SuperNodeData) liste.elementAt( i ) ;
+                               if( ! d.getIP().equals(LocalHost.Instance().getIP() ) ) 
+                               {
+                                       // if not me, I inform the other super nodes
+                                       remoteStub = d.getStub() ;
+                                       try {
+                                               remoteStub.setMapped( _g, _mode ) ; 
+                                       } catch( Exception e ) {
+                                               System.err.println( "Unable to set mapped GNode on SuperNode " + d.getIP() ) ;
+                                       }
+                               }
+                       }
+               }
+       }
+       
        
        protected boolean workingOnGnodes()
        {
        
        protected boolean workingOnGnodes()
        {
@@ -444,7 +494,7 @@ public class SuperNodeListe implements Cloneable {
                }
        }
 
                }
        }
 
-       public void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) 
+       public synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) 
        {
                if( _dead != null && _remp != null )
                {
        {
                if( _dead != null && _remp != null )
                {
index 7dfd861..ffad2e9 100644 (file)
@@ -3,6 +3,7 @@ package jaceP2P;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.rmi.ConnectException;
 import java.rmi.RemoteException;
 import java.util.Vector;
 
 import java.rmi.RemoteException;
 import java.util.Vector;
 
@@ -56,7 +57,8 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
        public Task sauv;
        public BackupConvg sauvConvg = new BackupConvg();
        public boolean postReloading = false;
        public Task sauv;
        public BackupConvg sauvConvg = new BackupConvg();
        public boolean postReloading = false;
-       public Vector<?> reduceAll;
+       @SuppressWarnings("unchecked")
+       public Vector reduceAll;
 
        int cpt = 0;
        int count = 0;
 
        int cpt = 0;
        int count = 0;
@@ -319,9 +321,13 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                                                // else
                                                // SenderSocket.Instance().getBuffer().add(msg);
                                        }
                                                // else
                                                // SenderSocket.Instance().getBuffer().add(msg);
                                        }
+                                       
+                               } catch( ConnectException ce ) {
+                                       recev.getHostStub().suicide2( "Not responding!" ) ;
                                } catch (Exception e) {
                                        System.err.println("Unable to send data message to " + dest
                                                        + ": " + e);
                                } catch (Exception e) {
                                        System.err.println("Unable to send data message to " + dest
                                                        + ": " + e);
+//                                     recev.getHostStub().suicide2( "Not responding!" ) ;
                                }
                                // System.out.println("TASK : g mis un msg qui doit etre envoye");
                                // envoie toujours asynchrone !!!!!!!! : le Message partira
                                }
                                // System.out.println("TASK : g mis un msg qui doit etre envoye");
                                // envoie toujours asynchrone !!!!!!!! : le Message partira
@@ -397,7 +403,7 @@ public class Task implements Runnable, Cloneable, java.io.Serializable {
                                // + ")   taille MsgQueue : " + MsgQueue.Instance().getSize());
                        } catch (Exception e) {
                                if (Register.Instance().getListeOfTasks() == null)
                                // + ")   taille MsgQueue : " + MsgQueue.Instance().getSize());
                        } catch (Exception e) {
                                if (Register.Instance().getListeOfTasks() == null)
-                                       System.err.println("Tasks list is null: " + e);
+                                       System.err.println("Tasks list is null2: " + e);
                        }
                        try {
                                JaceSession.Instance().getTaskThread().sleep(10);
                        }
                        try {
                                JaceSession.Instance().getTaskThread().sleep(10);
index b230110..cb0728d 100644 (file)
@@ -22,25 +22,25 @@ public class TaskId implements java.io.Serializable {
                this.hostStub = s;
        }
 
                this.hostStub = s;
        }
 
-       public void setAppliName(String nom) {
+       public synchronized void setAppliName(String nom) {
                this.appliName = nom;
        }
 
        // TODO a virer et laisser que le hostStub
                this.appliName = nom;
        }
 
        // TODO a virer et laisser que le hostStub
-       public void setHostIP(String nom) {
+       public synchronized void setHostIP(String nom) {
                this.hostIP = nom;
        }
 
        // TODO a virer et laisser que le hostStub
                this.hostIP = nom;
        }
 
        // TODO a virer et laisser que le hostStub
-       public void setHostName(String nom) {
+       public synchronized void setHostName(String nom) {
                this.hostName = nom;
        }
 
                this.hostName = nom;
        }
 
-       public void setRank(int val) {
+       public synchronized void setRank(int val) {
                this.rank = val;
        }
 
                this.rank = val;
        }
 
-       public void setHostStub(JaceInterface s) {
+       public synchronized void setHostStub(JaceInterface s) {
                this.hostStub = s;
        }
 
                this.hostStub = s;
        }
 
index d214061..a95f0a7 100644 (file)
@@ -7,11 +7,13 @@ class UpdateRegisterConcernedThread extends Thread {
        int requete;
        int i, rank;
        Task tache = null;
        int requete;
        int i, rank;
        Task tache = null;
-       Vector<?> neighbors;
+       @SuppressWarnings("unchecked")
+       Vector neighbors;
        int nbOfDeamonsPerThread;
        Node oldNode, node;
 
        int nbOfDeamonsPerThread;
        Node oldNode, node;
 
-       public UpdateRegisterConcernedThread(Vector<?> neighbors, Register r, int i,
+       @SuppressWarnings("unchecked")
+       public UpdateRegisterConcernedThread(Vector neighbors, Register r, int i,
                        int rank, Node noeud, Node tmpNode) {
 
                this.reg = r;
                        int rank, Node noeud, Node tmpNode) {
 
                this.reg = r;
@@ -26,114 +28,177 @@ class UpdateRegisterConcernedThread extends Thread {
 
        public void run() {
                ListeTask listOfTasks = Register.Instance().getListeOfTasks().clone();
 
        public void run() {
                ListeTask listOfTasks = Register.Instance().getListeOfTasks().clone();
+//             boolean retry = false ;
+//             int nbRetry = 0 ;
+//             int nbRetryMax = 2 ;
+
+               String name = "" ;
+
                // listOfTasks.viewAll();
                for (int index = i * nbOfDeamonsPerThread; index < i
                // listOfTasks.viewAll();
                for (int index = i * nbOfDeamonsPerThread; index < i
-                               * nbOfDeamonsPerThread + nbOfDeamonsPerThread
-                               && index < neighbors.size(); index++) {
+               * nbOfDeamonsPerThread + nbOfDeamonsPerThread
+               && index < neighbors.size(); index++) 
+               {
 
 
-                       try {
-                               if (((Integer) neighbors.elementAt(index)).intValue() == rank) {
-                                       Register g = new Register();
-                                       ListeTask newListOfTasks = new ListeTask();
-                                       g.setAppliName(reg.getAppliName());
-                                       g.setParams(reg.getParams());
+//                     retry = true ;
+//                     nbRetry = 0 ;
 
 
-                                       g.setSpawnerStub(JaceSpawner.Instance()
-                                                       .getSpawnerResponsibleOn(rank));
-                                       g.setNbOfTasks(reg.getNbOfTasks());
+//                     while( retry )
+//                     {
+                               try {
+                                       if (((Integer) neighbors.elementAt(index)).intValue() == rank) {
+                                               Register g = new Register();
+                                               ListeTask newListOfTasks = new ListeTask();
+                                               g.setAppliName(reg.getAppliName());
+                                               g.setParams(reg.getParams());
 
 
-                                       for (int j = 0; j < neighbors.size(); j++) {
-                                               TaskId id = listOfTasks
-                                                               .getTaskIdOfRank(((Integer) neighbors
-                                                                               .elementAt(j)).intValue());
-                                               newListOfTasks.addTask(id);
-                                               if (id.getHostStub() != null) {
-                                                       Node noeud = reg.getNodeOfStub(id.getHostStub());
-                                                       Node n2 = noeud;
-
-                                                       g.addNode(n2);
-                                               }
-                                       }
-                                       g.setListeOfTasks(newListOfTasks);
-
-                                       TaskId neighborTask = listOfTasks
-                                                       .getTaskIdOfRank((((Integer) neighbors
-                                                                       .elementAt(index)).intValue() + 1)
-                                                                       % listOfTasks.getSize());
-                                       JaceInterface stubVoisin = neighborTask.getHostStub();
-                                       JaceInterface stub = listOfTasks.getTaskIdOfRank(
-                                                       ((Integer) neighbors.elementAt(index)).intValue())
-                                                       .getHostStub();
-                                       if (stub == null || stubVoisin == null) {
-                                               System.out.println("stub NULL");
-                                       } else {
-
-                                               String name = listOfTasks.getTaskIdOfRank(
-                                                               ((Integer) neighbors.elementAt(index))
-                                                                               .intValue()).getHostName();
+                                               g.setSpawnerStub(JaceSpawner.Instance()
+                                                               .getSpawnerResponsibleOn(rank));
+                                               g.setNbOfTasks(reg.getNbOfTasks());
 
 
-                                               try {
-                                                       // whatever the case, update the Register on each Node
+                                               for (int j = 0; j < neighbors.size(); j++) {
+                                                       TaskId id = listOfTasks
+                                                       .getTaskIdOfRank(((Integer) neighbors
+                                                                       .elementAt(j)).intValue()) ;
+                                                       newListOfTasks.addTask( id ) ;
+                                                       if( id.getHostStub() != null ) {
+                                                               Node noeud = reg.getNodeOfStub( id.getHostStub() ) ;
+//                                                             Node n2 = noeud ;
+                                                               if( noeud != null )
+                                                               {
+                                                                       g.addNode( noeud ) ;
+                                                               } else {
+                                                                       noeud = reg.getNodeOfName( id.getHostName() ) ;
+                                                                       
+                                                                       if( noeud != null )
+                                                                       {
+                                                                               g.addNode( noeud ) ;
+                                                                       } else {
+                                                                               System.err.println( "UpdateRegisterConcernedThread: cannot found the corresponding node !" ) ;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                               
+                                               g.setListeOfTasks(newListOfTasks);
 
 
-                                                       // JaceSpawnerInterface
-                                                       // ja=Register.Instance().getSpawnerStub();
-                                                       // System.out.println("avant update register");
+                                               TaskId neighborTask = listOfTasks
+                                               .getTaskIdOfRank((((Integer) neighbors
+                                                               .elementAt(index)).intValue() + 1)
+                                                               % listOfTasks.getSize());
+                                               JaceInterface stubVoisin = neighborTask.getHostStub();
+                                               JaceInterface stub = listOfTasks.getTaskIdOfRank(
+                                                               ((Integer) neighbors.elementAt(index)).intValue())
+                                                               .getHostStub();
+                                               if( stub == null || stubVoisin == null ) 
+                                               {
+                                                       System.out.println("stub NULL");
+                                               } else {
+                                                       name = listOfTasks.getTaskIdOfRank(
+                                                                       ((Integer) neighbors.elementAt(index))
+                                                                       .intValue()).getHostName();
 
 
-                                                       stub.updateRegister(g, stubVoisin, 0);
+                                                       Node noeud = null ;
+                                                       
+                                                       try {
+                                                               // whatever the case, update the Register on each Node
 
 
-                                                       // System.out.println(" after update register");
-                                                       // if updateRegister worked, that means Node is
-                                                       // Alive
-                                                       Node noeud = Register.Instance()
-                                                                       .getNodeOfStub(stub);
-                                                       if (noeud != null) {
-                                                               noeud.setAliveFlag(true);
-                                                               noeud.setAliveTime();
+                                                               // JaceSpawnerInterface
+                                                               // ja=Register.Instance().getSpawnerStub();
+                                                               // System.out.println("avant update register");
 
 
-                                                       }
-                                               } catch (Exception e) {
-                                                       System.err
-                                                                       .println(name
-                                                                                       + " ("
-                                                                                       + LocalHost.Instance()
-                                                                                                       .resolve(name)
-                                                                                       + " rank="
-                                                                                       + index
-                                                                                       + ") cannot be reached by UpdateRegisterConcernedThread   for new node "
-                                                                                       + "     size : "
-                                                                                       + Register.Instance().getSize()
-                                                                                       + " :" + e);
+                                                               stub.updateRegister( g, stubVoisin, 0 ) ;
 
 
-                                               }
-                                       }
-                               } else {
-                                       //int tag;
-                                       TaskId id = listOfTasks
-                                                       .getTaskIdOfRank(((Integer) neighbors
-                                                                       .elementAt(index)).intValue());
-                                       String name = id.getHostName();
+                                                               // System.out.println(" after update register");
+                                                               // if updateRegister worked, that means Node is
+                                                               // Alive
+                                                               noeud = Register.Instance()
+                                                               .getNodeOfStub(stub);
+                                                               if (noeud != null) {
+                                                                       noeud.setAliveFlag(true);
+                                                                       noeud.setAliveTime();
 
 
-                                       try {
-
-                                               JaceInterface stub = id.getHostStub();
-                                               stub.updateRegister(oldNode, node);
-                                       } catch (Exception e) {
-                                               System.err
+                                                               }
+//                                                             retry = false ;
+                                                       } catch( Exception e ) {
+                                                               System.err
                                                                .println(name
                                                                                + " ("
                                                                .println(name
                                                                                + " ("
-                                                                               + LocalHost.Instance().resolve(name)
+                                                                               + LocalHost.Instance()
+                                                                               .resolve(name)
                                                                                + " rank="
                                                                                + index
                                                                                + " rank="
                                                                                + index
-                                                                               + ") cannot be reached by UpdateRegisterConcernedThread   "
+                                                                               + ") cannot be reached by UpdateRegisterConcernedThread for new node "
                                                                                + "     size : "
                                                                                + "     size : "
-                                                                               + Register.Instance().getSize() + " :"
-                                                                               + e);
+                                                                               + Register.Instance().getSize()
+                                                                               + " :" + e);
+//                                                             try{
+//                                                                     Thread.sleep( (nbRetry + 1) * 2000 ) ;
+//                                                             }catch(Exception sl){}
+//                                                             nbRetry++ ;
+
+//                                                             if( nbRetry > nbRetryMax )
+//                                                             {
+//                                                                     retry = false ;
+//                                                                     System.err.println( "Cannot retry anymore!" ) ;
+//                                                                     if( noeud != null )
+//                                                                     {
+//                                                                             try {
+//                                                                                     JaceSpawner.Instance().signalDeadNode( noeud.getStub(), index ) ;
+//                                                                             } catch( Exception ex ) {
+//                                                                                     JaceSpawner.Instance().signalDeadNode( null, index ) ;
+//                                                                             }
+//                                                                     } else {
+//                                                                             JaceSpawner.Instance().signalDeadNode( null, index ) ;
+//                                                                     }
+//                                                             }
+                                                       }
+                                               }
+                                       } else {
+                                               //int tag;
+                                               TaskId id = listOfTasks
+                                               .getTaskIdOfRank(((Integer) neighbors
+                                                               .elementAt(index)).intValue());
+                                               name = id.getHostName();
+
+                                               try {
+
+                                                       JaceInterface stub = id.getHostStub() ;
+                                                       stub.updateRegister( oldNode, node, rank ) ;
+//                                                     retry = false ;
+                                               } catch (Exception e) {
+                                                       System.err
+                                                       .println(name
+                                                                       + " ("
+                                                                       + LocalHost.Instance().resolve(name)
+                                                                       + " rank="
+                                                                       + index
+                                                                       + ") cannot be reached by UpdateRegisterConcernedThread size : "
+                                                                       + Register.Instance().getSize() + " :"
+                                                                       + e);
+
+//                                                     try{
+//                                                             Thread.sleep( (nbRetry + 1) * 2000 ) ;
+//                                                     }catch(Exception sl){}
+//                                                     nbRetry++ ;
+
+//                                                     if( nbRetry > nbRetryMax )
+//                                                     {
+//                                                             retry = false ;
+//                                                             System.err.println( "Cannot retry anymore!" ) ;
+//                                                     }
+                                               }
                                        }
                                        }
+                               } catch( Exception e2 ) {
+                                       System.err.println("Error in updateRegisterConcernedThread :"
+                                                       + e2);
                                }
                                }
-                       } catch (Exception e2) {
-                               System.err.println("Error in updateRegisterConcernedThread :"
-                                               + e2);
-                       }
+//                     }
+
+//                     if( nbRetry > nbRetryMax )
+//                     {
+//                             
+//                     }
                }
                // System.out.println("at the end of an updateRegisterCon. j="+i);
                // Register.Instance().getListeOfTasks().viewAll();
                }
                // System.out.println("at the end of an updateRegisterCon. j="+i);
                // Register.Instance().getListeOfTasks().viewAll();
index 7b71d58..df8c036 100644 (file)
@@ -91,7 +91,20 @@ class UpdateRegisterThread extends Thread {
                                // System.out.println("avant update register");
 
                                // 1 l'appli vient de commencer
                                // System.out.println("avant update register");
 
                                // 1 l'appli vient de commencer
-                               stub.updateRegister(g, stubVoisin, requete);
+                               int ret = 1 ;
+                               int loop = 0 ;
+                               int LOOP_MAX = 3 ;
+                               
+                               while( ret == 1 && loop < LOOP_MAX )
+                               {
+                                       ret = stub.updateRegister(g, stubVoisin, requete);
+                                       loop++ ;
+                               }
+                               
+                               if( loop == LOOP_MAX )
+                               {
+                                       System.err.println( "Problem during register update!" ) ;
+                               } else {
                                // System.out.println("Envoi du registre a :"+index);
                                // g.viewAll();
                                // System.out.println("ancien registre");
                                // System.out.println("Envoi du registre a :"+index);
                                // g.viewAll();
                                // System.out.println("ancien registre");
@@ -100,11 +113,11 @@ class UpdateRegisterThread extends Thread {
                                // Register.Instance().viewAll();
                                // System.out.println(" after update register");
                                // if updateRegister worked, that means Node is Alive
                                // Register.Instance().viewAll();
                                // System.out.println(" after update register");
                                // if updateRegister worked, that means Node is Alive
-                               Node noeud = Register.Instance().getNodeOfStub(stub);
-                               if (noeud != null) {
-                                       noeud.setAliveFlag(true);
-                                       noeud.setAliveTime();
-
+                                       Node noeud = Register.Instance().getNodeOfStub(stub);
+                                       if (noeud != null) {
+                                               noeud.setAliveFlag(true);
+                                               noeud.setAliveTime();
+                                       }
                                }
                        } catch (Exception e) {
                                System.err.println(name + " ("
                                }
                        } catch (Exception e) {
                                System.err.println(name + " ("