Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding missing handler when a restart crash.
[hpcvm.git] / src / and / hpcvm / Server.java
index e865eb2..185b5f3 100644 (file)
@@ -84,7 +84,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        private OperatingClients startingClients ;
        private OperatingClients deployingClients ;
        private LimitThread limitThread ;
-       private int maxThread;
+       private int maxThread ;
+       private int ind ;
+       private boolean running ;
        
        
        protected Server() throws RemoteException 
@@ -195,17 +197,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        {
                                if( _ip.equals( clients.get( i ).getIP() ) ) 
                                {                                       
-                                       if( _status.equalsIgnoreCase( "stopped" ) )
-                                       {
-                                               System.out.println( "Client " + clients.get( i ).getName() + " is stopped." ) ;
-                                               clients.get( i ).setStatus( "connected" ) ;
-                                               ComputingClient cc = clients.get( i ).getComputingClient() ;
-                                               computingClients.remove( cc ) ;
-                                               clients.get( i ).setComputingClient( null ) ;
-                                       } else {
-                                               clients.get( i ).setStatus( _status ) ;
-                                               System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
-                                       }
+                                       clients.get( i ).setStatus( _status ) ;
+                                       System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
                                        
                                        break ;
                                }
@@ -229,6 +222,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                limitThread = new LimitThread() ;
                maxThread = 20 ;
                
+               ind = -1 ;
+               running = false ;
+               
                working_directory = "/localhome/vmware" ;
                
                save_interleave  = 30 * 60 * 1000 ;
@@ -267,7 +263,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                clients.get( i ).getStub().emergencyStop() ;
                                clients.get( i ).getStub().stop() ;
                        } catch (RemoteException e) {
-                               e.printStackTrace();
+                               System.err.println( "Unable to send stop signal to " + clients.get( i ).getName() ) ;
+                               e.printStackTrace() ;
                        }
                }
                
@@ -402,6 +399,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        } catch( RemoteException e ) {
                                                                System.err.println( "Unable to indicate to client to retrieve last save!" ) ;
                                                                e.printStackTrace() ;
+                                                               yield() ;
                                                        }
                                                                
                                                        if( res == 0 )
@@ -429,6 +427,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                                } catch( RemoteException e ) {
                                                                                        System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
                                                                                        e.printStackTrace() ;
+                                                                                       yield() ;
                                                                                }
                                                                                
                                                                                if( ok_new && ok_old )
@@ -439,11 +438,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                }
                                                                
                                                                // Replacing in RunningApplication
-                                                               applications.get( 0 ).replaceComputingClient( cc, ccl ) ;
+                                                               applications.get( ind ).replaceComputingClient( cc, ccl ) ;
                                                                
-                                                               for( int l = 0 ; l < applications.get(0).getComputingClients().size() ; l++ )
+                                                               for( int l = 0 ; l < applications.get( ind ).getComputingClients().size() ; l++ )
                                                                {
-                                                                       applications.get(0).getComputingClients().get( l ).setSaveRequest( false ) ;
+                                                                       applications.get( ind ).getComputingClients().get( l ).setSaveRequest( false ) ;
                                                                }
                                                                
                                                                        
@@ -452,10 +451,6 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                System.err.println( "Unable to deploy the save on the new computing client!" ) ;
                                                        }
                                                }
-//                                             } else {
-//                                                     System.err.println( "Problem while launching the VM on " 
-//                                                                     + clients.get(i).getName() + "!" ) ;
-//                                             }
                                                        
                                                if( ok )
                                                {
@@ -505,7 +500,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                @Override
                public void run() 
                {
-                       boolean change ;
+                       boolean change, dead ;
                        
                        while( run )
                        {
@@ -518,40 +513,55 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                {
                                        ConnectedClient cl = it.next() ;
                                        cl.incTimeout() ;
+                                       dead = false ;
                                        
-                                       if( cl.getTimeout() > max_timeout )
+                                       if( cl.getTimeout() > max_timeout || cl.getFail() )
                                        {
-                                               System.out.println( "Disconnection of " + cl.getName() ) ;
-                                               if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
+                                               if( ! cl.getFail() )
                                                {
-                                                       System.out.println( "A VM was running on it!!" ) ;
-                                                       System.out.println( "I will redeploy a save and restart all VM ..." ) ;
+                                                       try {
+                                                               cl.getStub().echo() ;
+                                                               cl.resetTimeout() ;
+                                                       } catch( RemoteException e ) {
+                                                               dead = true ;
+                                                       }
+                                               }
+                                               
+                                               if( dead )
+                                               {
+                                                       System.out.println( "Disconnection of " + cl.getName() ) ;
+                                                       if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
+                                                       {
+                                                               System.out.println( "A VM was running on it!!" ) ;
+                                                               System.out.println( "I will redeploy a save and restart all VM ..." ) ;
                                
-//                                                     for( int i = 0 ; i < computingClients.size() ; i++ )
-//                                                     {
-//                                                             if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
+//                                                             for( int i = 0 ; i < computingClients.size() ; i++ )
 //                                                             {
-//                                                                     computingClients.remove( i ) ;
-//                                                                     break ;
+//                                                                     if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
+//                                                                     {
+//                                                                             computingClients.remove( i ) ;
+//                                                                             break ;
+//                                                                     }
 //                                                             }
-//                                                     }
-                                                       synchronized( counter ){
-                                                               counter.inc() ;}
+                                                               synchronized( counter )
+                                                               {
+                                                                       counter.inc() ;
+                                                               }
                                                                
-                                                       
-                                                       new Server.FaultManager( cl ).start() ;
-                                                       nb_disconnections_computing++ ;
-                                               } else {
-                                                       System.out.println( "There was no VM running on it." ) ;
-                                                       System.out.println( "Maybe it will come back later :)" ) ;
-                                               }
+                                                               new Server.FaultManager( cl ).start() ;
+                                                               nb_disconnections_computing++ ;
+                                                       } else {
+                                                               System.out.println( "There was no VM running on it." ) ;
+                                                               System.out.println( "Maybe it will come back later :)" ) ;
+                                                       }
                                                
-                                               synchronized( clients )
-                                               {
-                                                       it.remove() ;
+                                                       synchronized( clients )
+                                                       {
+                                                               it.remove() ;
+                                                       }
+                                                       nb_disconnections++ ;
+                                                       change = true ;
                                                }
-                                               nb_disconnections++ ;
-                                               change = true ;
                                        }
                                }
                                
@@ -585,6 +595,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        } catch( RemoteException e ) {
                                                                System.err.println( "Unable to invoke emergency stop signal on " + clients.get( i ).getName() ) ;
                                                                e.printStackTrace() ;
+                                                               yield() ;
                                                        }
                                                }
                                        }
@@ -604,28 +615,41 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                counter.wait() ;
                                                        } catch( InterruptedException e ) {
                                                                e.printStackTrace() ;
+                                                               yield() ;
                                                        }
                                                }
                                        }
                                        
-                                       for( int  i = 0 ; i < applications.get(0).getComputingClients().size() ; i++ )
+                                       for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
-                                               final ServicesClient sc = applications.get(0).getComputingClients().get( i ).getClient().getStub() ;
+                                               applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
                                                
-                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
+                                               new RestartVM( applications.get( ind ).getComputingClients().get( i ).getClient() ).start() ;
                                                
-                                               new Thread( new Runnable() {
-                                                       
-                                                       @Override
-                                                       public void run() 
-                                                       {
-                                                               try {
-                                                                       sc.restartVMAfterCrash() ;
-                                                               } catch( RemoteException e ) {
-                                                                       e.printStackTrace() ;
-                                                               }
-                                                       }
-                                               } ).start() ;
+//                                             final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
+                                               
+//                                             new Thread( new Runnable() {
+//                                                     
+//                                                     @Override
+//                                                     public void run() 
+//                                                     {
+//                                                             try {
+//                                                                     if( sc.restartVMAfterCrash() != 0 )
+//                                                                     {
+//                                                                             System.err.println( "Problem while restarting VM on " +sc.getName() + "!" ) ;
+//                                                                     }
+//                                                             } catch( RemoteException e ) {
+//                                                                     try {
+//                                                                             System.err.println( "Problem while restarting VM on " + sc.getName() + "!" ) ;
+//                                                                     } catch( RemoteException e1 ) {
+//                                                                             System.err.println( "Problem while restarting a VM!" ) ;
+//                                                                             e1.printStackTrace() ;
+//                                                                     }
+//                                                                     e.printStackTrace() ;
+//                                                                     yield() ;
+//                                                             }
+//                                                     }
+//                                             } ).start() ;
                                        }
                                }
                                
@@ -634,6 +658,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                        Thread.sleep( 2000 ) ;
                                } catch( InterruptedException e ) {
                                        e.printStackTrace() ;
+                                       yield() ;
                                }
                        }
                }
