Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New development version.
[jaceP2P.git] / src / jaceP2P / JaceSuperNodeServer.java
index de7b876..463887a 100644 (file)
@@ -7,15 +7,14 @@ import java.util.Vector;
 
 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.LSM;
-import and.Mapping.Mapping;
-import and.Mapping.QM;
+import and.Mapping.Maheve;
 import and.Mapping.Simple;
-import and.Mapping.Utils;
 
 
 public class JaceSuperNodeServer extends UnicastRemoteObject implements
@@ -25,9 +24,8 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        // Attributes
        private int beat;
        private ArrayList<GNode> gnodes = null;
-       private Algo al = null ;
-       private int count = 0 ;
-//     private boolean daemonListChange ;
+       private ArrayList<Algo> algos = null ;
+       private boolean inDemand = false, operating = false, authorized = false ;
        
        // Constructors
 
@@ -35,7 +33,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                super() ;
                beat = timeBeat ;
                gnodes = new ArrayList<GNode>() ;
-//             daemonListChange = true ;
+               algos = new ArrayList<Algo>() ;
        }
 
        public int getSuperNodeBeat() throws RemoteException {
@@ -57,7 +55,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                SuperNodeListe.Instance().viewAll();
        }
 
-       public void sendSurplus(Vector<?> nodes) throws RemoteException {
+       public void sendSurplus(Vector<?> nodes, ArrayList<GNode> _gnodes) throws RemoteException {
                System.out.println("Recieved " + nodes.size() + " nodes");
 
                for (int i = 0; i < nodes.size(); i++) {
@@ -76,10 +74,16 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                                                .setNbOfNodes(Register.Instance().getSize());
                                new ForwardCount().start();
                        } catch (Exception e) {
-                               System.out.println("Error changing Server in SendSurplus : "
+                               System.err.println("Error changing Server in SendSurplus : "
                                                + e);
                        }
                }
+               
+               /** Updating gnodes **/
+               if( _gnodes != null )
+               {
+                       gnodes = _gnodes ;
+               }
        }
 
        public void setToken() throws RemoteException {
@@ -92,7 +96,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
 
                        System.out.println("Put token to true");
                } catch (Exception e) {
-                       System.out
+                       System.err
                                        .println("Unable to heartBeat the next SuperNode with the new Token : "
                                                        + e);
                }
@@ -116,25 +120,31 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        public synchronized void workerRegistering(JaceInterface workerStub,
                        String workerIP, String workerName, int port, GNode g)
                        throws RemoteException {
-               System.out.println("CONNEXION of " + workerName);
+               System.out.println("CONNECTION of " + 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.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.setId( noeud.getId() ) ;
-               gnodes.add(g);
+               g.setNode( noeud ) ;
+               g.setId( id ) ;
+               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);
@@ -151,7 +161,30 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                                .setNbOfNodes(Register.Instance().getSize());
                SuperNodeListe.Instance().forwardCountNode();
                
+               authorized = true ;
                SuperNodeListe.Instance().addGNode( g ) ;
+               authorized = 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 ) ;
+                       }
+               }
+               
        }
 
        /****************************************************/
@@ -186,18 +219,34 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        /** Mapping !! Sébastien Miquée **/
        /*********************************/
 
-       public Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
+       /**
+        * Search and return to the requester spawner a register containing
+        * computation nodes plus some extra nodes if needed. This method requires
+        * as parameters the mapping algorithm choice and its parameters, and the
+        * amount of requested nodes and the task to be used, in order to 
+        * construct the tasks graph.
+        * @param spawnerIP IP of the requester
+        * @param nbTasks Amount of tasks
+        * @param t Tasks to be executed
+        * @param nbNoeuds Total amount of requested nodes
+        * @param algo Identifier of the mapping algorithm
+        * @param paramAlgo Parameter of the mapping algorithm 
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e        
+        */
+       @Override
+       public synchronized Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
                        int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
 
                // Have we the correct application ?
