X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/blobdiff_plain/7cb1767605817324506b7500a36cf650bebcd010..c2a0de69e20fda415c1ca6d90b04d2a4cf253acc:/src/and/hpcvm/Client.java diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index 3de9f2a..06bb4e7 100644 --- a/src/and/hpcvm/Client.java +++ b/src/and/hpcvm/Client.java @@ -932,15 +932,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! lastSaveOk ) { -// 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() ) @@ -1019,42 +1010,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient 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() ; @@ -1403,13 +1358,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( serverSocket != null ) { try { - serverSocket.close() ; - -// for( int i = 0 ; i < dialogs.size() ; i++ ) -// { -// dialogs.get( i ).stopDialogVM() ; -// } - + serverSocket.close() ; } catch( IOException e ) { e.printStackTrace() ; } @@ -1438,8 +1387,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient socket = serverSocket.accept() ; 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() ; @@ -1451,24 +1399,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient private class DialogVM extends Thread { - protected boolean go ; private Socket socket ; private BufferedReader reader ; private String line ; - DialogVM( Socket _socket ) { go = true ; socket = _socket ; } - - protected void stopDialogVM() - { - go = false ; - - try { - reader.close() ; reader = null ; - socket.close() ; socket = null ; - } catch( IOException e ) { - e.printStackTrace() ; - } - } + DialogVM( Socket _socket ) { socket = _socket ; } @Override public void run() @@ -1478,105 +1413,119 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { System.err.println( "Unable to open a dialog socket with the VM!" ) ; e.printStackTrace(); - stopDialogVM() ; } - -// while( go ) - { - try { - line = null ; - - if( reader != null ) - { - line = reader.readLine() ; - } - - /** VM is starting -- retrieving informations **/ - if( go && line != null && line.equalsIgnoreCase( "infos" ) ) + + try { + line = null ; + + if( reader != null ) + { + line = reader.readLine() ; + } + + /** VM is starting -- retrieving informations **/ + if( line != null && line.equalsIgnoreCase( "infos" ) ) + { + /* Receiving name */ + machine.setName( reader.readLine() ) ; + + /* Receiving IP */ + String ip = reader.readLine() ; + if( ! ip.equalsIgnoreCase( machine.getIp() ) ) { - /* Receiving name */ - machine.setName( reader.readLine() ) ; - - /* Receiving IP */ - String ip = reader.readLine() ; - if( ! ip.equalsIgnoreCase( machine.getIp() ) ) - { - System.err.println( "VM IP not well configured!!" ) ; - } - - /* Close streams */ - reader.close() ; reader = null ; - socket.close() ; socket = null ; - - go = false ; + System.err.println( "VM IP not well configured!!" ) ; } - + + /* Close streams */ + reader.close() ; reader = null ; + socket.close() ; socket = null ; + + } else if( line != null && line.equalsIgnoreCase( "save" ) ) { /** It's time to do a save **/ - if( go && line != null && line.equalsIgnoreCase( "save" ) ) - { + + try { + machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ; + } catch( Exception e ) { + System.err.println( "Problem while reading the computation id!" ) ; + e.printStackTrace() ; + } + + synchronized( saveRequest ) + { try { - machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ; - } catch( Exception e ) { - System.err.println( "Problem while reading the computation id!" ) ; + LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ; + } catch( RemoteException e ) { + System.err.println( "Unable to request save to server!" ) ; e.printStackTrace() ; } - - synchronized( saveRequest ) - { - try { - LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ; - } catch( RemoteException e ) { - System.err.println( "Unable to request save to server!" ) ; - e.printStackTrace() ; - } - - try { - saveRequest.wait() ; - } catch( InterruptedException e ) { - e.printStackTrace(); - } - } - - if( saveRequest.getStatus() ) - { - /* Close streams */ - reader.close() ; reader = null ; - socket.close() ; socket = null ; - - go = false ; - - saveRequest.setStatus( false ) ; - - /* Requesting the VM save */ - saveVM() ; - } else { - sendSaveOkVM() ; - } - } - - - /** Computation is done, we can shutdown the VM **/ - if( go && line != null && line.equalsIgnoreCase( "quit" ) ) - { + try { - Thread.sleep( 5000 ) ; + saveRequest.wait() ; } catch( InterruptedException e ) { - e.printStackTrace() ; + e.printStackTrace(); } - + } + + if( saveRequest.getStatus() ) + { /* Close streams */ reader.close() ; reader = null ; socket.close() ; socket = null ; - - go = false ; - - stopVM() ; + + saveRequest.setStatus( false ) ; + + /* Requesting the VM save */ + saveVM() ; + } else { + sendSaveOkVM() ; + } + } else if( line != null && line.equalsIgnoreCase( "quit" ) ) { + /** Computation is done, we can shutdown the VM **/ + + try { + Thread.sleep( 5000 ) ; + } catch( InterruptedException e ) { + e.printStackTrace() ; + } + + /* Close streams */ + reader.close() ; reader = null ; + socket.close() ; socket = null ; + + stopVM() ; + + machine.setStatus( "connected" ) ; + try { + LocalHost.Instance().getServerStub().changeStatus( + LocalHost.Instance().getIP(), "connected" ) ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server of the VM status!" ) ; + e.printStackTrace() ; } - } catch( IOException e ) { - go = false ; - e.printStackTrace() ; + try { + LocalHost.Instance().getServerStub().endApplication() ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server of the end of application!" ) ; + e.printStackTrace() ; + } + } else if( line != null && line.equalsIgnoreCase( "start" ) ) { + /** Computation is starting **/ + + /* Close streams */ + reader.close() ; reader = null ; + socket.close() ; socket = null ; + + try { + LocalHost.Instance().getServerStub().goApplication() ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server of the end of application!" ) ; + e.printStackTrace() ; + } } + + } catch( IOException e ) { + e.printStackTrace() ; } } }