@@ -670,12 +695,13 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                try {
                                        computingClients.get( i ).getClient().getStub().saveOk() ;
                                } catch (RemoteException e) {
-                                       e.printStackTrace();
+                                       System.err.println( "Unable to invoke the saveOk method on " + computingClients.get( i ).getClient().getName() ) ;
+                                       e.printStackTrace() ;
                                }
                                computingClients.get( i ).setSaveStatus( false ) ;
                        }
                        
-                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
                }
                
                return 0 ;
@@ -691,22 +717,30 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) ) 
                                {
                                        computingClients.get( i ).setLastSave( _saveName ) ;
-                                       System.out.println( "Save name successfully changed for " + _ip ) ;
+                                       System.out.println( "Save name successfully changed on " + computingClients.get( i ).getClient().getName() ) ;
                                        return 0 ;
                                }
                        }
+                       
+                       System.err.println( "Unable to found computing client with IP " + _ip + "!" ) ;
+                       return 1 ;
                }
                
+               System.err.println( "Unable to change save name. IP or save name empty ! (IP: " + _ip + " ; save name: " + _saveName +")" ) ;
+               
                return 1 ;
        }
 
+       
        @Override
        public ArrayList<ServicesClient> startApplication( int _nb ) 
        {
                int nb = clients.size() - computingClients.size() ;
                
-               if( nb > _nb )
+               if( nb > _nb && ! running )
                {
+                       running = true ;
+                       
                        final ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
                        final ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
                        
@@ -728,8 +762,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        
                                                        try {
                                                                startingClients.wait() ;
-                                                       } catch (InterruptedException e) {
-                                                               e.printStackTrace();
+                                                       } catch( InterruptedException e ) {
+                                                               e.printStackTrace() ;
                                                        }
                                                }
                                                
@@ -756,30 +790,30 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        limitThread.inc() ;
                                                }
                                                
