Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Using parallelism is better :) Plus some bugs correction.
[hpcvm.git] / src / and / hpcvm / Client.java
index 7d58da8..3de9f2a 100644 (file)
@@ -932,29 +932,29 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                
                if( ! lastSaveOk )
                {
-                       String arch1 = "", arch2 = "" ;
-                       File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" )  ;
+//                     String arch1 = "", arch2 = "" ;
+//                     File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" )  ;
+//                     if( file.exists() )
+//                     {
+//                             arch1 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ;
+//                     }
+//                     
+//                     file = null ;
+//                     
+                       String arch = "" ;
+                       File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ;
                        if( file.exists() )
                        {
-                               arch1 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ;
+                               arch = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;
                        }
                        
                        file = null ;
                        
-                       file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ;
-                       if( file.exists() )
-                       {
-                               arch2 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;
-                       }
-                       
-                       file = null ;
-                       
-                       if( arch1.length() > 0 || arch2.length() > 0 )
+                       if( arch.length() > 0 )
                        {                       
                                System.out.println( "Deletion of last nok archive ... " ) ;
                        
-                               command = new String[]{ "/bin/rm", "-rf", 
-                                       arch1, arch2 } ;
+                               command = new String[]{ "/bin/rm", "-rf", arch } ;
                                                        
                                try {
                                        procSave = Runtime.getRuntime().exec( command ) ;
@@ -986,9 +986,9 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        System.out.print( "Creation of the archive ... " ) ;
                        
                        /** Archive creation **/
-                       command = new String[]{ "/bin/tar", "-cf", 
-                                       machine.getName() + "_new_" + machine.getComputationId() + ".tar",
-                                       machine.getDirectory(), "-C", working_directory } ;
+                       command = new String[]{ "/bin/tar", "-cz", "-C", working_directory,
+                                       "-f", working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz",
+                                       machine.getDirectory() } ;
                                
                        if( emergencyStop )
                        {
@@ -1020,41 +1020,41 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                error = true ;
                        }
                
-                       /** Compression of the archive **/
-                       if( ! error )
-                       {
-                               System.out.print( "Compression of the archive ... " ) ;
-                               command = new String[]{ "/bin/gzip", 
-                                               working_directory + "/" + machine.getName() 
-                                               + "_new_" + machine.getComputationId() + ".tar" } ;
-                               
-                               if( emergencyStop )
-                               {
-                                       return 1 ;
-                               }
-                               
-                               try {
-                                       procSave = Runtime.getRuntime().exec( command ) ;
-                                       procSave.waitFor() ;
-                       
-                                       if( procSave.exitValue() == 0 )
-                                       {
-                                               System.out.println( "Archive successfully compressed." ) ;
-                                       } else {
-                                               System.err.println( "Archive not compressed!" ) ;
-                                               printProcessError( procSave ) ;
-                                               
-                                               error = true ;
-                                       }
-                               } catch( IOException e ) {
-                                       System.err.println( "Error during archive compression command: " ) ;
-                                       e.printStackTrace() ;
-                                       error = true ;
-                               } catch( InterruptedException e ) {
-                                       e.printStackTrace() ;
-                                       error = true ;
-                               }
-                       }
+//                     /** Compression of the archive **/
+//                     if( ! error )
+//                     {
+//                             System.out.print( "Compression of the archive ... " ) ;
+//                             command = new String[]{ "/bin/gzip", 
+//                                             working_directory + "/" + machine.getName() 
+//                                             + "_new_" + machine.getComputationId() + ".tar" } ;
+//                             
+//                             if( emergencyStop )
+//                             {
+//                                     return 1 ;
+//                             }
+//                             
+//                             try {
+//                                     procSave = Runtime.getRuntime().exec( command ) ;
+//                                     procSave.waitFor() ;
+//                     
+//                                     if( procSave.exitValue() == 0 )
+//                                     {
+//                                             System.out.println( "Archive successfully compressed." ) ;
+//                                     } else {
+//                                             System.err.println( "Archive not compressed!" ) ;
+//                                             printProcessError( procSave ) ;
+//                                             
+//                                             error = true ;
+//                                     }
+//                             } catch( IOException e ) {
+//                                     System.err.println( "Error during archive compression command: " ) ;
+//                                     e.printStackTrace() ;
+//                                     error = true ;
+//                             } catch( InterruptedException e ) {
+//                                     e.printStackTrace() ;
+//                                     error = true ;
+//                             }
+//                     }
                        
                        long fin = System.currentTimeMillis() ;
                        
@@ -1191,7 +1191,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
 //             date_last_save = 0 ;
                
                isRestartedSave = false ;
-               lastSaveOk = true ;
+               lastSaveOk = false ;
                
                /** Connection to server **/
                try {
@@ -1354,19 +1354,19 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        private class PingServer extends Thread
        {
-               private boolean run ;
+               protected boolean go ;
                
                PingServer()
                {
-                       run = true ;
+                       go = true ;
                }
                
-               protected void stopPing() { run = false ; }
+               protected void stopPing() { go = false ; }
                
                @Override
                public void run() 
                {
-                       while( run )
+                       while( go )
                        {
                                try {
                                        LocalHost.Instance().getServerStub().ping( LocalHost.Instance().getIP() ) ;
@@ -1376,7 +1376,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                }
                                
                                try {
-                                       Thread.sleep( 2000 ) ;
+                                       sleep( 2000 ) ;
                                } catch( InterruptedException e ) {
                                        e.printStackTrace() ;
                                }
@@ -1387,28 +1387,28 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        private class DialogVMServer extends Thread
        {
-               private boolean run ;
+               protected boolean go ;
                private Socket socket ;
-               private ArrayList<DialogVM> dialogs = new ArrayList<DialogVM>() ;
+//             private ArrayList<DialogVM> dialogs = new ArrayList<DialogVM>() ;
                
                DialogVMServer()
                {
-                       run = true ;
+                       go = true ;
                }
                
                protected void stopDialogVMServer() 
                { 
-                       run = false ;
+                       go = false ;
                        
                        if( serverSocket != null )
                        {
                                try {
                                        serverSocket.close() ;
                                        
-                                       for( int i = 0 ; i < dialogs.size() ; i++ )
-                                       {
-                                               dialogs.get( i ).stopDialogVM() ;
-                                       }
+//                                     for( int i = 0 ; i < dialogs.size() ; i++ )
+//                                     {
+//                                             dialogs.get( i ).stopDialogVM() ;
+//                                     }
                                        
                                } catch( IOException e ) {
                                        e.printStackTrace() ;
@@ -1429,16 +1429,17 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                System.err.println( "Unable to launch the SocketServer on port " + dialog_port + "!" ) ;
                                e.printStackTrace() ;
                                
-                               run = false ;
+                               go = false ;
                        }       
                        
-                       while( run )
+                       while( go )
                        {                               
                                try {
                                        socket = serverSocket.accept() ;
                                        
-                                       dialogs.add( new DialogVM( socket ) ) ;
-                                       dialogs.get( dialogs.size() - 1 ).start() ;     
+                                       new DialogVM( socket ).start() ;
+//                                     dialogs.add( new DialogVM( socket ) ) ;
+//                                     dialogs.get( dialogs.size() - 1 ).start() ;     
                                } catch( IOException e ) {
                                        System.err.println( "Problem with the accept function!" ) ;
                                        e.printStackTrace() ;
@@ -1450,16 +1451,16 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        private class DialogVM extends Thread
        {
-               private boolean run ;
+               protected boolean go ;
                private Socket socket ;
                private BufferedReader reader ;
                private String line ;
                
-               DialogVM( Socket _socket ) { run = true ; socket = _socket ; }
+               DialogVM( Socket _socket ) { go = true ; socket = _socket ; }
        
                protected void stopDialogVM()
                {
-                       run = false ;
+                       go = false ;
 
                        try {
                                reader.close() ; reader = null ;
@@ -1480,7 +1481,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                stopDialogVM() ;
                        }
                        
-                       while( run )
+//                     while( go )
                        {
                                try {
                                        line = null ;
@@ -1491,7 +1492,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        }
                                        
                                        /** VM is starting -- retrieving informations **/
-                                       if( run && line != null &&  line.equalsIgnoreCase( "infos" ) )
+                                       if( go && line != null &&  line.equalsIgnoreCase( "infos" ) )
                                        {
                                                /* Receiving name */
                                                machine.setName( reader.readLine() ) ;
@@ -1507,11 +1508,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                reader.close() ; reader = null ;
                                                socket.close() ; socket = null ;
                                                
-                                               run = false ;
+                                               go = false ;
                                        }
                                        
                                        /** It's time to do a save **/
-                                       if( run && line != null &&  line.equalsIgnoreCase( "save" ) )
+                                       if( go && line != null &&  line.equalsIgnoreCase( "save" ) )
                                        {                                               
                                                try {
                                                        machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
@@ -1542,7 +1543,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                        reader.close() ; reader = null ;
                                                        socket.close() ; socket = null ;
                                                        
-                                                       run = false ;
+                                                       go = false ;
                                                        
                                                        saveRequest.setStatus( false ) ;
                                                
@@ -1555,7 +1556,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        
                                        
                                        /** Computation is done, we can shutdown the VM **/
-                                       if( run && line != null &&  line.equalsIgnoreCase( "quit" ) )
+                                       if( go && line != null &&  line.equalsIgnoreCase( "quit" ) )
                                        {
                                                try {
                                                        Thread.sleep( 5000 ) ;
@@ -1567,12 +1568,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                reader.close() ; reader = null ;
                                                socket.close() ; socket = null ;
                                                
-                                               run = false ;
+                                               go = false ;
                                                
                                                stopVM() ;
                                        }
                                        
                                } catch( IOException e ) {
+                                       go = false ;
                                        e.printStackTrace() ;
                                }
                        }