-               if (t == null) {
-                       System.err.println( "Problem of class transmission !" ) ;
+               if( t == null ) {
+                       System.err.println( "Problem of class transmission!" ) ;
                        return null ;
                }
                
                if( t.getDependencies( 0 ) == null )
                {
-                       System.err.println( "No redifinition of getDependencies() function!" ) ;
+                       System.err.println( "No redifinition of getDependencies() function!" ) ;
                        return null ;
                }
                
@@ -205,31 +254,43 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                /** Creation of an empty new Register **/
                Register reg = new Register() ;
 
+               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 **/
+               System.out.println( "\nHeterogeneity of the grid : " + grid.getHeterogenityDegre() + "\n" ) ;
+               
 
                /** Creation of tasks GTask **/
                ArrayList<GTask> ts = new ArrayList<GTask>();
-               for (int i = 0; i < nbTasks; i++) {
-                       ts.add(new GTask( i ) ) ;
+               for( int i = 0; i < nbTasks; i++ ) {
+                       ts.add( new GTask( i ) ) ;
                }
 
                /** Research of dependencies **/
-               for (int i = 0; i < nbTasks; i++) {
-                       int dep[] = null;
-                       dep = t.getDependencies(i);
+               for( int i = 0; i < nbTasks; i++ ) {
+                       int dep[] = null ;
+                       dep = t.getDependencies( i ) ;
 
                        /** Adding dependencies to tasks **/
-                       for (int j = 0; j < dep.length; j++) {
-                               if (dep[j] != -1) {
-                                       ts.get(i).addDependance(ts.get(dep[j]));
+                       for( int j = 0; j < dep.length; j++ ) {
+                               if( dep[j] != -1 ) {
+                                       ts.get( i ).addDependance( ts.get( dep[ j ] ) ) ;
                                } else {
-                                       break;
+                                       break ;
                                }
                        }
                }
-
+               
+               /** Creation of the application interaction graph **/
                Graph graph = new Graph();
 
                for( int i = 0 ; i < ts.size() ; i++) 
@@ -237,399 +298,610 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        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 **/
-               al = null ;
+               Algo al = null ;
 
-               switch (algo) {
+               switch( algo ) {
                case 0:
                        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:
-                       al = new LSM(graph, grid, paramAlgo);
+                       al = new FT_FEC(graph, grid, paramAlgo);
                        break;
+               case 3:
+                       al = new Maheve( graph, grid ) ;
+                       break ;
                default:
                        al = new DefaultMapping( graph, grid, gnodes ) ;
                }
 
-               if (al != null) {
+               if (al != null) 
+               {
                        /** Launching the Mapping **/
                        al.map();
 
-                       /** Transforming mapping in register **/
-                       Mapping mp = al.getMapping();
 
                        /** Creating the register **/
-                       ArrayList<GNode> ag = mp.getMappedGNodes();
+                       ArrayList<GNode> ag = al.getMapping().getMappedGNodes();
+                       
+                       System.out.println("NB returned nodes : "+ag.size());
 
-                       for (int i = 0; i < ag.size(); i++) {
+                       
+                       /** 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());
-                               gnodes.remove(ag.get(i));
+                               
+                               ag.get(i).setMapped( true ) ;
+                               setMapped( ag.get(i), 1 ) ;
                                Register.Instance().removeNode((Node) ag.get(i).getNode());
                        }
+                       
+                       
+                       /** Searching extra nodes if any **/
+                       if( nbNoeuds > nbTasks )
+                       {
+                               int nb = nbNoeuds - nbTasks ;
+                               GNode sup = null ;
+                               
+                               for( int i = 0 ; i < nb ; i ++ )
+                               {
+                                       sup = algos.get(idAlgo).getOtherGNode( gnodes ) ;
+                                       algos.get(idAlgo).getMapping().addOtherNode( sup ) ;
+                                       reg.addNodeBeg( (Node) sup.getNode() ) ;
+                                       setMapped( sup, 1 ) ;
+                                       Register.Instance().removeNode((Node) sup.getNode());
+                               }
+                       }
+                       
+                       authorized = false ;
 
                        if (ag.size() != 0) {
                                SuperNodeListe.Instance().forwardCountNode();
                        }
 
                } 
-//             else {
-//                     al = new DefaultMapping( graph, grid, gnodes ) ;
-//                     /** Launching the Mapping **/
-//                     al.map();
-//
-//                     /** Transforming mapping in register **/
-//                     Mapping mp = al.getMapping();
-//
-//                     /** Creating the register **/
-//                     ArrayList<GNode> ag = mp.getMappedGNodes();
-//
-//                     for (int i = 0; i < ag.size(); i++) {
-//                             reg.addNode((Node) ag.get(i).getNode());
-//                             gnodes.remove(ag.get(i));
-//                             Register.Instance().removeNode((Node) ag.get(i).getNode());
-//                     }
-//
-//                     if (ag.size() != 0) {
-//                             SuperNodeListe.Instance().forwardCountNode();
-//                     }
-//                     return getRegisterSpawner(spawnerIP, nbTasks);
-//             }
-               
-//             daemonListChange = false ;
-
-               System.out.println( "Spawner returned reg: " + reg ) ;
-               
-               /* Mapping distribution over other Super Nodes */
-               SuperNodeListe.Instance().setMapping( al ) ;
-               
-               /* Returning result */
+               
+               operating = false ;
+               
+               /** Returning result **/
                return reg ;
        }
 
-       /*****************************************/
-       /****        Sébastien Miquée         ****/
-       /**                                     **/
-       /**      Recherche nouveau noeud        **/
-       /*****************************************/
        
-       protected GNode delGNodeFromList( Node _n )
+       public synchronized void setMapped( GNode _g, int _mode ) throws RemoteException 
        {
-               GNode deadGNode = null ;
+               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
+        * a computation node. After having done the local suppression of the node
+        * it propagates the suppression to other SuperNodes.
+        * @param _n The fallen node
+        * @param _mode Choice of the list (0: gnodes, 1: mapping, 2:just mapped)
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e        
+        */
+       @Override
+       public synchronized GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
+       {
+               GNode removedGNode = null ;
                
-               for( int i = 0 ; i < gnodes.size() ; i++ )
+               if( _n != null )
+               {       
+                       boolean free = false ;
+                       
+                       if( ! operating )
+                       {
+                               workingOnGnodes() ;
+                               free = true ;
+                       }
+
+                       if( _mode == 0 )
+                       {
+                               GNode dead = null ;
+                               
+                               for( int i = 0 ; i < gnodes.size() ; i++ )
+                               {
+                                       if( _n.getId() == ((Node) gnodes.get(i).getNode()).getId() )
+                                       {
+                                               dead = gnodes.remove( i ) ;
+                                               break ;
+                                       }
+                               }
+                               
+                               if( dead != null )
+                               {
+                                       for( int i = 0 ; i < algos.size() ; i++ )
+                                       {
+                                               algos.get( i ).getGrid().removeGNode( dead ) ;
+                                               Register.Instance().removeNodeOfName( dead.getName() ) ;
+                                               SuperNodeListe.Instance().removeGNode( dead, _mode, _spawnerIp ) ;
+                                       }
+                               } else {
+                                       System.err.println( "The dead node signaled does not exist!" ) ;
+                               }
+                       }
+                       
+                       if( free )
+                       {
+                               operating = false ;
+                       }
+               
+               }
+               
+               return removedGNode ;
+       }
+       
+       
+       /**
+        * Search the position of the mapping algorithm in the list.
+        * @param _id Identifier of the algorithm
+        * @return The position in the list
+        */
+       private int searchAlgo( String _id ) 
+       {
+               int id = -1 ;
+               
+               for( int i = 0 ; i < algos.size() ; i++ )
                {
-                       if( ((Node)gnodes.get(i).getNode()).getId() == _n.getId() ) 
+                       if( algos.get( i ).getIdS().equals( _id ) )
                        {
-                               deadGNode = gnodes.remove( i ) ;
+                               id = i ; 
                                break ;
                        }
                }
                
-//             daemonListChange = true ;
+               return id ;
+       }
+
+       /**
+        * Determine if this SuperNode can operate on the gnodes list.
+        * It asks other SuperNodes to know if their are working on this list
+        * and set the authorization, or not.
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e        
+        */
+       private synchronized void workingOnGnodes()
+       {
+               boolean tmp = true ;    
                
-               SuperNodeListe.Instance().removeGNode( deadGNode ) ;
+               inDemand = false ; 
+               operating = false ;
+           
+               while( ! operating )
+               {
+                       inDemand = true ;
+                       tmp = true ;
+                       
+                       tmp = tmp && SuperNodeListe.Instance().workingOnGnodes() ;
+
+                       operating = tmp ;
+                       
+                       if( ! tmp )
+                       {
+                               inDemand = false ;
+                               
+                               try {
+                                       Thread.sleep( 10 ) ;
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+               }
                
-               return deadGNode ;
+               inDemand = false ;
        }
-
        
-       public Node getNewNode( String _spawnerIP, Node _deadNode ) throws RemoteException
+       /**
+        * 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
        {
-               Node node = null ;
-               GNode remp = null, gnode = null ;
+               int idNode = -1 ;
+               int idAlgo = searchAlgo( _spawnerIP ) ;
                
+               if( idAlgo == -1 )
+               {
+                       System.err.println( "No algorithm found for this Spawner!" ) ;
+                       return null ;
+               }
                
-               if( _deadNode != null )
+               /** We have to replace a Spawner **/
+               if( _rank == -2 )
                {
-                       gnode = delGNodeFromList( _deadNode ) ;
+                       idNode = -2 ;
+               } else {
+               /** We have to replace a computing node **/
+                       idNode = algos.get( idAlgo ).getMapping().getIdOfAssociation( _rank ) ;
+               }
                
-                       /* TODO */
-                       Mapping mp = al.getMapping() ;
+               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
+        * 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 _deadNode The failed node
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
+       @Override
+       public synchronized Node getNewNode( String _spawnerIP, GNode _deadNode ) throws RemoteException
+       {
+               Node node = null ;
+               GNode remp = null ;
+
+               int idAlgo = searchAlgo( _spawnerIP ) ;
                
-//             ArrayList <GNode> mapped = mp.getMappedGNodes() ;
+               if( idAlgo == -1 )
+               {
+                       System.err.println( "No algorithm found for this Spawner!" ) ;
+                       return null ;
+               }
                
-                       mp.removeGNode( gnode ) ;
                
-                       /*****************/
-                       // mettre directement dans Algo !
-//             for( int i = 0 ; i < mapped.size() ; i++ )
-//             {
-//                     gnode = mapped.get( i ) ;
-//                     tmp = (Node) gnode.getNode() ;
-//                     if( tmp.getId() == _deadNode.getId() )
-//                     {
-//                             mapped.remove( i ) ;
-//                             break ;
-//                     }
-//             }
+               /** Can we use gnodes ?**/
+               workingOnGnodes() ;
                
-                       remp = al.replaceNode( gnode, gnodes ) ;
+               if( _deadNode != null )         
+               {
+                       authorized = true ;
+                       
+                       removeMappedGNode( _deadNode, 1 ) ;
+                       
+                       authorized = false ;
+
+                       remp = algos.get( idAlgo ).replaceNode( _deadNode, gnodes ) ;
                
                        if( remp != null )
                        {
                                System.out.println( "Replacing node found." ) ;
-                               node = (Node) remp.getNode() ;
-                               delGNodeFromList( node ) ;
-//                             gnodes.remove( remp ) ;
-//                             Register.Instance().removeNode( node );
+                               
+                               authorized = true ;
+                               
+                               remp.setMapped( true ) ;
+                               
+                               setMapped( remp, 1 ) ;
+                               Register.Instance().removeNodeOfName( remp.getName() ) ;
+                               
+                               
+                               /** Updating all mapping **/
+                               updateMappedNode( _deadNode, remp, _spawnerIP ) ;
+                               propagateReplaceNode( _deadNode, remp, _spawnerIP ) ;
+                               
+                               authorized = false ;
+                               
                                SuperNodeListe.Instance().forwardCountNode();
                        } else {
                                System.err.println( "Replacing node not found !!" ) ;
                        }
                } else {
-                       remp = al.getOtherGNode() ;
+                       remp = algos.get( idAlgo ).getOtherGNode( gnodes ) ;
                        
                        if( remp != null )
                        {
                                System.out.println( "Other new node found." ) ;
-                               node = (Node) remp.getNode() ;
-                               delGNodeFromList( node ) ;
-//                             gnodes.remove( remp ) ;
-//                             Register.Instance().removeNode( node );
+
+                               remp.setMapped( true ) ;
+                               
+                               authorized = true ;
+                               
+                               setMapped( remp, 1 ) ;
+                               Register.Instance().removeNodeOfName( remp.getName() ) ;
+                               
+                               authorized = false ;
+                               
                                SuperNodeListe.Instance().forwardCountNode();
                        } else {
                                System.err.println( "Other new node not found !!" ) ;
                        }
                }
                
+               if( remp != null )
+               {
+                       node = (Node) remp.getNode() ;
+               } else {
+                       System.err.println( "SuperNode: No new node found!" ) ;
+               }
+               
+               
+               /** Free the gnodes use **/
+               operating = false ;
+               
                return node ;
        }
        
        
-       /**********************************************************/
-       /**********************************************************/
+       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.
+        * @param _dead The failed node
+        * @param _remp The replacing node
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
+       @Override
+       public synchronized void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP ) 
+       {
+               if( _remp != null )
+               {
+                       int pos = 0 ;
+                       
+                       int idAlgo = searchAlgo( _spawnerIP ) ;
+                       
+                       if( idAlgo == -1 )
+                       {
+                               System.err.println( "No algorithm found for this Spawner!" ) ;
+                               return ;
+                       }
+               
+                       pos = algos.get( idAlgo ).getMapping().getIdOfAssociation( _dead ) ;
+               
+                       if( pos != -1 )
+                       {
+                               /** Changing the 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!" ) ;
+                       }
+                       
+               } else {
+                       System.err.println( "The new GNode is null!" ) ;
+               }       
+       }
+
        
-//     public Node getNewNode(String spawnerIP) throws RemoteException {
-//             boolean found = false;
-//             int i = 0;
-//             Node tmpNode = null;
-//             SuperNodeData d = null;
-//             //int passage = 0;
-//             String snode_IP;
-//             JaceSuperNodeInterface stub = null;
-//
-//             try {
-//                     System.out.println("\n" + spawnerIP
-//                                     + " (spawner) requests a new node : ");
-//                     while (i < Register.Instance().getSize() && found == false) {
-//                             tmpNode = Register.Instance().getNodeAt(i);
-//
-//                             if (tmpNode.getAppliName() == null
-//                                             && tmpNode.getAliveFlag() == true) {
-//                                     tmpNode.setAppliName("notnull");
-//                                     found = true;
-//
-//                                     // enlever maintenant le noeud du register de
-//                                     // SuperNode??????
-//                                     // System.out.println("je remove le noeud car il va beater le spawner (getNewNode)");
-//                                     // Register.Instance().removeNodeAt(i);
-//                                     Register.Instance().removeNode(tmpNode);
-//                                     // Register.Instance().removeNode(tmpNode.getIP());
-//
-//                                     int index = SuperNodeListe.Instance().existSuperNode(
-//                                                     LocalHost.Instance().getIP());
-//
-//                                     ((SuperNodeData) SuperNodeListe.Instance().getListe()
-//                                                     .elementAt(index)).setNbOfNodes(Register.Instance()
-//                                                     .getSize());
-//                                     SuperNodeListe.Instance().forwardCountNode();
-//                             }
-//                             i++;
-//                     }
-//             } catch (Exception e1) {
-//                     System.out.println("... plante en cherchant chez moi");
-//             }
-//
-//             // Register.Instance().viewAll();
-//             SuperNodeListe.Instance().viewAll();
-//
-//             try {
-//                     // si pas assez de noeud sur ce superNode,
-//                     if (found == false) {
-//                             System.out.println("pas de noeud dispo chez moi");
-//
-//                             SuperNodeListe snodeListTmp = SuperNodeListe.Instance().clone();
-//                             // while ( (found == false) && (passage <
-//                             // SuperNodeListe.Instance().getSize()) ) {
-//                             while ((found == false) && (snodeListTmp.getSize() > 0)) {
-//                                     // System.out.println("passage = " + passage);
-//                                     // d = SuperNodeListe.Instance().getBestSuperNodeData();
-//                                     d = snodeListTmp.getBestSuperNodeData();
-//                                     System.out.println("KKKKKKKKKKKKKKK ......... le best c "
-//                                                     + d.getIP() + " il en a " + d.getNbOfNodes());
-//                                     if (d != null) {
-//                                             snode_IP = d.getIP();
-//                                             // si c moi, je passe au suivant
-//                                             if (LocalHost.Instance().getIP().equals(snode_IP)) {
-//                                                     // passage++;
-//                                                     System.out
-//                                                                     .println("OUUUUPS,   c moi dc je tente un autre");
-//                                                     snodeListTmp.removeSuperNode(d);
-//                                                     continue;
-//                                             }
-//
-//                                             stub = d.getStub();
-//
-//                                             if (stub != null) {
-//                                                     try {
-//                                                             Register tmpReg = stub.reserveLocalNodes(1);
-//                                                             if (tmpReg != null) {
-//                                                                     // for (int j = 0; j < tmpReg.getSize();
-//                                                                     // j++) {
-//                                                                     System.out.println("IL EN A 1 !!!!!!!");
-//                                                                     tmpNode = tmpReg.getNodeAt(0);
-//                                                                     found = true;
-//                                                                     System.out.println("le snode " + snode_IP
-//                                                                                     + " me reserve le noeud demande");
-//                                                             } else {
-//                                                                     System.out
-//                                                                                     .println("MERDE !!!  pas de noeud dispo sur "
-//                                                                                                     + snode_IP);
-//                                                                     System.out
-//                                                                                     .println("Je demande un noeud a un autre");
-//                                                             }
-//
-//                                                     } catch (Exception e) {
-//                                                             System.out
-//                                                                             .println("le snode est mort, je demande les noeuds a un autre");
-//                                                             // remettre localement a 0 le nb de noeuds de ce
-//                                                             // superNode
-//                                                             SuperNodeListe.Instance().modifCountNode(
-//                                                                             snode_IP, 0);
-//                                                             snodeListTmp = SuperNodeListe.Instance()
-//                                                                             .clone();
-//                                                     }
-//                                             }
-//                                     } else {
-//                                             System.out
-//                                                             .println("PUTAIN !!!! aucun noeud encore dispo sur les snode");
-//                                             // passage = SuperNodeListe.Instance().getSize();
-//                                     }
-//                                     // passage++;
-//                                     snodeListTmp.removeSuperNode(d);
-//                             }
-//                     }
-//             } catch (Exception e2) {
-//                     System.out.println("plante en cherchant chez les autres");
-//             }
-//
-//             // si pas assez de noeud sur tous les superNode,
-//             if (found == false) {
-//                     System.out.println("aucun noeud dispo dans le systeme");
-//             } else {
-//                     System.out.println("je lui donne son noeud");
-//             }
-//
-//             return tmpNode;
-//     }
-
-//     public Register reserveLocalNodes(int nb) throws RemoteException {
-//             Register reg = null;
-//             System.out
-//                             .println("\nA superNode or a Spawner asks me for a register of "
-//                                             + nb + " Daemons");
-//
-//             int count = 0;
-//             int i = 0;
-//             Node tmpNode;
-//
-//             if (Register.Instance().getSize() == 0) {
-//                     return new Register();
-//             } else {
-//                     reg = new Register();
-//
-//                     while (i < Register.Instance().getSize() && count < nb) {
-//                             tmpNode = Register.Instance().getNodeAt(i);
-//
-//                             if (tmpNode.getAppliName() == null
-//                                             && tmpNode.getAliveFlag() == true
-//                             /* && tmpNode.getNbOfBeats() > 10 */) {
-//                                     // if node available, alive and not recently connected, then
-//                                     tmpNode.setAppliName("notnull");
-//                                     reg.addNode(tmpNode);
-//
-//                                     // remove now the node from SuperNode or later ?
-//                                     // System.out.println("I remove the Node from SuperNode beating it will now beat the Spawner");
-//                                     Register.Instance().removeNode(tmpNode);
-//                                     count++;
-//                             }
-//                             // increment counter only y Node NOT REMOVED
-//                             else {
-//                                     i++;
-//                             }
-//                     }
-//
-//                     // Register.Instance().viewAll();
-//                     System.out.println("Number of Daemons reserved on me : " + count);
-//                     // Inform other SuperNodes that some Daemons initialy registered on
-//                     // me
-//                     // are no longer available because reserved for the spawner that
-//                     // invoked me
-//                     int index = SuperNodeListe.Instance().existSuperNode(
-//                                     LocalHost.Instance().getIP());
-//                     ((SuperNodeData) SuperNodeListe.Instance().getListe().elementAt(
-//                                     index)).setNbOfNodes(Register.Instance().getSize());
-//
-//                     if (count != 0) {
-//                             SuperNodeListe.Instance().forwardCountNode();
-//                     }
-//
-//                     System.out.println("I return " + count + " nodes");
-//                     // System.out.println( reg ) ;
-//                     // SuperNodeListe.Instance().viewAll() ;
-//                     return reg;
-//             }
-//     }
+       /**
+        * Inform all SuperNodes of the replacement of a failed computing node.
+        * @param _dead The failed node
+        * @param _remp The replacing node
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e        
+        */
+       private synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
+       {
+               if( _remp != null )
+               {       
+                       SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp, _spawnerIP ) ;
+               } else {
+                       System.err.println( "The replacement node is null!" ) ;
+               }
+       }
 
+       /**********************************************************/
+       /**********************************************************/
+
+       
        @Override
+       /**
+        * Add a new node in the list.
+        * @param _g The new node
+        *
+        * @author S&eacute;bastien Miqu&eacute;e        
+        */
        public void addGNode( GNode _g ) throws RemoteException 
        {
                if( _g != null )
-                       gnodes.add( _g ) ; 
+               {
+                       boolean free = false ;
+                       
+                       if( ! operating )
+                       {
+                               workingOnGnodes() ;
+                               free = true ;
+                       }       
+                       
+                       gnodes.add( _g ) ;
+                       
+                       updateGrids( _g ) ;
+                       
+                       if( free )
+                               operating = false ;
+               }
        }
        
 
+       /**
+        * Set the local mapping with another done on an other SuperNode.
+        * @param _al The new mapping
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
        @Override
-       public void removeGNode( GNode _g ) throws RemoteException 
+       public synchronized void setMapping( Algo _al ) throws RemoteException 
        {
-               if( _g != null )
+               if( searchAlgo( _al.getIdS() ) == -1 )
                {
-                       for( int i = 0 ; i < gnodes.size() ; i++ )
-                       {
-                               if( ((Node)gnodes.get(i).getNode()).getId() == ((Node)_g.getNode()).getId() ) 
-                               {
-                                       gnodes.remove( i ) ;
-                                       break ;
-                               }
+                       algos.add( _al ) ;
+               } else {
+                       System.err.println( "I already have this mapping algorithm!" ) ;
+               }
+       }
+
+       
+       @Override
+       /**
+        * Allow or deny the use of operations on the gnodes list, in order to
+        * do a mapping operation.
+        * @return The authorization or not to block gnodes
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
+       public boolean blockForMapping() throws RemoteException
+       {
+               while( inDemand )
+               {
+                       try {
+                               Thread.sleep( 10 ) ;
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
                        }
                }
                
+               if( operating && ! authorized )
+               {
+                       return false ;
+               } else {
+                       return true ;
+               }
        }
-       
 
+       /**
+        * Return the array containing the current not mapped nodes available.
+        * @return The array of available nodes
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e 
+        */
        @Override
-       public void setMapping( Algo _al ) throws RemoteException 
+       public ArrayList<GNode> getGNodes() throws RemoteException 
        {
-               al = _al ;              
+               return gnodes ;
        }
        
+       
+       /**
+        * Remove a mapping algorithm of the algorithms list.
+        * @param _id The algorithm identifier
+        * @param _mode Indicate if the information should be transmitted
+        * 
+        * @author S&eacute;bastien Miqu&eacute;e
+        */
+       public void removeAlgo( String _id, int _mode ) throws RemoteException
+       {
+               int pos ;
+               
+               pos = searchAlgo( _id ) ;
+               
+               if( pos != -1 )
+               {
+                       algos.remove( pos ) ;
+                       
+                       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 ;
+       }
+       
+       
 }
 
 /** ! **/