-                                               final int ind = i ;
-                                               new Thread( new Runnable(){
-                                                       
+                                               final int indice = i ;
+                                               new Thread( new Runnable()
+                                               {       
                                                        @Override
                                                        public void run() 
                                                        {
                                                                int res = 1 ;
                                                                try {
-                                                                       res = clients.get( ind ).getStub().startVM( 0 ) ;
+                                                                       res = clients.get( indice ).getStub().startVM( 0 ) ;
                                                                } catch( RemoteException e ) {
-                                                                       e.printStackTrace();
+                                                                       e.printStackTrace() ;
                                                                }
                                                                
                                                                if( res == 0 )
                                                                {
-                                                                       ac.add( clients.get( ind ).getStub() ) ;
-                                                                       clients.get( ind ).setStatus( "running" ) ;
-                                                                       ComputingClient cl = new ComputingClient( clients.get( ind ) ) ;
-                                                                       clients.get( ind ).setComputingClient( cl ) ;
+                                                                       ac.add( clients.get( indice ).getStub() ) ;
+                                                                       clients.get( indice ).setStatus( "running" ) ;
+                                                                       ComputingClient cl = new ComputingClient( clients.get( indice ) ) ;
+                                                                       clients.get( indice ).setComputingClient( cl ) ;
                                                                        computingClients.add( cl ) ;
                                                                        tmp.add( cl ) ;
                                                                } else {
                                                                        System.err.println( "Problem while launching the VM on " 
-                                                                                       + clients.get(ind).getName() + "!" ) ;
+                                                                                       + clients.get( indice ).getName() + "!" ) ;
                                                                }
                                                                
                                                                synchronized( limitThread )
@@ -805,7 +839,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        {
                                app.setComputingClients( tmp ) ;
                                app.setRunning( true ) ;
-                               app.setStartTime( System.currentTimeMillis() ) ;
+//                             app.setStartTime( System.currentTimeMillis() ) ;
                                
                                int index, index2 ;
                                /* Choosing save neighbors */
@@ -848,6 +882,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        
                        applications.add( app ) ;
                        
+                       ind = applications.indexOf( app ) ;
+                       
                        return ac ;
                }
                
@@ -882,14 +918,14 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        {
                if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
                {
-                       if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
+                       if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
                        {
                                // Mark it as a requester
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
-                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
                                        {
-                                               applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( true ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setSaveRequest( true ) ;
                                                                                                
                                                break ;
                                        }
@@ -899,13 +935,13 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                // Is every body ok?
                                boolean ok = false ;
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                        if( i == 0 )
                                        {
-                                               ok = applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
+                                               ok = applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
                                        } else {
-                                               ok = ok & applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;       
+                                               ok = ok & applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;     
                                        }
                                        
                                        if( ! ok )
@@ -922,33 +958,33 @@ public class Server extends UnicastRemoteObject implements ServicesServer
 //                                             e1.printStackTrace() ;
 //                                     }
                                        
-                                       for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                                       for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
                                                try {
-                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
-                                                       applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( false ) ;                                                  
+                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
+                                                       applications.get( ind ).getComputingClients().get( i ).setSaveRequest( false ) ;                                                        
                                                } catch( RemoteException e ) {
                                                        System.err.println( "Unable to send the save request response to " +
-                                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+                                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
                                                        e.printStackTrace() ; 
                                                }
                                        }
                                        
-                                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
                                }
                                
                        } else {
                                semaSave.release() ;
                                
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
-                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
                                        {
                                                try {
-                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
+                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
                                                } catch( RemoteException e ) {
                                                        System.err.println( "Unable to send the save request response to " +
-                                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+                                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
                                                        e.printStackTrace() ; 
                                                }
                                                break ;
@@ -967,29 +1003,29 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        {
                if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
                {
-                       System.out.println( "Client " + _ip + " has finished to restart ("+applications.get(0).getComputingClients().size()+") ... " ) ;
-                       if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
+                       System.out.println( "Client " + _ip + " has finished to restart ("+applications.get( ind ).getComputingClients().size()+") ... " ) ;
+//                     if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
                        {
                                // Has it already finished?
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
-                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
                                        {
-                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( true ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setRestartOk( true ) ;
                                                                                                
                                                break ;
                                        }
                                }
                                
-                               // Is every body ok?
+                               // Is everybody ok?
                                boolean ok = false ;
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                        if( i == 0 )
                                        {
-                                               ok = applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
+                                               ok = applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
                                        } else {
-                                               ok = ok & applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ; 
+                                               ok = ok & applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;       
                                        }
                                        
                                        if( ! ok )
@@ -1000,11 +1036,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                if( ok )
                                {
-                                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
                                        
-                                       for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                                       for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
-                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
                                        }
                                }
                                
@@ -1012,32 +1048,57 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                }
        }       
        
+       
+       @Override
+       public void goApplication()
+       {
+               synchronized( applications ) {
+               if( running && applications.get( ind ).getStartTime() != 0 )
+               {
+                       applications.get( ind ).setStartTime( System.currentTimeMillis() ) ;
+                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
+               }}
+       }
+       
 
        @Override
        public void endApplication() 
        {
-               Iterator<ComputingClient> it = computingClients.iterator() ;
-               
-               while( it.hasNext() )
+               synchronized( applications )
                {
-                       ComputingClient cl = it.next() ;
-
-                       try {
-                               cl.getClient().getStub().emergencyStop() ;
-                       } catch (RemoteException e) {
-                               e.printStackTrace();
-                       }
+                       if( running )
+                       {
+                               applications.get( ind ).setEndTime( System.currentTimeMillis() ) ;
+                               applications.get( ind ).setRunning( false ) ;
+                               applications.get( ind ).clear() ;
                        
-                       cl.getClient().setStatus( "connected" ) ;
-                       cl.getClient().setComputingClient( null ) ;
-                       it.remove() ;
-                       cl = null ;
-               }
+                               Iterator<ComputingClient> it = computingClients.iterator() ;
                
-               applications.get( 0 ).setEndTime( System.currentTimeMillis() ) ;
-               applications.get( 0 ).setRunning( false ) ;
-               applications.get( 0 ).clear() ;
+                               while( it.hasNext() )
+                               {
+                                       ComputingClient cl = it.next() ;
+
+                                       try {
+                                               cl.getClient().getStub().emergencyStop() ;
+                                       } catch (RemoteException e) {
+                                               e.printStackTrace();
+                                       }
+                       
+                                       cl.getClient().setStatus( "connected" ) ;
+                                       cl.getClient().setComputingClient( null ) ;
+                                       it.remove() ;
+                                       cl = null ;
+                               }
                
+                       
+                               applications.get( ind ).clear() ;
+                       
+                               running = false ;
+                       
+                               System.out.println( "Application " + applications.get( ind ).getName() + " ends in " + 
+                                       applications.get( ind ).getExecutionTime() + " seconds." ) ;
+                       }
+               }
        }
 
 
@@ -1088,8 +1149,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
 //                     boolean error, ok, server ;
 //                     ArrayList<ConnectedClient> deployed = new ArrayList<ConnectedClient>() ;
                        
-                       boolean server = true ;
-                       boolean ok ;
+//                     boolean server = true ;
+//                     boolean ok ;
                        
                        for( int i = 0 ; i < clients.size() ; i++ )
                        {
@@ -1113,7 +1174,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                limitThread.inc() ;
                                        }
                                        
-                                       final int ind = i ;
+                                       final int indice = i ;
                                        new Thread( new Runnable() {
 
                                                @Override
@@ -1122,9 +1183,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        boolean error = true  ;
                                                        
                                                        try {
-                                                               ret = clients.get( ind ).getStub().deployVM( _name, _archive, _directory ) ;
+                                                               ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
                                                        } catch( RemoteException e ) {
-                                                               System.err.println( "Unable to deploy the VM on " + clients.get( ind ).getName() + "!" ) ;
+                                                               System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
                                                                e.printStackTrace() ;
                                                        }
                                        
@@ -1132,17 +1193,17 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        if( ret == 2 )
                                                        {
                                                                // Attention au multi-envois !!!
-                                                               System.out.print( "Sending VM archive to " + clients.get( ind ).getName() + " ... " ) ;
+                                                               System.out.print( "Sending VM archive to " + clients.get( indice ).getName() + " ... " ) ;
                                        
                                                                String wd = "" ;
                                                                String snIP = "" ;
                                                                error = false ;
                                        
                                                                try {
-                                                                       wd = clients.get( ind ).getStub().getWorkingDirectory() ;
-                                                                       snIP = clients.get( ind ).getStub().getIPHost() ;
+                                                                       wd = clients.get( indice ).getStub().getWorkingDirectory() ;
+                                                                       snIP = clients.get( indice ).getStub().getIPHost() ;
                                                                } catch (RemoteException e2) {
-                                                                       System.err.println( "Unable to retrieve information on " + clients.get( ind ).getName() + "!" ) ;
+                                                                       System.err.println( "Unable to retrieve information on " + clients.get( indice ).getName() + "!" ) ;
                                                                        e2.printStackTrace() ;
                                                                        error = true ;
                                                                }
@@ -1192,9 +1253,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                        // Second try ...
                                                                        ret = 1 ;
                                                                        try {
-                                                                               ret = clients.get( ind ).getStub().deployVM( _name, _archive, _directory ) ;
+                                                                               ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
                                                                        } catch( RemoteException e ) {
-                                                                               System.err.println( "Unable to deploy the VM on " + clients.get( ind ).getName() + "!" ) ;
+                                                                               System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
                                                                                e.printStackTrace() ;
                                                                        }
                                                                }
@@ -1202,7 +1263,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                                        if( ret == 0 )
                                                        {
-                                                               System.out.println( "Initial VM archive successfully deployed on " + clients.get( ind ).getName() + "." ) ;
+                                                               System.out.println( "Initial VM archive successfully deployed on " + clients.get( indice ).getName() + "." ) ;
                                                                
                                                                synchronized( deployingClients )
                                                                {
@@ -1278,6 +1339,52 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                protected int getNb() { return nb ; }
        }
        
+       
+       private class RestartVM extends Thread
+       {
+               private ConnectedClient cc ;
+               
+               protected RestartVM( ConnectedClient _cc )
+               {
+                       cc = _cc ;
+               }
+                       
+               public void run()
+               {
+                       boolean error = false ;
+                       if( cc != null )
+                       {
+                               try {
+                                       if( cc.getStub().restartVMAfterCrash() != 0 )
+                                       {
+                                               System.err.println( "Problem while restarting VM on " + cc.getName() + "!" ) ;
+                                               error = true ;
+                                       }
+                               } catch( RemoteException e ) {
+                                       e.printStackTrace() ;
+                                       error = true ;
+                                       yield() ;
+                               }
+                       } else {
+                               System.err.println( "The client to restart is null!" ) ;
+                       }
+                       
+                       if( error )
+                       {
+                               cc.setFail( true ) ;
+                               
+                               try {
+                                       System.out.print( "Trying to stop the client ... " ) ;
+                                       cc.getStub().stop() ;
+                                       System.out.println( "successful client stop." );
+                               } catch( RemoteException e ) {
+                                       System.out.println( "unsuccessful client stop!" ) ;
+                                       e.printStackTrace() ;
+                               }
+                       }
+               }
+       }
+       
 }
 
 /** La programmation est un art, respectons ceux qui la pratiquent !! **/