Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Release of threads, and adding error messages.
[hpcvm.git] / src / and / hpcvm / Server.java
index 8f35386..b703aa7 100644 (file)
@@ -263,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() ;
                        }
                }
                
@@ -398,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 )
@@ -425,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 )
@@ -527,10 +530,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
 //                                                                     break ;
 //                                                             }
 //                                                     }
-                                                       synchronized( counter ){
-                                                               counter.inc() ;}
+                                                       synchronized( counter )
+                                                       {
+                                                               counter.inc() ;
+                                                       }
                                                                
-                                                       
                                                        new Server.FaultManager( cl ).start() ;
                                                        nb_disconnections_computing++ ;
                                                } else {
@@ -577,6 +581,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() ;
                                                        }
                                                }
                                        }
@@ -596,16 +601,17 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                counter.wait() ;
                                                        } catch( InterruptedException e ) {
                                                                e.printStackTrace() ;
+                                                               yield() ;
                                                        }
                                                }
                                        }
                                        
                                        for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
-                                               final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
-                                               
                                                applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
                                                
+                                               final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
+                                               
                                                new Thread( new Runnable() {
                                                        
                                                        @Override
@@ -615,6 +621,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                        sc.restartVMAfterCrash() ;
                                                                } catch( RemoteException e ) {
                                                                        e.printStackTrace() ;
+                                                                       yield() ;
                                                                }
                                                        }
                                                } ).start() ;
@@ -626,6 +633,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                        Thread.sleep( 2000 ) ;
                                } catch( InterruptedException e ) {
                                        e.printStackTrace() ;
+                                       yield() ;
                                }
                        }
                }
@@ -662,7 +670,8 @@ 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 ) ;
                        }
@@ -683,15 +692,21 @@ 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 on " + _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 ) 
        {
@@ -722,8 +737,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        
                                                        try {
                                                                startingClients.wait() ;
-                                                       } catch (InterruptedException e) {
-                                                               e.printStackTrace();
+                                                       } catch( InterruptedException e ) {
+                                                               e.printStackTrace() ;
                                                        }
                                                }
                                                
@@ -751,8 +766,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                }
                                                
                                                final int indice = i ;
-                                               new Thread( new Runnable(){
-                                                       
+                                               new Thread( new Runnable()
+                                               {       
                                                        @Override
                                                        public void run() 
                                                        {
@@ -760,7 +775,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                try {
                                                                        res = clients.get( indice ).getStub().startVM( 0 ) ;
                                                                } catch( RemoteException e ) {
-                                                                       e.printStackTrace();
+                                                                       e.printStackTrace() ;
                                                                }
                                                                
                                                                if( res == 0 )
@@ -964,7 +979,7 @@ 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( ind ).getComputingClients().size()+") ... " ) ;
-                       if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
+//                     if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
                        {
                                // Has it already finished?
                                for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
@@ -977,7 +992,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                        }
                                }
                                
-                               // Is every body ok?
+                               // Is everybody ok?
                                boolean ok = false ;
                                for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {